2014-01-10 03:09:22 +04:00
|
|
|
PaneContainerModel = require '../src/pane-container-model'
|
|
|
|
PaneModel = require '../src/pane-model'
|
|
|
|
|
|
|
|
describe "PaneContainerModel", ->
|
|
|
|
describe "serialization", ->
|
2014-01-10 22:21:46 +04:00
|
|
|
[containerA, pane1A, pane2A, pane3A] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
2014-01-13 04:49:08 +04:00
|
|
|
# This is a dummy item to prevent panes from being empty on deserialization
|
|
|
|
class Item
|
|
|
|
atom.deserializers.add(this)
|
|
|
|
@deserialize: -> new this
|
|
|
|
serialize: -> deserializer: 'Item'
|
|
|
|
|
|
|
|
pane1A = new PaneModel(items: [new Item])
|
2014-01-10 03:09:22 +04:00
|
|
|
containerA = new PaneContainerModel(root: pane1A)
|
2014-01-13 04:49:08 +04:00
|
|
|
pane2A = pane1A.splitRight(items: [new Item])
|
|
|
|
pane3A = pane2A.splitDown(items: [new Item])
|
2014-01-10 22:21:46 +04:00
|
|
|
|
|
|
|
it "preserves the focused pane across serialization", ->
|
2014-01-10 03:09:22 +04:00
|
|
|
expect(pane3A.focused).toBe true
|
|
|
|
|
|
|
|
containerB = containerA.testSerialization()
|
2014-01-10 04:40:04 +04:00
|
|
|
[pane1B, pane2B, pane3B] = containerB.getPanes()
|
|
|
|
expect(pane3B.focused).toBe true
|
|
|
|
|
2014-01-10 22:21:46 +04:00
|
|
|
it "preserves the active pane across serialization, independent of focus", ->
|
2014-01-12 07:48:01 +04:00
|
|
|
pane3A.activate()
|
2014-01-10 22:21:46 +04:00
|
|
|
expect(containerA.activePane).toBe pane3A
|
|
|
|
|
|
|
|
containerB = containerA.testSerialization()
|
|
|
|
[pane1B, pane2B, pane3B] = containerB.getPanes()
|
|
|
|
expect(containerB.activePane).toBe pane3B
|
|
|
|
|
2014-01-10 04:40:04 +04:00
|
|
|
describe "::activePane", ->
|
|
|
|
[container, pane1, pane2] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
pane1 = new PaneModel
|
|
|
|
container = new PaneContainerModel(root: pane1)
|
|
|
|
|
2014-01-11 04:25:30 +04:00
|
|
|
it "references the first pane if no pane has been made active", ->
|
2014-01-10 04:40:04 +04:00
|
|
|
expect(container.activePane).toBe pane1
|
|
|
|
expect(pane1.active).toBe true
|
|
|
|
|
2014-01-12 07:48:01 +04:00
|
|
|
it "references the most pane on which ::activate was most recently called", ->
|
2014-01-10 04:40:04 +04:00
|
|
|
pane2 = pane1.splitRight()
|
2014-01-12 07:48:01 +04:00
|
|
|
pane2.activate()
|
2014-01-10 04:40:04 +04:00
|
|
|
expect(container.activePane).toBe pane2
|
|
|
|
expect(pane1.active).toBe false
|
|
|
|
expect(pane2.active).toBe true
|
2014-01-12 07:48:01 +04:00
|
|
|
pane1.activate()
|
2014-01-10 04:40:04 +04:00
|
|
|
expect(container.activePane).toBe pane1
|
|
|
|
expect(pane1.active).toBe true
|
|
|
|
expect(pane2.active).toBe false
|
|
|
|
|
2014-01-11 04:25:30 +04:00
|
|
|
it "is reassigned to the next pane if the current active pane is destroyed", ->
|
2014-01-10 04:40:04 +04:00
|
|
|
pane2 = pane1.splitRight()
|
2014-01-12 07:48:01 +04:00
|
|
|
pane2.activate()
|
2014-01-10 04:40:04 +04:00
|
|
|
pane2.destroy()
|
|
|
|
expect(container.activePane).toBe pane1
|
|
|
|
expect(pane1.active).toBe true
|
|
|
|
pane1.destroy()
|
|
|
|
expect(container.activePane).toBe null
|
2014-01-10 05:17:02 +04:00
|
|
|
|
|
|
|
describe "when the last pane is removed", ->
|
|
|
|
[container, pane, surrenderedFocusHandler] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
pane = new PaneModel
|
|
|
|
container = new PaneContainerModel(root: pane)
|
|
|
|
container.on 'surrendered-focus', surrenderedFocusHandler = jasmine.createSpy("surrenderedFocusHandler")
|
|
|
|
|
2014-01-10 22:22:19 +04:00
|
|
|
it "assigns null to the root and the activePane", ->
|
|
|
|
pane.destroy()
|
|
|
|
expect(container.root).toBe null
|
|
|
|
expect(container.activePane).toBe null
|