Skip to content

Commit

Permalink
Fix #38
Browse files Browse the repository at this point in the history
  • Loading branch information
ddavison committed Sep 8, 2014
1 parent 47d3190 commit d3e47bb
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 101 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ npm-debug.log
node_modules
*.iml
.idea/
spec/fixtures/sample.txt
4 changes: 4 additions & 0 deletions lib/sublime-tab-bar-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class SublimeTabBarView extends TabBarView
path = atom.project?.relativize(pathToOpen) ? pathToOpen
@openPermanent.push pathToOpen unless pathToOpen in @openPermanent

@subscribe atom.workspaceView, 'core:save', ->
tab = atom.workspaceView.find('.tab.active')
tab.removeClass('temp') if tab.is('.temp')

# Tabs added manually by the user should consider temporary status.
@considerTemp = true

Expand Down
21 changes: 10 additions & 11 deletions spec/sublime-tabs-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,14 @@ describe 'SublimeTabBarView', ->
runs ->
expect(tabBar.tabForItem(imageView)).toHaveClass 'temp'

describe 'when saving a file'
it 'makes the tab permanent'
editor2 = null
waitsForPromise ->
atom.workspace.open('sample.txt').then (o) ->
editor2 = o
pane.activateItem(editor2)

atom
describe 'when saving a file', ->
it 'makes the tab permanent', ->
editor2 = null
waitsForPromise ->
atom.workspace.open('sample.txt').then (o) ->
editor2 = o
pane.activateItem(editor2)

runs ->
expect(tabBar.tabForItem(editor2)).toHaveClass 'temp'
runs ->
atom.workspaceView.trigger 'core:save'
expect(tabBar.tabForItem(editor2)).not.toHaveClass 'temp'
179 changes: 89 additions & 90 deletions spec/tree-view-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
_ = require 'underscore-plus'
os = require 'os'
fs = require 'fs-plus'
path = require 'path'
temp = require('temp').track()
wrench = require 'wrench'

_ = require 'underscore-plus'
{$, $$, WorkspaceView} = require 'atom'
TreeView = require '../lib/sublime-tree-view'
fs = require 'fs-plus'
TreeView = require '../lib/sublime-tree-view'
path = require 'path'
temp = require('temp').track()
wrench = require 'wrench'
os = require 'os'

waitsForFileToOpen = (fn) ->
openHandler = jasmine.createSpy()
Expand All @@ -29,7 +28,7 @@ describe "TreeView", ->
atom.workspaceView = new WorkspaceView

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

runs ->
atom.workspaceView.trigger 'tree-view:toggle'
Expand Down Expand Up @@ -72,13 +71,13 @@ describe "TreeView", ->
describe "when the project has no path", ->
beforeEach ->
atom.project.setPath(undefined)
atom.packages.deactivatePackage("sublime-tabs")
atom.packages.deactivatePackage("tree-view")

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

runs ->
treeView = atom.packages.getActivePackage("sublime-tabs").mainModule.createView()
treeView = atom.packages.getActivePackage("tree-view").mainModule.createView()

it "does not attach to the root view or create a root node when initialized", ->
expect(treeView.hasParent()).toBeFalsy()
Expand Down Expand Up @@ -112,40 +111,40 @@ describe "TreeView", ->
expect(treeView.root).not.toExist()

describe "when the project is assigned a path because a new buffer is saved", ->
it "creates a root directory view but does not attach to the root view", ->
it "creates a root directory view and attaches to the root view", ->
waitsForPromise ->
atom.workspaceView.open()

runs ->
projectPath = temp.mkdirSync('atom-project')
atom.workspace.getActivePaneItem().saveAs(path.join(projectPath, 'test.txt'))
expect(treeView.hasParent()).toBeFalsy()
expect(treeView.hasParent()).toBeTruthy()
expect(fs.absolute(treeView.root.getPath())).toBe fs.absolute(projectPath)
expect(treeView.root.parent()).toMatchSelector(".tree-view")

describe "when the root view is opened to a file path", ->
it "does not attach to the root view but does create a root node when initialized", ->
atom.packages.deactivatePackage("sublime-tabs")
atom.packages.deactivatePackage("tree-view")
atom.packages.packageStates = {}

waitsForPromise ->
atom.workspace.open('tree-view.js')

waitsForPromise ->
atom.packages.activatePackage('sublime-tabs')
atom.packages.activatePackage('tree-view')

runs ->
treeView = atom.packages.getActivePackage("sublime-tabs").mainModule.createView()
treeView = atom.packages.getActivePackage("tree-view").mainModule.createView()
expect(treeView.hasParent()).toBeFalsy()
expect(treeView.root).toExist()

describe "when the root view is opened to a directory", ->
it "attaches to the root view", ->
waitsForPromise ->
atom.packages.activatePackage('sublime-tabs')
atom.packages.activatePackage('tree-view')

runs ->
treeView = atom.packages.getActivePackage("sublime-tabs").mainModule.createView()
treeView = atom.packages.getActivePackage("tree-view").mainModule.createView()
expect(treeView.hasParent()).toBeTruthy()
expect(treeView.root).toExist()

Expand All @@ -154,14 +153,14 @@ describe "TreeView", ->
dotGit = path.join(temp.mkdirSync('repo'), '.git')
fs.makeTreeSync(dotGit)
atom.project.setPath(dotGit)
atom.packages.deactivatePackage("sublime-tabs")
atom.packages.deactivatePackage("tree-view")
atom.packages.packageStates = {}

waitsForPromise ->
atom.packages.activatePackage('sublime-tabs')
atom.packages.activatePackage('tree-view')

runs ->
{treeView} = atom.packages.getActivePackage("sublime-tabs").mainModule
{treeView} = atom.packages.getActivePackage("tree-view").mainModule
expect(treeView).toBeFalsy()

describe "serialization", ->
Expand All @@ -172,10 +171,10 @@ describe "TreeView", ->
sampleJs.click()

runs ->
atom.packages.deactivatePackage("sublime-tabs")
atom.packages.deactivatePackage("tree-view")

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

runs ->
treeView = atom.workspaceView.find(".tree-view").view()
Expand All @@ -187,10 +186,10 @@ describe "TreeView", ->
atom.workspaceView.attachToDom()
treeView.focus()
expect(treeView.list).toMatchSelector ':focus'
atom.packages.deactivatePackage("sublime-tabs")
atom.packages.deactivatePackage("tree-view")

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

runs ->
treeView = atom.workspaceView.find(".tree-view").view()
Expand Down Expand Up @@ -514,20 +513,20 @@ describe "TreeView", ->
expect(atom.workspaceView.getActiveView().isFocused).toBeFalsy()

describe "when an directory is alt-clicked", ->
# describe "when the directory is collapsed", ->
# it "recursively expands the directory", ->
# treeView.root.click()
# treeView.root.collapse()
describe "when the directory is collapsed", ->
it "recursively expands the directory", ->
treeView.root.click()
treeView.root.collapse()

# expect(treeView.root).not.toHaveClass 'expanded'
# treeView.root.trigger clickEvent({ altKey: true })
# expect(treeView.root).toHaveClass 'expanded'
expect(treeView.root).not.toHaveClass 'expanded'
treeView.root.trigger clickEvent({ altKey: true })
expect(treeView.root).toHaveClass 'expanded'

# children = treeView.root.find('.directory')
# expect(children.length).toBeGreaterThan 0
# children.each (index, child) ->
# childView = $(child).view()
# expect(childView).toHaveClass 'expanded'
children = treeView.root.find('.directory')
expect(children.length).toBeGreaterThan 0
children.each (index, child) ->
childView = $(child).view()
expect(childView).toHaveClass 'expanded'

describe "when the directory is expanded", ->
parent = null
Expand Down Expand Up @@ -575,14 +574,14 @@ describe "TreeView", ->
dirView = treeView.root.find('.directory:contains(dir1)').view()
expect(dirView).toHaveClass 'selected'

# describe "when the item has no path", ->
# it "deselects the previously selected entry", ->
# waitsForFileToOpen ->
# sampleJs.click()
describe "when the item has no path", ->
it "deselects the previously selected entry", ->
waitsForFileToOpen ->
sampleJs.click()

# runs ->
# atom.workspaceView.getActivePaneView().activateItem($$ -> @div('hello'))
# expect(atom.workspaceView.find('.selected')).not.toExist()
runs ->
atom.workspaceView.getActivePaneView().activateItem($$ -> @div('hello'))
expect(atom.workspaceView.find('.selected')).not.toExist()

describe "when a different editor becomes active", ->
beforeEach ->
Expand Down Expand Up @@ -820,20 +819,20 @@ describe "TreeView", ->
treeView.trigger 'tree-view:expand-directory'

describe "tree-view:recursive-expand-directory", ->
# describe "when an collapsed root is recursively expanded", ->
# it "expands the root and all subdirectories", ->
# treeView.root.click()
# treeView.root.collapse()
describe "when an collapsed root is recursively expanded", ->
it "expands the root and all subdirectories", ->
treeView.root.click()
treeView.root.collapse()

# expect(treeView.root).not.toHaveClass 'expanded'
# treeView.trigger 'tree-view:recursive-expand-directory'
# expect(treeView.root).toHaveClass 'expanded'
expect(treeView.root).not.toHaveClass 'expanded'
treeView.trigger 'tree-view:recursive-expand-directory'
expect(treeView.root).toHaveClass 'expanded'

# children = treeView.root.find('.directory')
# expect(children.length).toBeGreaterThan 0
# children.each (index, child) ->
# childView = $(child).view()
# expect(childView).toHaveClass 'expanded'
children = treeView.root.find('.directory')
expect(children.length).toBeGreaterThan 0
children.each (index, child) ->
childView = $(child).view()
expect(childView).toHaveClass 'expanded'

describe "tree-view:collapse-directory", ->
subdir = null
Expand Down Expand Up @@ -890,20 +889,20 @@ describe "TreeView", ->
children.each (index, child) ->
$(child).view().expand()

# describe "when an expanded directory is recursively collapsed", ->
# it "collapses the directory and all its child directories", ->
# parent.click().expand()
# expect(parent).toHaveClass 'expanded'
# children.each (index, child) ->
# $(child).view().click().expand()
# expect($(child).view()).toHaveClass 'expanded'
describe "when an expanded directory is recursively collapsed", ->
it "collapses the directory and all its child directories", ->
parent.click().expand()
expect(parent).toHaveClass 'expanded'
children.each (index, child) ->
$(child).view().click().expand()
expect($(child).view()).toHaveClass 'expanded'

# treeView.trigger 'tree-view:recursive-collapse-directory'
treeView.trigger 'tree-view:recursive-collapse-directory'

# expect(parent).not.toHaveClass 'expanded'
# children.each (index, child) ->
# expect($(child).view()).not.toHaveClass 'expanded'
# expect(treeView.root).toHaveClass 'expanded'
expect(parent).not.toHaveClass 'expanded'
children.each (index, child) ->
expect($(child).view()).not.toHaveClass 'expanded'
expect(treeView.root).toHaveClass 'expanded'

describe "tree-view:open-selected-entry", ->
describe "when a file is selected", ->
Expand Down Expand Up @@ -941,7 +940,7 @@ describe "TreeView", ->
[dirView, fileView, dirView2, fileView2, fileView3, rootDirPath, dirPath, filePath, dirPath2, filePath2, filePath3] = []

beforeEach ->
atom.packages.deactivatePackage('sublime-tabs')
atom.packages.deactivatePackage('tree-view')

rootDirPath = fs.absolute(temp.mkdirSync('tree-view'))

Expand All @@ -962,7 +961,7 @@ describe "TreeView", ->
atom.project.setPath(rootDirPath)

waitsForPromise ->
atom.packages.activatePackage('sublime-tabs')
atom.packages.activatePackage('tree-view')

runs ->
atom.workspaceView.trigger 'tree-view:toggle'
Expand Down Expand Up @@ -1681,27 +1680,27 @@ describe "TreeView", ->
it "duplicates the current file", ->
expect(copyDialog.miniEditor.getText()).toBe('tree-view.js')

# describe "tree-view:remove", ->
# it "won't remove the root directory", ->
# spyOn(atom, 'confirm')
# atom.workspaceView.attachToDom()
# treeView.show()
# treeView.root.view().click()
# treeView.trigger 'tree-view:remove'
describe "tree-view:remove", ->
it "won't remove the root directory", ->
spyOn(atom, 'confirm')
atom.workspaceView.attachToDom()
treeView.show()
treeView.root.view().click()
treeView.trigger 'tree-view:remove'

# args = atom.confirm.mostRecentCall.args[0]
# expect(args.buttons).toEqual ['OK']
args = atom.confirm.mostRecentCall.args[0]
expect(args.buttons).toEqual ['OK']

# it "shows the native alert dialog", ->
# spyOn(atom, 'confirm')
it "shows the native alert dialog", ->
spyOn(atom, 'confirm')

# waitsForFileToOpen ->
# fileView.click()
waitsForFileToOpen ->
fileView.click()

# runs ->
# treeView.trigger 'tree-view:remove'
# args = atom.confirm.mostRecentCall.args[0]
# expect(Object.keys(args.buttons)).toEqual ['Move to Trash', 'Cancel']
runs ->
treeView.trigger 'tree-view:remove'
args = atom.confirm.mostRecentCall.args[0]
expect(Object.keys(args.buttons)).toEqual ['Move to Trash', 'Cancel']

describe "file system events", ->
temporaryFilePath = null
Expand Down Expand Up @@ -1866,7 +1865,7 @@ describe "TreeView", ->
[dirView, fileView1, fileView2, fileView3, treeView, rootDirPath, dirPath, filePath1, filePath2, filePath3] = []

beforeEach ->
atom.packages.deactivatePackage('sublime-tabs')
atom.packages.deactivatePackage('tree-view')

rootDirPath = fs.absolute(temp.mkdirSync('tree-view'))

Expand All @@ -1883,7 +1882,7 @@ describe "TreeView", ->
atom.project.setPath(rootDirPath)

waitsForPromise ->
atom.packages.activatePackage('sublime-tabs')
atom.packages.activatePackage('tree-view')

runs ->
atom.workspaceView.trigger 'tree-view:toggle'
Expand Down

0 comments on commit d3e47bb

Please sign in to comment.