2017-03-08 01:52:32 +03:00
|
|
|
'use strict'
|
|
|
|
|
2017-03-08 01:30:33 +03:00
|
|
|
const Panel = require('../src/panel')
|
|
|
|
const PanelContainer = require('../src/panel-container')
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
describe('PanelContainer', () => {
|
|
|
|
let container
|
2017-03-08 01:20:27 +03:00
|
|
|
|
|
|
|
class TestPanelItem {
|
|
|
|
}
|
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
beforeEach(() => {
|
2017-04-06 01:26:47 +03:00
|
|
|
container = new PanelContainer({viewRegistry: atom.views})
|
2017-03-08 01:52:32 +03:00
|
|
|
})
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
describe('::addPanel(panel)', () => {
|
|
|
|
it('emits an onDidAddPanel event with the index the panel was inserted at', () => {
|
|
|
|
const addPanelSpy = jasmine.createSpy()
|
|
|
|
container.onDidAddPanel(addPanelSpy)
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-04-06 02:10:21 +03:00
|
|
|
const panel1 = new Panel({item: new TestPanelItem()}, atom.views)
|
2017-03-08 01:30:33 +03:00
|
|
|
container.addPanel(panel1)
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel: panel1, index: 0})
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-04-06 02:10:21 +03:00
|
|
|
const panel2 = new Panel({item: new TestPanelItem()}, atom.views)
|
2017-03-08 01:30:33 +03:00
|
|
|
container.addPanel(panel2)
|
2017-03-08 01:52:32 +03:00
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel: panel2, index: 1})
|
2017-03-08 01:20:27 +03:00
|
|
|
})
|
2017-03-08 01:52:32 +03:00
|
|
|
})
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
describe('when a panel is destroyed', () => {
|
|
|
|
it('emits an onDidRemovePanel event with the index of the removed item', () => {
|
|
|
|
const removePanelSpy = jasmine.createSpy()
|
|
|
|
container.onDidRemovePanel(removePanelSpy)
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-04-06 02:10:21 +03:00
|
|
|
const panel1 = new Panel({item: new TestPanelItem()}, atom.views)
|
2017-03-08 01:30:33 +03:00
|
|
|
container.addPanel(panel1)
|
2017-04-06 02:10:21 +03:00
|
|
|
const panel2 = new Panel({item: new TestPanelItem()}, atom.views)
|
2017-03-08 01:30:33 +03:00
|
|
|
container.addPanel(panel2)
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:30:33 +03:00
|
|
|
expect(removePanelSpy).not.toHaveBeenCalled()
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:30:33 +03:00
|
|
|
panel2.destroy()
|
|
|
|
expect(removePanelSpy).toHaveBeenCalledWith({panel: panel2, index: 1})
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:30:33 +03:00
|
|
|
panel1.destroy()
|
2017-03-08 01:52:32 +03:00
|
|
|
expect(removePanelSpy).toHaveBeenCalledWith({panel: panel1, index: 0})
|
2017-03-08 01:20:27 +03:00
|
|
|
})
|
2017-03-08 01:52:32 +03:00
|
|
|
})
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
describe('::destroy()', () => {
|
|
|
|
it('destroys the container and all of its panels', () => {
|
2017-03-08 01:30:33 +03:00
|
|
|
const destroyedPanels = []
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-04-06 02:10:21 +03:00
|
|
|
const panel1 = new Panel({item: new TestPanelItem()}, atom.views)
|
2017-03-08 01:52:32 +03:00
|
|
|
panel1.onDidDestroy(() => { destroyedPanels.push(panel1) })
|
2017-03-08 01:30:33 +03:00
|
|
|
container.addPanel(panel1)
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-04-06 02:10:21 +03:00
|
|
|
const panel2 = new Panel({item: new TestPanelItem()}, atom.views)
|
2017-03-08 01:52:32 +03:00
|
|
|
panel2.onDidDestroy(() => { destroyedPanels.push(panel2) })
|
2017-03-08 01:30:33 +03:00
|
|
|
container.addPanel(panel2)
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:30:33 +03:00
|
|
|
container.destroy()
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:30:33 +03:00
|
|
|
expect(container.getPanels().length).toBe(0)
|
2017-03-08 01:52:32 +03:00
|
|
|
expect(destroyedPanels).toEqual([panel1, panel2])
|
2017-03-08 01:20:27 +03:00
|
|
|
})
|
2017-03-08 01:52:32 +03:00
|
|
|
})
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
describe('panel priority', () => {
|
|
|
|
describe('left / top panel container', () => {
|
|
|
|
let initialPanel
|
|
|
|
beforeEach(() => {
|
2017-03-08 01:20:27 +03:00
|
|
|
// 'left' logic is the same as 'top'
|
2017-03-08 01:30:33 +03:00
|
|
|
container = new PanelContainer({location: 'left'})
|
2017-04-06 02:10:21 +03:00
|
|
|
initialPanel = new Panel({item: new TestPanelItem()}, atom.views)
|
2017-03-08 01:52:32 +03:00
|
|
|
container.addPanel(initialPanel)
|
2017-03-08 01:30:33 +03:00
|
|
|
})
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
describe('when a panel with low priority is added', () => {
|
|
|
|
it('is inserted at the beginning of the list', () => {
|
|
|
|
const addPanelSpy = jasmine.createSpy()
|
|
|
|
container.onDidAddPanel(addPanelSpy)
|
2017-04-06 02:10:21 +03:00
|
|
|
const panel = new Panel({item: new TestPanelItem(), priority: 0}, atom.views)
|
2017-03-08 01:30:33 +03:00
|
|
|
container.addPanel(panel)
|
|
|
|
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
2017-03-08 01:52:32 +03:00
|
|
|
expect(container.getPanels()[0]).toBe(panel)
|
2017-03-08 01:20:27 +03:00
|
|
|
})
|
2017-03-08 01:52:32 +03:00
|
|
|
})
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
describe('when a panel with priority between two other panels is added', () => {
|
|
|
|
it('is inserted at the between the two panels', () => {
|
|
|
|
const addPanelSpy = jasmine.createSpy()
|
2017-04-06 02:10:21 +03:00
|
|
|
let panel = new Panel({item: new TestPanelItem(), priority: 1000}, atom.views)
|
2017-03-08 01:30:33 +03:00
|
|
|
container.addPanel(panel)
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
container.onDidAddPanel(addPanelSpy)
|
2017-04-06 02:10:21 +03:00
|
|
|
panel = new Panel({item: new TestPanelItem(), priority: 101}, atom.views)
|
2017-03-08 01:30:33 +03:00
|
|
|
container.addPanel(panel)
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:30:33 +03:00
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 1})
|
2017-03-08 01:52:32 +03:00
|
|
|
expect(container.getPanels()[1]).toBe(panel)
|
2017-03-08 01:20:27 +03:00
|
|
|
})
|
2017-03-08 01:52:32 +03:00
|
|
|
})
|
2017-03-08 01:30:33 +03:00
|
|
|
})
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
describe('right / bottom panel container', () => {
|
|
|
|
let initialPanel
|
|
|
|
beforeEach(() => {
|
2017-03-08 01:20:27 +03:00
|
|
|
// 'bottom' logic is the same as 'right'
|
2017-03-08 01:30:33 +03:00
|
|
|
container = new PanelContainer({location: 'right'})
|
2017-04-06 02:10:21 +03:00
|
|
|
initialPanel = new Panel({item: new TestPanelItem()}, atom.views)
|
2017-03-08 01:52:32 +03:00
|
|
|
container.addPanel(initialPanel)
|
2017-03-08 01:30:33 +03:00
|
|
|
})
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
describe('when a panel with high priority is added', () => {
|
|
|
|
it('is inserted at the beginning of the list', () => {
|
|
|
|
const addPanelSpy = jasmine.createSpy()
|
|
|
|
container.onDidAddPanel(addPanelSpy)
|
2017-04-06 02:10:21 +03:00
|
|
|
const panel = new Panel({item: new TestPanelItem(), priority: 1000}, atom.views)
|
2017-03-08 01:30:33 +03:00
|
|
|
container.addPanel(panel)
|
|
|
|
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
2017-03-08 01:52:32 +03:00
|
|
|
expect(container.getPanels()[0]).toBe(panel)
|
2017-03-08 01:20:27 +03:00
|
|
|
})
|
2017-03-08 01:52:32 +03:00
|
|
|
})
|
2017-03-08 01:20:27 +03:00
|
|
|
|
2017-03-08 01:52:32 +03:00
|
|
|
describe('when a panel with low priority is added', () => {
|
|
|
|
it('is inserted at the end of the list', () => {
|
|
|
|
const addPanelSpy = jasmine.createSpy()
|
|
|
|
container.onDidAddPanel(addPanelSpy)
|
2017-04-06 02:10:21 +03:00
|
|
|
const panel = new Panel({item: new TestPanelItem(), priority: 0}, atom.views)
|
2017-03-08 01:30:33 +03:00
|
|
|
container.addPanel(panel)
|
|
|
|
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 1})
|
2017-03-08 01:52:32 +03:00
|
|
|
expect(container.getPanels()[1]).toBe(panel)
|
2017-03-08 01:20:27 +03:00
|
|
|
})
|
2017-03-08 01:52:32 +03:00
|
|
|
})
|
2017-03-08 01:30:33 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|