Skip to content

Commit

Permalink
Test deserialization in terms of user-observable functionality
Browse files Browse the repository at this point in the history
- Rework serialization/deserialization test
- Move simulateReload function so that it can be used in multiple
describe blocks
  • Loading branch information
jasonrudolph committed Jun 2, 2017
1 parent 9629cae commit 44a2be7
Showing 1 changed file with 39 additions and 42 deletions.
81 changes: 39 additions & 42 deletions spec/workspace-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,35 @@ describe('Workspace', () => {

afterEach(() => temp.cleanupSync())

describe('serialization', () => {
const simulateReload = () => {
const workspaceState = atom.workspace.serialize()
const projectState = atom.project.serialize({isUnloading: true})
atom.workspace.destroy()
atom.project.destroy()
atom.project = new Project({
notificationManager: atom.notifications,
packageManager: atom.packages,
confirm: atom.confirm.bind(atom),
applicationDelegate: atom.applicationDelegate
})
atom.project.deserialize(projectState)
atom.workspace = new Workspace({
config: atom.config,
project: atom.project,
packageManager: atom.packages,
grammarRegistry: atom.grammars,
styleManager: atom.styles,
deserializerManager: atom.deserializers,
notificationManager: atom.notifications,
applicationDelegate: atom.applicationDelegate,
viewRegistry: atom.views,
assert: atom.assert.bind(atom),
textEditorRegistry: atom.textEditors
})
return atom.workspace.deserialize(workspaceState, atom.deserializers)
}
const simulateReload = () => {
const workspaceState = workspace.serialize()
const projectState = atom.project.serialize({isUnloading: true})
workspace.destroy()
atom.project.destroy()
atom.project = new Project({
notificationManager: atom.notifications,
packageManager: atom.packages,
confirm: atom.confirm.bind(atom),
applicationDelegate: atom.applicationDelegate
})
atom.project.deserialize(projectState)
workspace = atom.workspace = new Workspace({
config: atom.config,
project: atom.project,
packageManager: atom.packages,
grammarRegistry: atom.grammars,
styleManager: atom.styles,
deserializerManager: atom.deserializers,
notificationManager: atom.notifications,
applicationDelegate: atom.applicationDelegate,
viewRegistry: atom.views,
assert: atom.assert.bind(atom),
textEditorRegistry: atom.textEditors
})
return workspace.deserialize(workspaceState, atom.deserializers)
}

describe('serialization', () => {
describe('when the workspace contains text editors', () => {
it('constructs the view with the same panes', () => {
const pane1 = atom.workspace.getActivePane()
Expand Down Expand Up @@ -120,20 +120,6 @@ describe('Workspace', () => {
expect(atom.workspace.getTextEditors().length).toBe(0)
})
})

it('remembers whether the workspace had an active text editor', async () => {
await atom.workspace.open('../sample.txt')
expect(atom.workspace.hasActiveTextEditor).toBe(true)

simulateReload()
expect(atom.workspace.hasActiveTextEditor).toBe(true)

atom.workspace.getActivePane().destroy()
expect(atom.workspace.hasActiveTextEditor).toBe(false)

simulateReload()
expect(atom.workspace.hasActiveTextEditor).toBe(false)
})
})

describe('::open(itemOrURI, options)', () => {
Expand Down Expand Up @@ -1518,6 +1504,17 @@ describe('Workspace', () => {

expect(observed).toEqual([])
})

it('invokes the observer when closing the one and only text editor after deserialization', async () => {
pane.activateItem(new TextEditor())

simulateReload()

const editor = workspace.getActiveTextEditor()
workspace.observeActiveTextEditor(editor => observed.push(editor))
workspace.closeActivePaneItemOrEmptyPaneOrWindow()
expect(observed).toEqual([editor, undefined])
})
})

describe('when an editor is destroyed', () => {
Expand Down

0 comments on commit 44a2be7

Please sign in to comment.