From f5c7061257df0640ea6e10e2b7f85de416c84cf9 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 3 Sep 2015 09:32:04 -0600 Subject: [PATCH] Move workspace serialization specs to workspace-spec --- spec/workspace-spec.coffee | 58 ++++++++++++++++++++ spec/workspace-view-spec.coffee | 95 --------------------------------- 2 files changed, 58 insertions(+), 95 deletions(-) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index ea4566bd0..836f17f13 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -17,6 +17,64 @@ describe "Workspace", -> atom.workspace = workspace = new Workspace waits(1) + describe "serialization", -> + simulateReload = -> + workspaceState = atom.workspace.serialize() + projectState = atom.project.serialize() + atom.workspace.destroy() + atom.project.destroy() + atom.project = atom.deserializers.deserialize(projectState) + atom.workspace = Workspace.deserialize(workspaceState) + + describe "when the workspace contains text editors", -> + it "constructs the view with the same panes", -> + pane1 = atom.workspace.getActivePane() + pane2 = pane1.splitRight(copyActiveItem: true) + pane3 = pane2.splitRight(copyActiveItem: true) + pane4 = null + + waitsForPromise -> + atom.workspace.open('b').then (editor) -> + pane2.activateItem(editor.copy()) + + waitsForPromise -> + atom.workspace.open('../sample.js').then (editor) -> + pane3.activateItem(editor) + + runs -> + pane3.activeItem.setCursorScreenPosition([2, 4]) + pane4 = pane2.splitDown() + + waitsForPromise -> + atom.workspace.open('../sample.txt').then (editor) -> + pane4.activateItem(editor) + + runs -> + pane4.getActiveItem().setCursorScreenPosition([0, 2]) + pane2.activate() + + simulateReload() + + expect(atom.workspace.getTextEditors().length).toBe 4 + [editor1, editor2, editor3, editor4] = atom.workspace.getTextEditors() + + expect(editor1.getPath()).toBe atom.project.getDirectories()[0]?.resolve('b') + expect(editor2.getPath()).toBe atom.project.getDirectories()[0]?.resolve('../sample.txt') + expect(editor2.getCursorScreenPosition()).toEqual [0, 2] + expect(editor3.getPath()).toBe atom.project.getDirectories()[0]?.resolve('b') + expect(editor4.getPath()).toBe atom.project.getDirectories()[0]?.resolve('../sample.js') + expect(editor4.getCursorScreenPosition()).toEqual [2, 4] + + expect(atom.workspace.getActiveTextEditor().getPath()).toBe editor3.getPath() + expect(document.title).toBe "#{path.basename(editor3.getPath())} - #{atom.project.getPaths()[0]} - Atom" + + describe "where there are no open panes or editors", -> + it "constructs the view with no open editors", -> + atom.workspace.getActivePane().destroy() + expect(atom.workspace.getTextEditors().length).toBe 0 + simulateReload() + expect(atom.workspace.getTextEditors().length).toBe 0 + describe "::open(uri, options)", -> openEvents = null diff --git a/spec/workspace-view-spec.coffee b/spec/workspace-view-spec.coffee index a160cdb39..b667b04db 100644 --- a/spec/workspace-view-spec.coffee +++ b/spec/workspace-view-spec.coffee @@ -25,101 +25,6 @@ describe "WorkspaceView", -> afterEach -> jasmine.restoreDeprecationsSnapshot() - describe "@deserialize()", -> - viewState = null - - simulateReload = -> - workspaceState = atom.workspace.serialize() - projectState = atom.project.serialize() - atom.workspaceView.remove() - atom.project = atom.deserializers.deserialize(projectState) - atom.workspace = Workspace.deserialize(workspaceState) - atom.workspaceView = atom.views.getView(atom.workspace).__spacePenView - atom.workspaceView.attachToDom() - - describe "when the serialized WorkspaceView has an unsaved buffer", -> - it "constructs the view with the same panes", -> - atom.workspaceView.attachToDom() - - waitsForPromise -> - atom.workspace.open() - - runs -> - editorView1 = atom.workspaceView.getActiveView() - buffer = editorView1.getEditor().getBuffer() - editorView1.getPaneView().getModel().splitRight(copyActiveItem: true) - expect(atom.workspaceView.getActivePaneView()).toBe atom.workspaceView.getPaneViews()[1] - - simulateReload() - - expect(atom.workspaceView.getEditorViews().length).toBe 2 - expect(atom.workspaceView.getActivePaneView()).toBe atom.workspaceView.getPaneViews()[1] - expect(document.title).toBe "untitled - #{atom.project.getPaths()[0]} - Atom" - - describe "when there are open editors", -> - it "constructs the view with the same panes", -> - atom.workspaceView.attachToDom() - pane1 = atom.workspaceView.getActivePaneView() - pane2 = pane1.splitRight() - pane3 = pane2.splitRight() - pane4 = null - - waitsForPromise -> - atom.workspace.open('b').then (editor) -> - pane2.activateItem(editor.copy()) - - waitsForPromise -> - atom.workspace.open('../sample.js').then (editor) -> - pane3.activateItem(editor) - - runs -> - pane3.activeItem.setCursorScreenPosition([2, 4]) - pane4 = pane2.splitDown() - - waitsForPromise -> - atom.workspace.open('../sample.txt').then (editor) -> - pane4.activateItem(editor) - - runs -> - pane4.activeItem.setCursorScreenPosition([0, 2]) - pane2.focus() - - simulateReload() - - expect(atom.workspaceView.getEditorViews().length).toBe 4 - editorView1 = atom.workspaceView.panes.find('atom-pane-axis.horizontal > atom-pane atom-text-editor:eq(0)').view() - editorView3 = atom.workspaceView.panes.find('atom-pane-axis.horizontal > atom-pane atom-text-editor:eq(1)').view() - editorView2 = atom.workspaceView.panes.find('atom-pane-axis.horizontal > atom-pane-axis.vertical > atom-pane atom-text-editor:eq(0)').view() - editorView4 = atom.workspaceView.panes.find('atom-pane-axis.horizontal > atom-pane-axis.vertical > atom-pane atom-text-editor:eq(1)').view() - - expect(editorView1.getEditor().getPath()).toBe atom.project.getDirectories()[0]?.resolve('a') - expect(editorView2.getEditor().getPath()).toBe atom.project.getDirectories()[0]?.resolve('b') - expect(editorView3.getEditor().getPath()).toBe atom.project.getDirectories()[0]?.resolve('../sample.js') - expect(editorView3.getEditor().getCursorScreenPosition()).toEqual [2, 4] - expect(editorView4.getEditor().getPath()).toBe atom.project.getDirectories()[0]?.resolve('../sample.txt') - expect(editorView4.getEditor().getCursorScreenPosition()).toEqual [0, 2] - - # ensure adjust pane dimensions is called - expect(editorView1.width()).toBeGreaterThan 0 - expect(editorView2.width()).toBeGreaterThan 0 - expect(editorView3.width()).toBeGreaterThan 0 - expect(editorView4.width()).toBeGreaterThan 0 - - # ensure correct editorView is focused again - expect(editorView2).toHaveFocus() - expect(editorView1).not.toHaveFocus() - expect(editorView3).not.toHaveFocus() - expect(editorView4).not.toHaveFocus() - - expect(document.title).toBe "#{path.basename(editorView2.getEditor().getPath())} - #{atom.project.getPaths()[0]} - Atom" - - describe "where there are no open editors", -> - it "constructs the view with no open editors", -> - atom.workspaceView.getActivePaneView().remove() - expect(atom.workspaceView.getEditorViews().length).toBe 0 - simulateReload() - expect(atom.workspaceView.getEditorViews().length).toBe 0 - describe "focus", -> beforeEach -> atom.workspaceView.attachToDom()