Serialize package states independently of RootView

Previously, package specs needed to deactivate the root view to test
their package serialization. Now, specs can just deactivate and then
reactivate the package, relying on serialization infrastructure that's
independent of the lifecycle of the RootView.
This commit is contained in:
Nathan Sobo
2013-03-25 15:37:11 -06:00
parent f5774972e9
commit bb8b3782b9
12 changed files with 35 additions and 49 deletions

View File

@@ -29,7 +29,7 @@ describe "RootView", ->
buffer = editor1.getBuffer()
editor1.splitRight()
viewState = rootView.serialize()
rootView.deactivate()
rootView.remove()
window.rootView = deserialize(viewState)
rootView.attachToDom()
@@ -54,7 +54,7 @@ describe "RootView", ->
pane2.focus()
viewState = rootView.serialize()
rootView.deactivate()
rootView.remove()
window.rootView = deserialize(viewState)
rootView.attachToDom()
@@ -91,7 +91,7 @@ describe "RootView", ->
expect(rootView.getEditors().length).toBe 0
viewState = rootView.serialize()
rootView.deactivate()
rootView.remove()
window.rootView = deserialize(viewState)
rootView.attachToDom()

View File

@@ -76,8 +76,9 @@ beforeEach ->
afterEach ->
keymap.bindingSets = bindingSetsToRestore
keymap.bindingSetsByFirstKeystrokeToRestore = bindingSetsByFirstKeystrokeToRestore
atom.deactivatePackages()
if rootView?
rootView.deactivate?()
rootView.remove?()
window.rootView = null
if project?
project.destroy()

View File

@@ -27,11 +27,6 @@ _.extend atom,
setPackageState: (name, state) ->
@packageStates[name] = state
serializeAtomPackages: ->
for pack in @getActivePackages()
@setPackageState(pack.name, state) if state = pack.serialize?()
@packageStates
activatePackages: ->
@activatePackage(pack.path) for pack in @getLoadedPackages()

View File

@@ -29,8 +29,7 @@ class RootView extends View
@div id: 'vertical', outlet: 'vertical', =>
@subview 'panes', panes ? new PaneContainer
@deserialize: ({ panes, packages, projectPath }) ->
atom.packageStates = packages ? {}
@deserialize: ({ panes }) ->
panes = deserialize(panes) if panes?.deserializer is 'PaneContainer'
new RootView({panes})
@@ -73,7 +72,6 @@ class RootView extends View
version: RootView.version
deserializer: 'RootView'
panes: @panes.serialize()
packages: atom.serializeAtomPackages()
confirmClose: ->
@panes.confirmClose()
@@ -94,10 +92,6 @@ class RootView extends View
afterAttach: (onDom) ->
@focus() if onDom
deactivate: ->
atom.deactivatePackages()
@remove()
open: (path, options = {}) ->
changeFocus = options.changeFocus ? true
path = project.resolve(path) if path?

View File

@@ -61,10 +61,12 @@ window.shutdown = ->
return if not project and not rootView
atom.setWindowState('pathToOpen', project.getPath())
atom.setWindowState('project', project.serialize())
atom.setWindowState('rootView', rootView.serialize())
atom.setWindowState('syntax', syntax.serialize())
atom.setWindowState('rootView', rootView.serialize())
atom.deactivatePackages()
atom.setWindowState('packageStates', atom.packageStates)
rootView.remove()
atom.saveWindowState()
rootView.deactivate()
project.destroy()
git?.destroy()
$(window).off('focus blur before')
@@ -95,6 +97,7 @@ window.deserializeWindowState = ->
windowState = atom.getWindowState()
atom.packageStates = windowState.packageStates ? {}
window.project = deserialize(windowState.project) ? new Project(pathToOpen)
window.rootView = deserialize(windowState.rootView) ? new RootView

View File

@@ -65,6 +65,9 @@ class CommandPanelView extends View
destroy: ->
@previewList.destroy()
rootView.off "command-panel:toggle-preview command-panel:find-in-file command-panel:find-in-project \
command-panel:repeat-relative-address command-panel:repeat-relative-address-in-reverse command-panel:set-selection-as-regex-address"
@remove()
toggle: ->
if @miniEditor.isFocused

View File

@@ -28,10 +28,7 @@ describe "CommandPanel", ->
rootView.trigger 'command-panel:toggle'
expect(commandPanel.miniEditor.isFocused).toBeTruthy()
rootViewState = rootView.serialize()
rootView.deactivate()
window.rootView = RootView.deserialize(rootViewState)
rootView.attachToDom()
atom.deactivatePackage('command-panel')
atom.activatePackage('command-panel')
expect(rootView.find('.command-panel')).not.toExist()
@@ -55,13 +52,12 @@ describe "CommandPanel", ->
expect(commandPanel.history[2]).toBe('/test3')
expect(commandPanel.historyIndex).toBe(3)
rootViewState = rootView.serialize()
rootView.deactivate()
RootView.deserialize(rootViewState).attachToDom()
atom.deactivatePackage('command-panel')
atom.activatePackage('command-panel')
rootView.trigger 'command-panel:toggle'
rootView.trigger 'command-panel:toggle'
commandPanel = rootView.find('.command-panel').view()
expect(commandPanel.history.length).toBe(2)
expect(commandPanel.history[0]).toBe('/test2')
expect(commandPanel.history[1]).toBe('/test3')

View File

@@ -143,8 +143,8 @@ describe 'FuzzyFinder', ->
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
rootView.open()
states = rootView.serialize().packages
states = _.map states['fuzzy-finder'], (path, time) -> [ path, time ]
atom.deactivatePackage('fuzzy-finder')
states = _.map atom.getPackageState('fuzzy-finder'), (path, time) -> [ path, time ]
states = _.sortBy states, (path, time) -> -time
paths = [ 'sample-with-tabs.coffee', 'sample.txt', 'sample.js' ]

View File

@@ -22,4 +22,4 @@ module.exports =
nextPane.showItem(new MarkdownPreviewView(editSession.buffer))
else
activePane.splitRight(new MarkdownPreviewView(editSession.buffer))
activePane.focus()
activePane.focus()

View File

@@ -32,7 +32,7 @@ describe "StatusBar", ->
describe "when associated with an unsaved buffer", ->
it "displays 'untitled' instead of the buffer's path, but still displays the buffer position", ->
rootView.deactivate()
rootView.remove()
window.rootView = new RootView
rootView.open()
rootView.simulateDomAttachment()

View File

@@ -40,8 +40,8 @@ class TreeView extends ScrollView
else
@selectActiveFile()
rootView.on 'pane:active-item-changed pane:became-active', => @selectActiveFile()
project.on 'path-changed', => @updateRoot()
rootView.on 'pane:active-item-changed.tree-view pane:became-active.tree-view', => @selectActiveFile()
project.on 'path-changed.tree-view', => @updateRoot()
@observeConfig 'core.hideGitIgnoredFiles', => @updateRoot()
if @root
@@ -67,6 +67,9 @@ class TreeView extends ScrollView
deactivate: ->
@root?.unwatchEntries()
rootView.off('.tree-view')
project.off('.tree-view')
@remove()
toggle: ->
if @hasFocus()

View File

@@ -47,9 +47,7 @@ describe "TreeView", ->
describe "when the project has no path", ->
beforeEach ->
project.setPath(undefined)
rootView.deactivate()
window.rootView = new RootView()
rootView.open()
atom.deactivatePackage("tree-view")
treeView = atom.activatePackage("tree-view").mainModule.createView()
it "does not attach to the root view or create a root node when initialized", ->
@@ -66,6 +64,7 @@ describe "TreeView", ->
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", ->
rootView.open()
rootView.getActivePaneItem().saveAs("/tmp/test.txt")
expect(treeView.hasParent()).toBeFalsy()
expect(treeView.root.getPath()).toBe '/tmp'
@@ -73,10 +72,9 @@ describe "TreeView", ->
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", ->
rootView.deactivate()
window.rootView = new RootView
rootView.open('tree-view.js')
atom.deactivatePackage("tree-view")
atom.packageStates = {}
rootView.open('tree-view.js')
treeView = atom.activatePackage("tree-view").mainModule.createView()
expect(treeView.hasParent()).toBeFalsy()
expect(treeView.root).toExist()
@@ -92,9 +90,7 @@ describe "TreeView", ->
treeView.find('.directory:contains(dir1)').click()
sampleJs.click()
rootViewState = rootView.serialize()
rootView.deactivate()
window.rootView = RootView.deserialize(rootViewState)
atom.deactivatePackage("tree-view")
atom.activatePackage("tree-view")
treeView = rootView.find(".tree-view").view()
@@ -106,12 +102,7 @@ describe "TreeView", ->
rootView.attachToDom()
treeView.focus()
expect(treeView.find(".tree-view")).toMatchSelector ':focus'
rootViewState = rootView.serialize()
rootView.deactivate()
window.rootView = RootView.deserialize(rootViewState)
rootView.attachToDom()
atom.deactivatePackage("tree-view")
atom.activatePackage("tree-view")
treeView = rootView.find(".tree-view").view()
expect(treeView.find(".tree-view")).toMatchSelector ':focus'
@@ -600,7 +591,7 @@ describe "TreeView", ->
[dirView, fileView, rootDirPath, dirPath, filePath] = []
beforeEach ->
rootView.deactivate()
atom.deactivatePackage('tree-view')
rootDirPath = fs.join(fs.absolute("/tmp"), "atom-tests")
fs.remove(rootDirPath) if fs.exists(rootDirPath)
@@ -612,7 +603,7 @@ describe "TreeView", ->
fs.write(filePath, "doesn't matter")
project.setPath(rootDirPath)
window.rootView = new RootView(rootDirPath)
atom.activatePackage('tree-view')
rootView.trigger 'tree-view:toggle'
treeView = rootView.find(".tree-view").view()