Move specs for Workspace::open to model layer

This commit is contained in:
Nathan Sobo
2014-01-21 14:17:49 -07:00
parent 45875188a4
commit 3fad9c616f
2 changed files with 43 additions and 53 deletions

View File

@@ -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] = []

View File

@@ -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)