From 92258087d3a9d9e10e1078d18b9e06fcbe04c20c Mon Sep 17 00:00:00 2001 From: Danny Varner Date: Sun, 22 Mar 2015 00:06:51 -0700 Subject: [PATCH] Add tests for tree preview command --- lib/sublime-tree-view.coffee | 4 +-- spec/sublime-tabs-spec.coffee | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/lib/sublime-tree-view.coffee b/lib/sublime-tree-view.coffee index d1fe975..32a35b8 100644 --- a/lib/sublime-tree-view.coffee +++ b/lib/sublime-tree-view.coffee @@ -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) -> @@ -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) diff --git a/spec/sublime-tabs-spec.coffee b/spec/sublime-tabs-spec.coffee index bb31216..bad9b47 100644 --- a/spec/sublime-tabs-spec.coffee +++ b/spec/sublime-tabs-spec.coffee @@ -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 -> @@ -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)