2014-01-21 21:48:29 +04:00
|
|
|
Workspace = require '../src/workspace'
|
|
|
|
|
2014-04-23 01:19:01 +04:00
|
|
|
describe "Workspace", ->
|
2014-01-21 21:48:29 +04:00
|
|
|
workspace = null
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
atom.project.setPath(atom.project.resolve('dir'))
|
2014-04-08 21:52:19 +04:00
|
|
|
atom.workspace = workspace = new Workspace
|
2014-01-21 21:48:29 +04:00
|
|
|
|
2014-02-04 07:00:50 +04:00
|
|
|
describe "::open(uri, options)", ->
|
2014-01-22 01:17:49 +04:00
|
|
|
beforeEach ->
|
2014-02-04 07:00:50 +04:00
|
|
|
spyOn(workspace.activePane, 'activate').andCallThrough()
|
2014-01-22 01:17:49 +04:00
|
|
|
|
2014-02-04 07:00:50 +04:00
|
|
|
describe "when the 'searchAllPanes' option is false (default)", ->
|
|
|
|
describe "when called without a uri", ->
|
|
|
|
it "adds and activates an empty editor on the active pane", ->
|
2014-03-02 02:40:48 +04:00
|
|
|
[editor1, editor2] = []
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open().then (editor) -> editor1 = editor
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(editor1.getPath()).toBeUndefined()
|
|
|
|
expect(workspace.activePane.items).toEqual [editor1]
|
|
|
|
expect(workspace.activePaneItem).toBe editor1
|
|
|
|
expect(workspace.activePane.activate).toHaveBeenCalled()
|
|
|
|
|
2014-02-04 07:00:50 +04:00
|
|
|
waitsForPromise ->
|
2014-03-02 02:40:48 +04:00
|
|
|
workspace.open().then (editor) -> editor2 = editor
|
2014-01-22 01:17:49 +04:00
|
|
|
|
2014-02-04 07:00:50 +04:00
|
|
|
runs ->
|
2014-03-02 02:40:48 +04:00
|
|
|
expect(editor2.getPath()).toBeUndefined()
|
|
|
|
expect(workspace.activePane.items).toEqual [editor1, editor2]
|
|
|
|
expect(workspace.activePaneItem).toBe editor2
|
2014-02-04 07:00:50 +04:00
|
|
|
expect(workspace.activePane.activate).toHaveBeenCalled()
|
2014-01-22 01:17:49 +04:00
|
|
|
|
2014-02-04 07:00:50 +04:00
|
|
|
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", ->
|
|
|
|
editor = null
|
2014-04-22 22:24:27 +04:00
|
|
|
editor1 = null
|
|
|
|
editor2 = null
|
|
|
|
|
2014-02-04 07:00:50 +04:00
|
|
|
waitsForPromise ->
|
2014-04-22 22:24:27 +04:00
|
|
|
workspace.open('a').then (o) ->
|
|
|
|
editor1 = o
|
|
|
|
workspace.open('b').then (o) ->
|
|
|
|
editor2 = o
|
|
|
|
workspace.open('a').then (o) ->
|
|
|
|
editor = o
|
2014-02-04 07:00:50 +04:00
|
|
|
|
|
|
|
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 ->
|
2014-02-19 06:57:45 +04:00
|
|
|
expect(editor.getUri()).toBe atom.project.resolve('a')
|
2014-02-04 07:00:50 +04:00
|
|
|
expect(workspace.activePaneItem).toBe editor
|
|
|
|
expect(workspace.activePane.items).toEqual [editor]
|
|
|
|
expect(workspace.activePane.activate).toHaveBeenCalled()
|
|
|
|
|
|
|
|
describe "when the 'searchAllPanes' option is true", ->
|
|
|
|
describe "when an editor for the given uri is already open on an inactive pane", ->
|
2014-04-24 03:19:43 +04:00
|
|
|
it "activates the existing editor on the inactive pane, then activates that pane", ->
|
2014-04-22 22:24:27 +04:00
|
|
|
editor1 = null
|
|
|
|
editor2 = null
|
|
|
|
pane1 = workspace.getActivePane()
|
|
|
|
pane2 = workspace.getActivePane().splitRight()
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
pane1.activate()
|
|
|
|
workspace.open('a').then (o) -> editor1 = o
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
pane2.activate()
|
|
|
|
workspace.open('b').then (o) -> editor2 = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.activePaneItem).toBe editor2
|
2014-02-04 07:00:50 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', searchAllPanes: true)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.activePane).toBe pane1
|
|
|
|
expect(workspace.activePaneItem).toBe editor1
|
2014-01-22 01:17:49 +04:00
|
|
|
|
2014-02-04 07:00:50 +04:00
|
|
|
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", ->
|
2014-01-22 01:17:49 +04:00
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
2014-02-04 07:00:50 +04:00
|
|
|
workspace.open('a', searchAllPanes: true).then (o) -> editor = o
|
2014-01-22 01:17:49 +04:00
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.activePaneItem).toBe editor
|
|
|
|
|
2014-02-04 07:00:50 +04:00
|
|
|
describe "when the 'split' option is set", ->
|
|
|
|
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
|
|
|
|
|
2014-01-22 01:17:49 +04:00
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
2014-02-04 07:00:50 +04:00
|
|
|
workspace.open('a', split: 'left').then (o) -> editor = o
|
2014-01-22 01:17:49 +04:00
|
|
|
|
|
|
|
runs ->
|
2014-02-04 07:00:50 +04:00
|
|
|
expect(workspace.activePane).toBe pane1
|
|
|
|
expect(pane1.items).toEqual [editor]
|
|
|
|
expect(pane2.items).toEqual []
|
|
|
|
|
2014-02-04 22:07:17 +04:00
|
|
|
# Focus right pane and reopen the file on the left
|
|
|
|
waitsForPromise ->
|
|
|
|
pane2.focus()
|
|
|
|
workspace.open('a', split: 'left').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.activePane).toBe pane1
|
|
|
|
expect(pane1.items).toEqual [editor]
|
|
|
|
expect(pane2.items).toEqual []
|
2014-05-05 20:09:25 +04:00
|
|
|
|
2014-05-05 20:16:40 +04:00
|
|
|
describe "when a pane axis is the leftmost sibling of the current pane", ->
|
2014-05-05 20:09:25 +04:00
|
|
|
it "opens the new item in the current pane", ->
|
|
|
|
editor = null
|
|
|
|
pane1 = workspace.activePane
|
|
|
|
pane2 = pane1.splitLeft()
|
|
|
|
pane3 = pane2.splitDown()
|
|
|
|
pane1.activate()
|
|
|
|
expect(workspace.activePane).toBe pane1
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', split: 'left').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.activePane).toBe pane1
|
|
|
|
expect(pane1.items).toEqual [editor]
|
2014-02-04 07:00:50 +04:00
|
|
|
|
2014-02-04 22:07:17 +04:00
|
|
|
describe "when the 'split' option is 'right'", ->
|
|
|
|
it "opens the editor in the rightmost pane of the current pane axis", ->
|
2014-02-04 07:00:50 +04:00
|
|
|
editor = null
|
2014-02-04 22:07:17 +04:00
|
|
|
pane1 = workspace.activePane
|
|
|
|
pane2 = null
|
2014-02-04 07:00:50 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', split: 'right').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
2014-02-04 22:07:17 +04:00
|
|
|
pane2 = workspace.getPanes().filter((p) -> p != pane1)[0]
|
2014-02-04 07:00:50 +04:00
|
|
|
expect(workspace.activePane).toBe pane2
|
|
|
|
expect(pane1.items).toEqual []
|
2014-02-04 22:07:17 +04:00
|
|
|
expect(pane2.items).toEqual [editor]
|
2014-02-04 07:00:50 +04:00
|
|
|
|
2014-02-04 22:07:17 +04:00
|
|
|
# Focus right pane and reopen the file on the right
|
2014-02-04 07:00:50 +04:00
|
|
|
waitsForPromise ->
|
2014-02-04 22:07:17 +04:00
|
|
|
pane1.focus()
|
2014-02-04 07:00:50 +04:00
|
|
|
workspace.open('a', split: 'right').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
2014-02-04 22:07:17 +04:00
|
|
|
expect(workspace.activePane).toBe pane2
|
2014-02-04 07:00:50 +04:00
|
|
|
expect(pane1.items).toEqual []
|
2014-02-04 22:07:17 +04:00
|
|
|
expect(pane2.items).toEqual [editor]
|
2014-01-22 01:17:49 +04:00
|
|
|
|
2014-05-05 20:16:40 +04:00
|
|
|
describe "when a pane axis is the rightmost sibling of the current pane", ->
|
2014-05-02 20:28:34 +04:00
|
|
|
it "opens the new item in a new pane split to the right of the current pane", ->
|
|
|
|
editor = null
|
|
|
|
pane1 = workspace.activePane
|
|
|
|
pane2 = pane1.splitRight()
|
|
|
|
pane3 = pane2.splitDown()
|
|
|
|
pane1.activate()
|
|
|
|
expect(workspace.activePane).toBe pane1
|
|
|
|
pane4 = null
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', split: 'right').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
pane4 = workspace.getPanes().filter((p) -> p != pane1)[0]
|
|
|
|
expect(workspace.activePane).toBe pane4
|
|
|
|
expect(pane4.items).toEqual [editor]
|
|
|
|
expect(workspace.paneContainer.root.children[0]).toBe pane1
|
|
|
|
expect(workspace.paneContainer.root.children[1]).toBe pane4
|
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
describe "when passed a path that matches a custom opener", ->
|
|
|
|
it "returns the resource returned by the custom opener", ->
|
|
|
|
fooOpener = (pathToOpen, options) -> { foo: pathToOpen, options } if pathToOpen?.match(/\.foo/)
|
|
|
|
barOpener = (pathToOpen) -> { bar: pathToOpen } if pathToOpen?.match(/^bar:\/\//)
|
|
|
|
workspace.registerOpener(fooOpener)
|
|
|
|
workspace.registerOpener(barOpener)
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2014-02-14 01:55:37 +04:00
|
|
|
pathToOpen = atom.project.resolve('a.foo')
|
2014-02-13 04:56:00 +04:00
|
|
|
workspace.open(pathToOpen, hey: "there").then (item) ->
|
|
|
|
expect(item).toEqual { foo: pathToOpen, options: {hey: "there"} }
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open("bar://baz").then (item) ->
|
|
|
|
expect(item).toEqual { bar: "bar://baz" }
|
|
|
|
|
2014-04-08 21:52:19 +04:00
|
|
|
it "emits an 'editor-created' event", ->
|
|
|
|
absolutePath = require.resolve('./fixtures/dir/a')
|
|
|
|
newEditorHandler = jasmine.createSpy('newEditorHandler')
|
|
|
|
workspace.on 'editor-created', newEditorHandler
|
|
|
|
|
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open(absolutePath).then (e) -> editor = e
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(newEditorHandler).toHaveBeenCalledWith editor
|
|
|
|
|
2014-04-23 01:15:07 +04:00
|
|
|
describe "::reopenItem()", ->
|
2014-01-22 01:20:48 +04:00
|
|
|
it "opens the uri associated with the last closed pane that isn't currently open", ->
|
|
|
|
pane = workspace.activePane
|
2014-04-22 22:24:27 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a').then ->
|
|
|
|
workspace.open('b').then ->
|
|
|
|
workspace.open('file1').then ->
|
|
|
|
workspace.open()
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
# does not reopen items with no uri
|
|
|
|
expect(workspace.activePaneItem.getUri()).toBeUndefined()
|
|
|
|
pane.destroyActiveItem()
|
2014-04-23 01:15:07 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.reopenItem()
|
|
|
|
|
|
|
|
runs ->
|
2014-04-22 22:24:27 +04:00
|
|
|
expect(workspace.activePaneItem.getUri()).not.toBeUndefined()
|
|
|
|
|
|
|
|
# destroy all items
|
|
|
|
expect(workspace.activePaneItem.getUri()).toBe atom.project.resolve('file1')
|
|
|
|
pane.destroyActiveItem()
|
|
|
|
expect(workspace.activePaneItem.getUri()).toBe atom.project.resolve('b')
|
|
|
|
pane.destroyActiveItem()
|
|
|
|
expect(workspace.activePaneItem.getUri()).toBe atom.project.resolve('a')
|
|
|
|
pane.destroyActiveItem()
|
|
|
|
|
|
|
|
# reopens items with uris
|
|
|
|
expect(workspace.activePaneItem).toBeUndefined()
|
2014-04-23 01:15:07 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.reopenItem()
|
|
|
|
|
|
|
|
runs ->
|
2014-04-22 22:24:27 +04:00
|
|
|
expect(workspace.activePaneItem.getUri()).toBe atom.project.resolve('a')
|
2014-01-22 01:20:48 +04:00
|
|
|
|
|
|
|
# does not reopen items that are already open
|
2014-04-22 22:24:27 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('b')
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.activePaneItem.getUri()).toBe atom.project.resolve('b')
|
2014-04-23 01:15:07 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.reopenItem()
|
|
|
|
|
|
|
|
runs ->
|
2014-04-22 22:24:27 +04:00
|
|
|
expect(workspace.activePaneItem.getUri()).toBe atom.project.resolve('file1')
|
2014-01-22 01:34:15 +04:00
|
|
|
|
|
|
|
describe "::increase/decreaseFontSize()", ->
|
|
|
|
it "increases/decreases the font size without going below 1", ->
|
|
|
|
atom.config.set('editor.fontSize', 1)
|
|
|
|
workspace.increaseFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe 2
|
|
|
|
workspace.increaseFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe 3
|
|
|
|
workspace.decreaseFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe 2
|
|
|
|
workspace.decreaseFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe 1
|
|
|
|
workspace.decreaseFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe 1
|
2014-02-22 00:08:26 +04:00
|
|
|
|
|
|
|
describe "::openLicense()", ->
|
|
|
|
it "opens the license as plain-text in a buffer", ->
|
|
|
|
waitsForPromise -> workspace.openLicense()
|
|
|
|
runs -> expect(workspace.activePaneItem.getText()).toMatch /Copyright/
|
2014-04-08 21:52:19 +04:00
|
|
|
|
|
|
|
describe "when an editor is destroyed", ->
|
|
|
|
it "removes the editor", ->
|
|
|
|
editor = null
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open("a").then (e) -> editor = e
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.getEditors()).toHaveLength 1
|
|
|
|
editor.destroy()
|
|
|
|
expect(workspace.getEditors()).toHaveLength 0
|
|
|
|
|
|
|
|
describe "when an editor is copied", ->
|
2014-04-11 22:14:46 +04:00
|
|
|
it "emits an 'editor-created' event", ->
|
2014-04-22 22:24:27 +04:00
|
|
|
editor = null
|
2014-04-08 21:52:19 +04:00
|
|
|
handler = jasmine.createSpy('editorCreatedHandler')
|
|
|
|
workspace.on 'editor-created', handler
|
|
|
|
|
2014-04-22 22:24:27 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open("a").then (o) -> editor = o
|
2014-04-08 21:52:19 +04:00
|
|
|
|
2014-04-22 22:24:27 +04:00
|
|
|
runs ->
|
|
|
|
expect(handler.callCount).toBe 1
|
|
|
|
editorCopy = editor.copy()
|
|
|
|
expect(handler.callCount).toBe 2
|
2014-06-24 03:55:44 +04:00
|
|
|
|
|
|
|
it "stores the active grammars used by all the open editor", ->
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.packages.activatePackage('language-javascript')
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open('sample.js')
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
state = atom.workspace.serialize()
|
|
|
|
expect(state.packagesWithActiveGrammars).toEqual ['language-javascript']
|