2014-10-17 02:33:28 +04:00
|
|
|
Panel = require '../src/panel'
|
|
|
|
PanelContainer = require '../src/panel-container'
|
|
|
|
|
|
|
|
describe "PanelContainer", ->
|
2014-12-01 00:47:51 +03:00
|
|
|
[container] = []
|
2014-10-17 02:33:28 +04:00
|
|
|
|
|
|
|
class TestPanelItem
|
|
|
|
constructior: ->
|
|
|
|
|
|
|
|
beforeEach ->
|
2014-12-01 00:47:51 +03:00
|
|
|
container = new PanelContainer
|
2014-10-17 02:33:28 +04:00
|
|
|
|
|
|
|
describe "::addPanel(panel)", ->
|
|
|
|
it 'emits an onDidAddPanel event with the index the panel was inserted at', ->
|
|
|
|
container.onDidAddPanel addPanelSpy = jasmine.createSpy()
|
|
|
|
|
2014-10-17 04:31:13 +04:00
|
|
|
panel1 = new Panel(item: new TestPanelItem())
|
2014-10-17 02:33:28 +04:00
|
|
|
container.addPanel(panel1)
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel: panel1, index: 0})
|
|
|
|
|
2014-10-17 04:31:13 +04:00
|
|
|
panel2 = new Panel(item: new TestPanelItem())
|
2014-10-17 02:33:28 +04:00
|
|
|
container.addPanel(panel2)
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel: panel2, index: 1})
|
|
|
|
|
|
|
|
describe "when a panel is destroyed", ->
|
|
|
|
it 'emits an onDidRemovePanel event with the index of the removed item', ->
|
|
|
|
container.onDidRemovePanel removePanelSpy = jasmine.createSpy()
|
|
|
|
|
2014-10-17 04:31:13 +04:00
|
|
|
panel1 = new Panel(item: new TestPanelItem())
|
2014-10-17 02:33:28 +04:00
|
|
|
container.addPanel(panel1)
|
2014-10-17 04:31:13 +04:00
|
|
|
panel2 = new Panel(item: new TestPanelItem())
|
2014-10-17 02:33:28 +04:00
|
|
|
container.addPanel(panel2)
|
|
|
|
|
|
|
|
expect(removePanelSpy).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
panel2.destroy()
|
|
|
|
expect(removePanelSpy).toHaveBeenCalledWith({panel: panel2, index: 1})
|
|
|
|
|
|
|
|
panel1.destroy()
|
|
|
|
expect(removePanelSpy).toHaveBeenCalledWith({panel: panel1, index: 0})
|
2014-10-18 00:44:40 +04:00
|
|
|
|
|
|
|
describe "panel priority", ->
|
2014-10-20 23:03:48 +04:00
|
|
|
describe 'left / top panel container', ->
|
2014-10-18 00:44:40 +04:00
|
|
|
[initialPanel] = []
|
|
|
|
beforeEach ->
|
2014-10-20 23:03:48 +04:00
|
|
|
# 'left' logic is the same as 'top'
|
2014-12-01 00:47:51 +03:00
|
|
|
container = new PanelContainer({location: 'left'})
|
2014-10-18 00:44:40 +04:00
|
|
|
initialPanel = new Panel(item: new TestPanelItem())
|
|
|
|
container.addPanel(initialPanel)
|
|
|
|
|
2014-10-20 23:03:48 +04:00
|
|
|
describe 'when a panel with low priority is added', ->
|
2014-10-18 00:44:40 +04:00
|
|
|
it 'is inserted at the beginning of the list', ->
|
|
|
|
container.onDidAddPanel addPanelSpy = jasmine.createSpy()
|
|
|
|
panel = new Panel(item: new TestPanelItem(), priority: 0)
|
|
|
|
container.addPanel(panel)
|
|
|
|
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
|
|
|
expect(container.getPanels()[0]).toBe panel
|
|
|
|
|
2014-10-20 23:03:48 +04:00
|
|
|
describe 'when a panel with priority between two other panels is added', ->
|
2014-10-18 00:44:40 +04:00
|
|
|
it 'is inserted at the between the two panels', ->
|
|
|
|
panel = new Panel(item: new TestPanelItem(), priority: 1000)
|
|
|
|
container.addPanel(panel)
|
|
|
|
|
|
|
|
container.onDidAddPanel addPanelSpy = jasmine.createSpy()
|
|
|
|
panel = new Panel(item: new TestPanelItem(), priority: 101)
|
|
|
|
container.addPanel(panel)
|
|
|
|
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 1})
|
|
|
|
expect(container.getPanels()[1]).toBe panel
|
|
|
|
|
2014-10-20 23:03:48 +04:00
|
|
|
describe 'right / bottom panel container', ->
|
2014-10-18 00:44:40 +04:00
|
|
|
[initialPanel] = []
|
|
|
|
beforeEach ->
|
2014-10-20 23:03:48 +04:00
|
|
|
# 'bottom' logic is the same as 'right'
|
2014-12-01 00:47:51 +03:00
|
|
|
container = new PanelContainer({location: 'right'})
|
2014-10-18 00:44:40 +04:00
|
|
|
initialPanel = new Panel(item: new TestPanelItem())
|
|
|
|
container.addPanel(initialPanel)
|
|
|
|
|
2014-10-20 23:03:48 +04:00
|
|
|
describe 'when a panel with high priority is added', ->
|
2014-10-18 00:44:40 +04:00
|
|
|
it 'is inserted at the beginning of the list', ->
|
|
|
|
container.onDidAddPanel addPanelSpy = jasmine.createSpy()
|
|
|
|
panel = new Panel(item: new TestPanelItem(), priority: 1000)
|
|
|
|
container.addPanel(panel)
|
|
|
|
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
|
|
|
expect(container.getPanels()[0]).toBe panel
|
|
|
|
|
2014-10-20 23:03:48 +04:00
|
|
|
describe 'when a panel with low priority is added', ->
|
2014-10-18 00:44:40 +04:00
|
|
|
it 'is inserted at the end of the list', ->
|
|
|
|
container.onDidAddPanel addPanelSpy = jasmine.createSpy()
|
|
|
|
panel = new Panel(item: new TestPanelItem(), priority: 0)
|
|
|
|
container.addPanel(panel)
|
|
|
|
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 1})
|
|
|
|
expect(container.getPanels()[1]).toBe panel
|