From 3fad9c616fd42c4ba232314fe35dedeeea117211 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 21 Jan 2014 14:17:49 -0700 Subject: [PATCH] Move specs for Workspace::open to model layer --- spec/workspace-spec.coffee | 43 ++++++++++++++++++++++++++ spec/workspace-view-spec.coffee | 53 --------------------------------- 2 files changed, 43 insertions(+), 53 deletions(-) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index b9e2a5912..cfd1e35d5 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -7,6 +7,49 @@ describe "Workspace", -> atom.project.setPath(atom.project.resolve('dir')) workspace = new Workspace + describe "::open(uri)", -> + beforeEach -> + spyOn(workspace.activePane, 'activate') + + describe "when called without a uri", -> + it "adds and activates an empty editor on the active pane", -> + editor = null + waitsForPromise -> + workspace.open().then (o) -> editor = o + + runs -> + expect(editor.getPath()).toBeUndefined() + expect(workspace.activePane.items).toEqual [editor] + expect(workspace.activePaneItem).toBe editor + expect(workspace.activePane.activate).toHaveBeenCalled() + + describe "when called with a uri", -> + describe "when the active pane already has an editor for the given uri", -> + it "activates the existing editor on the active pane", -> + editor1 = workspace.openSync('a') + editor2 = workspace.openSync('b') + + editor = null + waitsForPromise -> + workspace.open('a').then (o) -> editor = o + + runs -> + expect(editor).toBe editor1 + expect(workspace.activePaneItem).toBe editor + expect(workspace.activePane.activate).toHaveBeenCalled() + + describe "when the active pane does not have an editor for the given uri", -> + it "adds and activates a new editor for the given path on the active pane", -> + editor = null + waitsForPromise -> + workspace.open('a').then (o) -> editor = o + + runs -> + expect(editor.getUri()).toBe 'a' + expect(workspace.activePaneItem).toBe editor + expect(workspace.activePane.items).toEqual [editor] + expect(workspace.activePane.activate).toHaveBeenCalled() + describe "::openSync(uri, options)", -> [activePane, initialItemCount] = [] diff --git a/spec/workspace-view-spec.coffee b/spec/workspace-view-spec.coffee index 00ab624aa..4e0b078e1 100644 --- a/spec/workspace-view-spec.coffee +++ b/spec/workspace-view-spec.coffee @@ -185,59 +185,6 @@ describe "WorkspaceView", -> atom.workspaceView.trigger 'window:decrease-font-size' expect(atom.config.get('editor.fontSize')).toBe 1 - describe ".open(filePath)", -> - [activePane] = [] - - beforeEach -> - spyOn(PaneView.prototype, 'focus') - activePane = atom.workspaceView.getActivePane() - - 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 = null - - waitsForPromise -> - atom.workspaceView.open().then (o) -> editor = o - - runs -> - expect(activePane.getItems().length).toBe 2 - 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 item for the given path", -> - it "shows the existing edit session in the pane", -> - previousEditor = activePane.activeItem - - editor = null - waitsForPromise -> - atom.workspaceView.open('b').then (o) -> editor = o - - runs -> - expect(activePane.activeItem).toBe editor - expect(editor).not.toBe previousEditor - - waitsForPromise -> - atom.workspaceView.open(previousEditor.getPath()).then (o) -> editor = o - - runs -> - expect(editor).toBe previousEditor - expect(activePane.activeItem).toBe editor - expect(activePane.focus).toHaveBeenCalled() - - describe "when the active pane does not have an existing item for the given path", -> - it "creates a new edit session for the given path in the active pane", -> - editor = null - - waitsForPromise -> - atom.workspaceView.open('b').then (o) -> editor = o - - runs -> - expect(activePane.activeItem).toBe editor - expect(activePane.getItems().length).toBe 2 - expect(activePane.focus).toHaveBeenCalled() - describe "window:toggle-invisibles event", -> it "shows/hides invisibles in all open and future editors", -> atom.workspaceView.height(200)