Skip to content

Commit

Permalink
Merge pull request #79 from piohhmy/keyboard-tree-preview
Browse files Browse the repository at this point in the history
Add tests for tree preview command
  • Loading branch information
ddavison committed Mar 23, 2015
2 parents cfea156 + 9225808 commit 40ef276
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/sublime-tree-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SublimeTreeView extends TreeView
initialize: (state) ->
super(state)

atom.commands.add '.tree-view',
atom.commands.add @element,
'tree-view:expand-directory-or-preview-file', => @expandDirOrPreview()

@on 'dblclick', '.entry', (e) ->
Expand All @@ -26,4 +26,4 @@ class SublimeTreeView extends TreeView
if selectedEntry instanceof DirectoryView
selectedEntry.expand(false)
else if selectedEntry instanceof FileView
atom.workspace.open(selectedEntry.getPath(), activatePane:false)
@openSelectedEntry(false)
54 changes: 54 additions & 0 deletions spec/sublime-tabs-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ _ = require 'underscore-plus'
path = require 'path'
SublimeTabBarView = require '../lib/sublime-tab-bar-view'
SublimeTabView = require '../lib/sublime-tab-view'
SublimeTreeView = require '../lib/sublime-tree-view'

describe 'SublimeTabs Initialization', ->
beforeEach ->
Expand Down Expand Up @@ -154,3 +155,56 @@ describe 'SublimeTabBarView', ->
runs ->
atom.workspaceView.trigger 'core:save'
expect(tabBar.tabForItem(editor2)).not.toHaveClass 'temp'


describe "tree-view:expand-directory-or-preview-file", ->
treeView = null

beforeEach ->
fixturesPath = atom.project.getPaths()[0]
path1 = path.join(fixturesPath, "tree-view", "dir1")
atom.project.setPaths([path1])

workspaceElement = atom.views.getView(atom.workspace)

atom.workspaceView = new WorkspaceView
atom.workspace = atom.workspaceView.model

waitsForPromise ->
atom.packages.activatePackage("sublime-tabs")

runs ->
atom.commands.dispatch(workspaceElement, 'tree-view:toggle')
treeView = $(atom.workspace.getLeftPanels()[0].getItem()).view()

describe "when a collapsed directory is selected", ->
it "expands the directory", ->
subdir1 = treeView.find('.directory:eq(1)')
subdir1.click() # select and expand
subdir1.click() # collapse
expect(subdir1).not.toHaveClass 'expanded'

atom.commands.dispatch(treeView.element, 'tree-view:expand-directory-or-preview-file')

expect(subdir1).toHaveClass 'expanded'

describe "when an expanded directory is selected", ->
it "keeps the directory expanded", ->
subdir1 = treeView.find('.directory:eq(1)')
subdir1.click() # select and expand
expect(subdir1).toHaveClass 'expanded'

atom.commands.dispatch(treeView.element, 'tree-view:expand-directory-or-preview-file')

expect(subdir1).toHaveClass 'expanded'

describe "when a file is selected", ->
it "opens selected entry without loosing focus", ->
treeViewPackage = atom.packages.getActivePackage('sublime-tabs').mainModule.treeView
treeView.find('.directory:eq(1)').click()
atom.commands.dispatch(treeView.element, 'core:move-down')
spyOn(treeViewPackage, 'openSelectedEntry').andCallThrough()

atom.commands.dispatch(treeView.element, 'tree-view:expand-directory-or-preview-file')

expect(treeViewPackage.openSelectedEntry).toHaveBeenCalledWith(false)

0 comments on commit 40ef276

Please sign in to comment.