mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge branch 'master' of github.com:github/atom
This commit is contained in:
@@ -397,6 +397,14 @@ describe "RootView", ->
|
||||
expect(-> rootView.activateExtension({ activate: -> })).toThrow()
|
||||
|
||||
describe "deactivation", ->
|
||||
it "is deactivated and removed from the extension list", ->
|
||||
rootView.activateExtension(extension)
|
||||
expect(rootView.extensions[extension.name]).toBeTruthy()
|
||||
spyOn(extension, "deactivate").andCallThrough()
|
||||
rootView.deactivateExtension(extension)
|
||||
expect(extension.deactivate).toHaveBeenCalled()
|
||||
expect(rootView.extensions[extension.name]).toBeFalsy()
|
||||
|
||||
it "is deactivated when the rootView is deactivated", ->
|
||||
rootView.activateExtension(extension)
|
||||
spyOn(extension, "deactivate").andCallThrough()
|
||||
|
||||
@@ -22,8 +22,7 @@ describe "TreeView", ->
|
||||
expect(treeView.root.directory.subscriptionCount()).toBeGreaterThan 0
|
||||
|
||||
afterEach ->
|
||||
treeView.deactivate()
|
||||
rootView.remove()
|
||||
rootView.deactivate()
|
||||
|
||||
describe ".initialize(project)", ->
|
||||
it "renders the root of the project and its contents alphabetically with subdirectories first in a collapsed state", ->
|
||||
@@ -49,7 +48,7 @@ describe "TreeView", ->
|
||||
|
||||
describe "when the project has no path", ->
|
||||
beforeEach ->
|
||||
treeView.deactivate()
|
||||
rootView.deactivate()
|
||||
|
||||
rootView = new RootView
|
||||
rootView.activateExtension(TreeView)
|
||||
@@ -58,6 +57,9 @@ describe "TreeView", ->
|
||||
it "does not create a root node", ->
|
||||
expect(treeView.root).not.toExist()
|
||||
|
||||
it "serializes without throwing an exception", ->
|
||||
expect(-> treeView.serialize()).not.toThrow()
|
||||
|
||||
it "creates a root view when the project path is created", ->
|
||||
rootView.open(require.resolve('fixtures/sample.js'))
|
||||
expect(treeView.root.getPath()).toBe require.resolve('fixtures')
|
||||
@@ -69,16 +71,24 @@ describe "TreeView", ->
|
||||
expect(treeView.root).not.toEqual oldRoot
|
||||
expect(oldRoot.hasParent()).toBeFalsy()
|
||||
|
||||
describe "when the prototypes deactivate method is called", ->
|
||||
it "calls the deactivate on tree view instance", ->
|
||||
spyOn(treeView, "deactivate").andCallThrough()
|
||||
rootView.deactivateExtension(TreeView)
|
||||
expect(treeView.deactivate).toHaveBeenCalled()
|
||||
|
||||
describe "serialization", ->
|
||||
newTreeView = null
|
||||
[newRootView, newTreeView] = []
|
||||
|
||||
afterEach ->
|
||||
newTreeView.deactivate()
|
||||
newRootView.deactivate()
|
||||
|
||||
it "restores expanded directories and selected file when deserialized", ->
|
||||
treeView.find('.directory:contains(zed)').click()
|
||||
sampleJs.click()
|
||||
newRootView = RootView.deserialize(rootView.serialize())
|
||||
rootView.deactivate() # Deactivates previous TreeView
|
||||
|
||||
newRootView.activateExtension(TreeView)
|
||||
|
||||
newTreeView = newRootView.find(".tree-view").view()
|
||||
@@ -86,7 +96,6 @@ describe "TreeView", ->
|
||||
expect(newTreeView).toExist()
|
||||
expect(newTreeView.selectedEntry()).toMatchSelector(".file:contains(sample.js)")
|
||||
expect(newTreeView.find(".directory:contains(zed)")).toHaveClass("expanded")
|
||||
newRootView.remove()
|
||||
|
||||
it "restores the focus state of the tree view", ->
|
||||
rootView.attachToDom()
|
||||
@@ -94,13 +103,13 @@ describe "TreeView", ->
|
||||
expect(treeView).toMatchSelector ':focus'
|
||||
|
||||
newRootView = RootView.deserialize(rootView.serialize())
|
||||
rootView.remove()
|
||||
rootView.deactivate() # Deactivates previous TreeView
|
||||
|
||||
newRootView.attachToDom()
|
||||
newRootView.activateExtension(TreeView)
|
||||
|
||||
newTreeView = newRootView.find(".tree-view").view()
|
||||
expect(newTreeView).toMatchSelector ':focus'
|
||||
newRootView.remove()
|
||||
|
||||
describe "when tree-view:toggle is triggered on the root view", ->
|
||||
beforeEach ->
|
||||
@@ -432,7 +441,7 @@ describe "TreeView", ->
|
||||
[dirView, fileView, rootDirPath, dirPath, filePath] = []
|
||||
|
||||
beforeEach ->
|
||||
treeView.deactivate()
|
||||
rootView.deactivate()
|
||||
|
||||
rootDirPath = "/tmp/atom-tests"
|
||||
fs.remove(rootDirPath) if fs.exists(rootDirPath)
|
||||
@@ -445,8 +454,8 @@ describe "TreeView", ->
|
||||
|
||||
rootView = new RootView(rootDirPath)
|
||||
project = rootView.project
|
||||
treeView = new TreeView(rootView)
|
||||
treeView.root = treeView.root
|
||||
rootView.activateExtension(TreeView)
|
||||
treeView = rootView.find(".tree-view").view()
|
||||
dirView = treeView.root.entries.find('.directory:contains(test-dir)').view()
|
||||
dirView.expand()
|
||||
fileView = treeView.find('.file:contains(test-file.txt)').view()
|
||||
@@ -590,15 +599,14 @@ describe "TreeView", ->
|
||||
describe "when the path is changed and confirmed", ->
|
||||
describe "when all the directories along the new path exist", ->
|
||||
it "moves the file, updates the tree view, and closes the dialog", ->
|
||||
runs ->
|
||||
newPath = fs.join(rootDirPath, 'renamed-test-file.txt')
|
||||
moveDialog.miniEditor.setText(newPath)
|
||||
newPath = fs.join(rootDirPath, 'renamed-test-file.txt')
|
||||
moveDialog.miniEditor.setText(newPath)
|
||||
|
||||
moveDialog.trigger 'tree-view:confirm'
|
||||
moveDialog.trigger 'tree-view:confirm'
|
||||
|
||||
expect(fs.exists(newPath)).toBeTruthy()
|
||||
expect(fs.exists(filePath)).toBeFalsy()
|
||||
expect(moveDialog.parent()).not.toExist()
|
||||
expect(fs.exists(newPath)).toBeTruthy()
|
||||
expect(fs.exists(filePath)).toBeFalsy()
|
||||
expect(moveDialog.parent()).not.toExist()
|
||||
|
||||
waitsFor "tree view to update", ->
|
||||
treeView.root.find('> .entries > .file:contains(renamed-test-file.txt)').length > 0
|
||||
|
||||
@@ -72,7 +72,7 @@ class RootView extends View
|
||||
try
|
||||
extensionStates[name] = extension.serialize?()
|
||||
catch e
|
||||
console?.error("Exception serializing '#{name}' extension", e)
|
||||
console?.error("Exception serializing '#{name}' extension\n", e.stack)
|
||||
extensionStates
|
||||
|
||||
deserializeView: (viewState) ->
|
||||
@@ -87,6 +87,10 @@ class RootView extends View
|
||||
@extensions[extension.name] = extension
|
||||
extension.activate(this, @extensionStates[extension.name])
|
||||
|
||||
deactivateExtension: (extension) ->
|
||||
extension.deactivate?()
|
||||
delete @extensions[extension.name]
|
||||
|
||||
deactivate: ->
|
||||
atom.rootViewStates[$windowNumber] = JSON.stringify(@serialize())
|
||||
extension.deactivate?() for name, extension of @extensions
|
||||
|
||||
@@ -70,7 +70,7 @@ class DirectoryView extends View
|
||||
|
||||
serializeEntryExpansionStates: ->
|
||||
entryStates = {}
|
||||
@entries.find('> .directory.expanded').each ->
|
||||
@entries?.find('> .directory.expanded').each ->
|
||||
view = $(this).view()
|
||||
entryStates[view.directory.getName()] = view.serializeEntryExpansionStates()
|
||||
entryStates
|
||||
|
||||
@@ -19,6 +19,9 @@ class TreeView extends View
|
||||
@instance = new TreeView(rootView)
|
||||
@instance.attach()
|
||||
|
||||
@deactivate: () ->
|
||||
@instance.deactivate()
|
||||
|
||||
@serialize: ->
|
||||
@instance.serialize()
|
||||
|
||||
@@ -60,7 +63,7 @@ class TreeView extends View
|
||||
@focus() if @focusAfterAttach
|
||||
|
||||
serialize: ->
|
||||
directoryExpansionStates: @root.serializeEntryExpansionStates()
|
||||
directoryExpansionStates: @root?.serializeEntryExpansionStates()
|
||||
selectedPath: @selectedEntry()?.getPath()
|
||||
hasFocus: @is(':focus')
|
||||
attached: @hasParent()
|
||||
|
||||
Reference in New Issue
Block a user