From 0758bd023117ce6fc7216f6dfd9cea604edef114 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 21 Jan 2014 10:48:29 -0700 Subject: [PATCH] Move specs for Workspace::openSync to model layer --- spec/workspace-spec.coffee | 67 +++++++++++++++++++++++++++++++++ spec/workspace-view-spec.coffee | 60 ----------------------------- 2 files changed, 67 insertions(+), 60 deletions(-) create mode 100644 spec/workspace-spec.coffee diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee new file mode 100644 index 000000000..8b4255c84 --- /dev/null +++ b/spec/workspace-spec.coffee @@ -0,0 +1,67 @@ +Workspace = require '../src/workspace' + +describe "Workspace", -> + workspace = null + + beforeEach -> + atom.project.setPath(atom.project.resolve('dir')) + workspace = new Workspace + + describe "::openSync(filePath, options)", -> + [activePane, initialItemCount] = [] + + beforeEach -> + activePane = workspace.activePane + spyOn(activePane, 'activate') + initialItemCount = activePane.items.length + + describe "when called with no path", -> + it "adds and activates an empty editor on the active pane", -> + editor = workspace.openSync() + expect(activePane.items.length).toBe initialItemCount + 1 + expect(activePane.activeItem).toBe editor + expect(editor.getPath()).toBeUndefined() + expect(activePane.activate).toHaveBeenCalled() + + describe "when called with a path", -> + describe "when the active pane already has an editor for the given path", -> + it "activates the existing editor on the active pane", -> + editor1 = workspace.openSync('a') + editor2 = workspace.openSync('b') + expect(activePane.activeItem).toBe editor2 + expect(activePane.items.length).toBe 2 + + editor = workspace.openSync(editor1.getPath()) + expect(editor).toBe editor1 + expect(activePane.activeItem).toBe editor + expect(activePane.activate).toHaveBeenCalled() + expect(activePane.items.length).toBe 2 + + describe "when the active pane does not have an editor for the path being opened", -> + it "adds and activates a new editor for the given path on the active pane", -> + editor = workspace.openSync('a') + expect(activePane.items.length).toBe 1 + expect(activePane.activeItem).toBe editor + expect(activePane.activate).toHaveBeenCalled() + + describe "when the 'activatePane' option is false", -> + it "does not activate the active pane", -> + workspace.openSync('b', activatePane: false) + expect(activePane.activate).not.toHaveBeenCalled() + + describe "when the 'split' option is specified", -> + it "activates the editor on the active pane if it has a sibling and otherwise creates a new pane", -> + pane1 = workspace.activePane + + editor = workspace.openSync('a', split: 'right') + pane2 = workspace.activePane + expect(pane2).not.toBe pane1 + + expect(workspace.paneContainer.root.children).toEqual [pane1, pane2] + + editor = workspace.openSync('file1', split: 'right') + expect(workspace.activePane).toBe pane2 + + expect(workspace.paneContainer.root.children).toEqual [pane1, pane2] + expect(pane1.items.length).toBe 0 + expect(pane2.items.length).toBe 2 diff --git a/spec/workspace-view-spec.coffee b/spec/workspace-view-spec.coffee index 5af9caffd..30ea866b5 100644 --- a/spec/workspace-view-spec.coffee +++ b/spec/workspace-view-spec.coffee @@ -185,66 +185,6 @@ describe "WorkspaceView", -> atom.workspaceView.trigger 'window:decrease-font-size' expect(atom.config.get('editor.fontSize')).toBe 1 - describe ".openSync(filePath, options)", -> - [activePane, initialItemCount] = [] - beforeEach -> - activePane = atom.workspaceView.getActivePane() - spyOn(activePane, 'focus') - initialItemCount = activePane.getItems().length - - describe "when called with no path", -> - it "opens an edit session with an empty buffer as an item in the active pane and focuses it", -> - editor = atom.workspaceView.openSync() - expect(activePane.getItems().length).toBe initialItemCount + 1 - expect(activePane.activeItem).toBe editor - expect(editor.getPath()).toBeUndefined() - expect(activePane.focus).toHaveBeenCalled() - - describe "when called with a path", -> - describe "when the active pane already has an edit session item for the path being opened", -> - it "shows the existing edit session in the pane", -> - previousEditor = activePane.activeItem - - editor = atom.workspaceView.openSync('b') - expect(activePane.activeItem).toBe editor - expect(editor).not.toBe previousEditor - - editor = atom.workspaceView.openSync(previousEditor.getPath()) - expect(editor).toBe previousEditor - expect(activePane.activeItem).toBe editor - - expect(activePane.focus).toHaveBeenCalled() - - describe "when the active pane does not have an edit session item for the path being opened", -> - it "creates a new edit session for the given path in the active editor", -> - editor = atom.workspaceView.openSync('b') - expect(activePane.items.length).toBe 2 - expect(activePane.activeItem).toBe editor - expect(activePane.focus).toHaveBeenCalled() - - describe "when the changeFocus option is false", -> - it "does not focus the active pane", -> - editor = atom.workspaceView.openSync('b', changeFocus: false) - expect(activePane.focus).not.toHaveBeenCalled() - - describe "when the split option is 'right'", -> - it "creates a new pane and opens the file in said pane", -> - pane1 = atom.workspaceView.getActivePane() - - editor = atom.workspaceView.openSync('b', split: 'right') - pane2 = atom.workspaceView.getActivePane() - expect(pane2[0]).not.toBe pane1[0] - expect(editor.getPath()).toBe require.resolve('./fixtures/dir/b') - - expect(atom.workspaceView.panes.find('.pane-row .pane').toArray()).toEqual [pane1[0], pane2[0]] - - editor = atom.workspaceView.openSync('file1', split: 'right') - pane3 = atom.workspaceView.getActivePane() - expect(pane3[0]).toBe pane2[0] - expect(editor.getPath()).toBe require.resolve('./fixtures/dir/file1') - - expect(atom.workspaceView.panes.find('.pane-row .pane').toArray()).toEqual [pane1[0], pane2[0]] - describe ".openSingletonSync(filePath, options)", -> [pane1] = [] beforeEach ->