Move specs for Workspace::openSingletonSync to model layer

This commit is contained in:
Nathan Sobo
2014-01-21 12:37:26 -07:00
parent 11ab6fd2ef
commit 5e83dee493
2 changed files with 55 additions and 50 deletions

View File

@@ -65,3 +65,58 @@ describe "Workspace", ->
expect(workspace.paneContainer.root.children).toEqual [pane1, pane2]
expect(pane1.items.length).toBe 0
expect(pane2.items.length).toBe 2
describe "::openSingletonSync(uri, options)", ->
describe "when an editor for the given uri is already open on the active pane", ->
it "activates the existing editor", ->
editor1 = workspace.openSync('a')
editor2 = workspace.openSync('b')
expect(workspace.activePaneItem).toBe editor2
workspace.openSingletonSync('a')
expect(workspace.activePaneItem).toBe editor1
describe "when an editor for the given uri is already open on an inactive pane", ->
it "activates the existing editor on the inactive pane, then activates that pane", ->
editor1 = workspace.openSync('a')
pane1 = workspace.activePane
pane2 = workspace.activePane.splitRight()
editor2 = workspace.openSync('b')
expect(workspace.activePaneItem).toBe editor2
workspace.openSingletonSync('a')
expect(workspace.activePane).toBe pane1
expect(workspace.activePaneItem).toBe editor1
describe "when no editor for the given uri is open in any pane", ->
it "opens an editor for the given uri in the active pane", ->
editor1 = workspace.openSingletonSync('a')
expect(workspace.activePaneItem).toBe editor1
describe "when the 'split' option is 'left'", ->
it "opens the editor in the leftmost pane of the current pane axis", ->
pane1 = workspace.activePane
pane2 = pane1.splitRight()
expect(workspace.activePane).toBe pane2
editor1 = workspace.openSingletonSync('a', split: 'left')
expect(workspace.activePane).toBe pane1
expect(pane1.items).toEqual [editor1]
expect(pane2.items).toEqual []
describe "when the 'split' option is 'right'", ->
describe "when the active pane is in a horizontal pane axis", ->
it "activates the editor on the rightmost pane of the current pane axis", ->
pane1 = workspace.activePane
pane2 = pane1.splitRight()
pane1.activate()
editor1 = workspace.openSingletonSync('a', split: 'right')
expect(workspace.activePane).toBe pane2
expect(pane2.items).toEqual [editor1]
expect(pane1.items).toEqual []
describe "when the active pane is not in a horizontal pane axis", ->
it "splits the current pane to the right, then activates the editor on the right pane", ->
pane1 = workspace.activePane
editor1 = workspace.openSingletonSync('a', split: 'right')
pane2 = workspace.activePane
expect(workspace.paneContainer.root.children).toEqual [pane1, pane2]
expect(pane2.items).toEqual [editor1]
expect(pane1.items).toEqual []

View File

@@ -185,56 +185,6 @@ describe "WorkspaceView", ->
atom.workspaceView.trigger 'window:decrease-font-size'
expect(atom.config.get('editor.fontSize')).toBe 1
describe ".openSingletonSync(filePath, options)", ->
[pane1] = []
beforeEach ->
pane1 = atom.workspaceView.getActivePane()
it "creates a new pane and reuses the file when already open", ->
atom.workspaceView.openSingletonSync('b', split: 'right')
pane2 = atom.workspaceView.getActivePane()
expect(pane2[0]).not.toBe pane1[0]
expect(pane1.itemForUri('b')).toBeFalsy()
expect(pane2.itemForUri('b')).not.toBeFalsy()
expect(atom.workspaceView.panes.find('.pane-row .pane').toArray()).toEqual [pane1[0], pane2[0]]
pane1.activate()
expect(atom.workspaceView.getActivePane()[0]).toBe pane1[0]
atom.workspaceView.openSingletonSync('b', split: 'right')
pane3 = atom.workspaceView.getActivePane()
expect(pane3[0]).toBe pane2[0]
expect(pane1.itemForUri('b')).toBeFalsy()
expect(pane2.itemForUri('b')).not.toBeFalsy()
expect(atom.workspaceView.panes.find('.pane-row .pane').toArray()).toEqual [pane1[0], pane2[0]]
it "handles split: left by opening to the left pane when necessary", ->
atom.workspaceView.openSingletonSync('b', split: 'right')
pane2 = atom.workspaceView.getActivePane()
expect(pane2[0]).not.toBe pane1[0]
atom.workspaceView.openSingletonSync('file1', split: 'left')
activePane = atom.workspaceView.getActivePane()
expect(activePane[0]).toBe pane1[0]
expect(pane1.itemForUri('file1')).toBeTruthy()
expect(pane2.itemForUri('file1')).toBeFalsy()
expect(atom.workspaceView.panes.find('.pane-row .pane').toArray()).toEqual [pane1[0], pane2[0]]
pane2.activate()
expect(atom.workspaceView.getActivePane()[0]).toBe pane2[0]
atom.workspaceView.openSingletonSync('file1', split: 'left')
activePane = atom.workspaceView.getActivePane()
expect(activePane[0]).toBe pane1[0]
expect(atom.workspaceView.panes.find('.pane-row .pane').toArray()).toEqual [pane1[0], pane2[0]]
it "reuses the file when already open", ->
atom.workspaceView.openSync('b')
atom.workspaceView.openSingletonSync('b', split: 'right')
expect(atom.workspaceView.panes.find('.pane').toArray()).toEqual [pane1[0]]
describe ".open(filePath)", ->
[activePane] = []