fixing the tree-view specs

This commit is contained in:
Jon Rohan
2013-01-22 16:34:35 -08:00
parent 5359a3297a
commit bfe43008ed
2 changed files with 43 additions and 31 deletions

View File

@@ -15,7 +15,7 @@ describe "TreeView", ->
atom.loadPackage("tree-view")
treeView = TreeView.instance
treeView.root = treeView.find('> li:first').view()
treeView.root = treeView.find('ol > li:first').view()
sampleJs = treeView.find('.file:contains(tree-view.js)')
sampleTxt = treeView.find('.file:contains(tree-view.txt)')
@@ -108,7 +108,7 @@ describe "TreeView", ->
it "restores the focus state of the tree view", ->
rootView.attachToDom()
treeView.focus()
expect(treeView).toMatchSelector ':focus'
expect(treeView.find(".tree-view")).toMatchSelector ':focus'
newRootView = RootView.deserialize(rootView.serialize())
rootView.deactivate() # Deactivates previous TreeView
@@ -117,7 +117,7 @@ describe "TreeView", ->
newRootView.activatePackage('tree-view', TreeView)
newTreeView = newRootView.find(".tree-view").view()
expect(newTreeView).toMatchSelector ':focus'
expect(newTreeView.find(".tree-view")).toMatchSelector ':focus'
it "restores the scroll top when toggled", ->
rootView.height(5)
@@ -154,14 +154,14 @@ describe "TreeView", ->
rootView.focus()
rootView.trigger 'tree-view:toggle'
expect(treeView).toBeVisible()
expect(treeView).toMatchSelector(':focus')
expect(treeView.find(".tree-view")).toMatchSelector(':focus')
describe "when the tree view is hidden", ->
it "shows and focuses the tree view", ->
treeView.detach()
rootView.trigger 'tree-view:toggle'
expect(treeView.hasParent()).toBeTruthy()
expect(treeView).toMatchSelector(':focus')
expect(treeView.find(".tree-view")).toMatchSelector(':focus')
describe "when tree-view:reveal-current-file is triggered on the root view", ->
beforeEach ->
@@ -196,10 +196,10 @@ describe "TreeView", ->
rootView.open() # When we trigger 'tool-panel:unfocus' below, we want an editor to become focused
rootView.attachToDom()
treeView.focus()
expect(treeView).toMatchSelector(':focus')
expect(treeView.find(".tree-view")).toMatchSelector(':focus')
treeView.trigger 'tool-panel:unfocus'
expect(treeView).toBeVisible()
expect(treeView).not.toMatchSelector(':focus')
expect(treeView.find(".tree-view")).not.toMatchSelector(':focus')
expect(rootView.getActiveEditor().isFocused).toBeTruthy()
describe "when core:close is triggered on the tree view", ->
@@ -434,7 +434,7 @@ describe "TreeView", ->
treeView.height(100)
treeView.attachToDom()
$(element).view().expand() for element in treeView.find('.directory')
expect(treeView.prop('scrollHeight')).toBeGreaterThan treeView.outerHeight()
expect(treeView.find(".tree-view").prop('scrollHeight')).toBeGreaterThan treeView.find(".tree-view").outerHeight()
expect(treeView.scrollTop()).toBe 0
@@ -458,11 +458,11 @@ describe "TreeView", ->
treeView.height(100)
treeView.attachToDom()
$(element).view().expand() for element in treeView.find('.directory')
expect(treeView.prop('scrollHeight')).toBeGreaterThan treeView.outerHeight()
expect(treeView.find(".tree-view").prop('scrollHeight')).toBeGreaterThan treeView.find(".tree-view").outerHeight()
expect(treeView.scrollTop()).toBe 0
treeView.trigger 'core:move-to-bottom'
expect(treeView.scrollBottom()).toBe treeView.prop('scrollHeight')
expect(treeView.scrollBottom()).toBe treeView.find(".tree-view").prop('scrollHeight')
it "selects the last entry", ->
expect(treeView.root).toHaveClass 'selected'
@@ -474,7 +474,7 @@ describe "TreeView", ->
treeView.height(5)
treeView.attachToDom()
$(element).view().expand() for element in treeView.find('.directory')
expect(treeView.prop('scrollHeight')).toBeGreaterThan treeView.outerHeight()
expect(treeView.find(".tree-view").prop('scrollHeight')).toBeGreaterThan treeView.find(".tree-view").outerHeight()
expect(treeView.scrollTop()).toBe 0
treeView.scrollToBottom()
@@ -489,7 +489,7 @@ describe "TreeView", ->
treeView.height(5)
treeView.attachToDom()
$(element).view().expand() for element in treeView.find('.directory')
expect(treeView.prop('scrollHeight')).toBeGreaterThan treeView.outerHeight()
expect(treeView.find(".tree-view").prop('scrollHeight')).toBeGreaterThan treeView.find(".tree-view").outerHeight()
expect(treeView.scrollTop()).toBe 0
treeView.trigger 'core:page-down'
@@ -500,14 +500,14 @@ describe "TreeView", ->
treeView.height(100)
treeView.attachToDom()
$(element).view().expand() for element in treeView.find('.directory')
expect(treeView.prop('scrollHeight')).toBeGreaterThan treeView.outerHeight()
expect(treeView.find(".tree-view").prop('scrollHeight')).toBeGreaterThan treeView.find(".tree-view").outerHeight()
treeView.moveDown()
expect(treeView.scrollTop()).toBe 0
entryCount = treeView.find(".entry").length
_.times entryCount, -> treeView.moveDown()
expect(treeView.scrollBottom() + 2).toBe treeView.prop('scrollHeight')
expect(treeView.scrollBottom()).toBe treeView.find(".tree-view").prop('scrollHeight')
_.times entryCount, -> treeView.moveUp()
expect(treeView.scrollTop()).toBe 0
@@ -687,7 +687,7 @@ describe "TreeView", ->
expect(fs.isDirectory(newPath)).toBeTruthy()
expect(addDialog.parent()).not.toExist()
expect(rootView.getActiveEditor().getPath()).not.toBe newPath
expect(treeView).toMatchSelector(':focus')
expect(treeView.find(".tree-view")).toMatchSelector(':focus')
expect(rootView.getActiveEditor().isFocused).toBeFalsy()
expect(dirView.find('.directory.selected:contains(new)').length).toBe(1)
@@ -700,7 +700,7 @@ describe "TreeView", ->
expect(fs.isDirectory(newPath)).toBeTruthy()
expect(addDialog.parent()).not.toExist()
expect(rootView.getActiveEditor().getPath()).not.toBe newPath
expect(treeView).toMatchSelector(':focus')
expect(treeView.find(".tree-view")).toMatchSelector(':focus')
expect(rootView.getActiveEditor().isFocused).toBeFalsy()
expect(dirView.find('.directory.selected:contains(new2)').length).toBe(1)
@@ -721,7 +721,7 @@ describe "TreeView", ->
treeView.attachToDom()
addDialog.trigger 'core:cancel'
expect(addDialog.parent()).not.toExist()
expect(treeView).toMatchSelector(':focus')
expect(treeView.find(".tree-view")).toMatchSelector(':focus')
describe "when the add dialog's editor loses focus", ->
it "removes the dialog and focuses root view", ->
@@ -835,7 +835,7 @@ describe "TreeView", ->
treeView.attachToDom()
moveDialog.trigger 'core:cancel'
expect(moveDialog.parent()).not.toExist()
expect(treeView).toMatchSelector(':focus')
expect(treeView.find(".tree-view")).toMatchSelector(':focus')
describe "when the move dialog's editor loses focus", ->
it "removes the dialog and focuses root view", ->

View File

@@ -74,15 +74,15 @@ class TreeView extends ScrollView
@selectEntry(@root) if @root
afterAttach: (onDom) ->
@treeViewList.focus() if @focusAfterAttach
@treeViewList.scrollTop(@scrollTopAfterAttach) if @scrollTopAfterAttach > 0
@focus() if @focusAfterAttach
@scrollTop(@scrollTopAfterAttach) if @scrollTopAfterAttach > 0
serialize: ->
directoryExpansionStates: @root?.serializeEntryExpansionStates()
selectedPath: @selectedEntry()?.getPath()
hasFocus: @hasFocus()
attached: @hasParent()
scrollTop: @treeViewList.scrollTop()
scrollTop: @scrollTop()
width: @width()
deactivate: ->
@@ -93,20 +93,23 @@ class TreeView extends ScrollView
@detach()
else
if @hasParent()
@treeViewList.focus()
@focus()
else
@attach()
attach: ->
return unless rootView.project.getPath()
@rootView.horizontal.prepend(this)
@treeViewList.focus()
@focus()
detach: ->
@scrollTopAfterAttach = @scrollTop()
super
@rootView.focus()
focus: ->
@treeViewList.focus()
hasFocus: ->
@treeViewList.is(':focus')
@@ -201,7 +204,7 @@ class TreeView extends ScrollView
else
@selectEntry(selectedEntry.parents('.directory').first())
else
@selectEntry(@find('.entry').last())
@selectEntry(@treeViewList.find('.entry').last())
@scrollToEntry(@selectedEntry())
@@ -304,15 +307,25 @@ class TreeView extends ScrollView
@treeViewList.find('.selected').removeClass('selected')
entry.addClass('selected')
scrollTop: (top) ->
if top
@treeViewList.scrollTop(top)
else
@treeViewList.scrollTop()
scrollBottom: (bottom) ->
if bottom
@treeViewList.scrollBottom(bottom)
else
@treeViewList.scrollBottom()
scrollToEntry: (entry) ->
displayElement = if entry instanceof DirectoryView then entry.header else entry
top = @treeViewList.scrollTop() + displayElement.position().top
top = @scrollTop() + displayElement.position().top
bottom = top + displayElement.outerHeight()
if bottom > @treeViewList.scrollBottom()
if bottom > @scrollBottom()
@treeViewList.scrollBottom(bottom)
if top < @treeViewList.scrollTop()
if top < @scrollTop()
@treeViewList.scrollTop(top)
scrollToBottom: ->
@@ -323,6 +336,5 @@ class TreeView extends ScrollView
scrollToTop: ->
super()
@selectEntry(@root) if @root
@scrollToEntry(@root) if @root
@treeViewList.scrollTop(0)