Move pane item removal specs to pane-element-spec

This commit is contained in:
Nathan Sobo
2015-09-03 11:40:43 -06:00
parent dfda3adb96
commit 60670b9c3c
2 changed files with 43 additions and 35 deletions

View File

@@ -1,17 +1,21 @@
PaneContainer = require '../src/pane-container'
describe "PaneElement", ->
[paneElement, container, pane] = []
beforeEach ->
container = new PaneContainer
pane = container.getRoot()
paneElement = atom.views.getView(pane)
describe "when the active item changes", ->
it "hides all item elements except the active one", ->
container = new PaneContainer
pane = container.getRoot()
item1 = document.createElement('div')
item2 = document.createElement('div')
item3 = document.createElement('div')
pane.addItem(item1)
pane.addItem(item2)
pane.addItem(item3)
paneElement = atom.views.getView(pane)
expect(pane.getActiveItem()).toBe item1
expect(item1.parentElement).toBeDefined()
@@ -32,15 +36,12 @@ describe "PaneElement", ->
expect(item3.style.display).toBe ''
it "transfers focus to the new item if the previous item was focused", ->
container = new PaneContainer
pane = container.getRoot()
item1 = document.createElement('div')
item1.tabIndex = -1
item2 = document.createElement('div')
item2.tabIndex = -1
pane.addItem(item1)
pane.addItem(item2)
paneElement = atom.views.getView(pane)
jasmine.attachToDOM(paneElement)
paneElement.focus()
@@ -49,7 +50,7 @@ describe "PaneElement", ->
expect(document.activeElement).toBe item2
describe "if the active item is a model object", ->
it "retrieves the associated view from atom.views and appends it", ->
it "retrieves the associated view from atom.views and appends it to the itemViews div", ->
class TestModel
atom.views.addViewProvider TestModel, (model) ->
@@ -59,12 +60,8 @@ describe "PaneElement", ->
item1 = new TestModel
item2 = new TestModel
container = new PaneContainer
pane = container.getRoot()
pane.addItem(item1)
pane.addItem(item2)
paneElement = atom.views.getView(pane)
expect(paneElement.itemViews.children[0].model).toBe item1
expect(paneElement.itemViews.children[0].style.display).toBe ''
@@ -75,14 +72,11 @@ describe "PaneElement", ->
describe "when the new active implements .getPath()", ->
it "adds the file path and file name as a data attribute on the pane", ->
container = new PaneContainer
pane = container.getRoot()
item1 = document.createElement('div')
item1.getPath = -> '/foo/bar.txt'
item2 = document.createElement('div')
pane.addItem(item1)
pane.addItem(item2)
paneElement = atom.views.getView(pane)
expect(paneElement.dataset.activeItemPath).toBe '/foo/bar.txt'
expect(paneElement.dataset.activeItemName).toBe 'bar.txt'
@@ -100,5 +94,40 @@ describe "PaneElement", ->
expect(paneElement.dataset.activeItemPath).toBeUndefined()
expect(paneElement.dataset.activeItemName).toBeUndefined()
describe "when an item is removed from the pane", ->
describe "when the destroyed item is an element", ->
it "removes the item from the itemViews div", ->
item1 = document.createElement('div')
item2 = document.createElement('div')
pane.addItem(item1)
pane.addItem(item2)
paneElement = atom.views.getView(pane)
expect(item1.parentElement).toBe paneElement.itemViews
pane.destroyItem(item1)
expect(item1.parentElement).toBeNull()
expect(item2.parentElement).toBe paneElement.itemViews
pane.destroyItem(item2)
expect(item2.parentElement).toBeNull()
describe "when the destroyed item is a model", ->
it "removes the model's associated view", ->
class TestModel
atom.views.addViewProvider TestModel, (model) ->
view = document.createElement('div')
model.element = view
view.model = model
view
item1 = new TestModel
item2 = new TestModel
pane.addItem(item1)
pane.addItem(item2)
expect(item1.element.parentElement).toBe paneElement.itemViews
pane.destroyItem(item1)
expect(item1.element.parentElement).toBeNull()
expect(item2.element.parentElement).toBe paneElement.itemViews
pane.destroyItem(item2)
expect(item2.element.parentElement).toBeNull()

View File

@@ -46,27 +46,6 @@ describe "PaneView", ->
deserializerDisposable.dispose()
jasmine.restoreDeprecationsSnapshot()
describe "when an item is destroyed", ->
it "triggers the 'pane:item-removed' event with the item and its former index", ->
itemRemovedHandler = jasmine.createSpy("itemRemovedHandler")
pane.on 'pane:item-removed', itemRemovedHandler
paneModel.destroyItem(editor1)
expect(itemRemovedHandler).toHaveBeenCalled()
expect(itemRemovedHandler.argsForCall[0][1..2]).toEqual [editor1, 1]
describe "when the destroyed item is a view", ->
it "removes the item from the 'item-views' div", ->
expect(view1.parent()).toMatchSelector pane.itemViews
paneModel.destroyItem(view1)
expect(view1.parent()).not.toMatchSelector pane.itemViews
describe "when the destroyed item is a model", ->
it "removes the associated view", ->
paneModel.activateItem(editor1)
expect(pane.itemViews.find('atom-text-editor').length).toBe 1
pane.destroyItem(editor1)
expect(pane.itemViews.find('atom-text-editor').length).toBe 0
describe "when an item is moved within the same pane", ->
it "emits a 'pane:item-moved' event with the item and the new index", ->
pane.on 'pane:item-moved', itemMovedHandler = jasmine.createSpy("itemMovedHandler")