2014-09-25 02:26:54 +04:00
|
|
|
path = require 'path'
|
|
|
|
temp = require 'temp'
|
2014-01-21 21:48:29 +04:00
|
|
|
Workspace = require '../src/workspace'
|
2014-09-17 03:44:03 +04:00
|
|
|
{View} = require '../src/space-pen-extensions'
|
2014-01-21 21:48:29 +04:00
|
|
|
|
2014-10-04 02:23:54 +04:00
|
|
|
describe "Workspace", ->
|
2014-01-21 21:48:29 +04:00
|
|
|
workspace = null
|
|
|
|
|
|
|
|
beforeEach ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([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-09-04 16:57:59 +04:00
|
|
|
openEvents = null
|
|
|
|
|
2014-01-22 01:17:49 +04:00
|
|
|
beforeEach ->
|
2014-09-04 16:57:59 +04:00
|
|
|
openEvents = []
|
|
|
|
workspace.onDidOpen (event) -> openEvents.push(event)
|
2014-09-04 16:57:46 +04:00
|
|
|
spyOn(workspace.getActivePane(), '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()
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane().items).toEqual [editor1]
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem()).toBe editor1
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane().activate).toHaveBeenCalled()
|
2014-09-04 16:57:59 +04:00
|
|
|
expect(openEvents).toEqual [{uri: undefined, pane: workspace.getActivePane(), item: editor1, index: 0}]
|
|
|
|
openEvents = []
|
2014-03-02 02:40:48 +04:00
|
|
|
|
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()
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane().items).toEqual [editor1, editor2]
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem()).toBe editor2
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane().activate).toHaveBeenCalled()
|
2014-09-04 16:57:59 +04:00
|
|
|
expect(openEvents).toEqual [{uri: undefined, pane: workspace.getActivePane(), item: editor2, index: 1}]
|
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
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem()).toBe editor
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane().activate).toHaveBeenCalled()
|
2014-02-04 07:00:50 +04:00
|
|
|
|
2014-09-04 16:57:59 +04:00
|
|
|
expect(openEvents).toEqual [
|
|
|
|
{
|
|
|
|
uri: atom.project.resolve('a')
|
|
|
|
item: editor1
|
|
|
|
pane: atom.workspace.getActivePane()
|
|
|
|
index: 0
|
|
|
|
}
|
|
|
|
{
|
|
|
|
uri: atom.project.resolve('b')
|
|
|
|
item: editor2
|
|
|
|
pane: atom.workspace.getActivePane()
|
|
|
|
index: 1
|
|
|
|
}
|
|
|
|
{
|
|
|
|
uri: atom.project.resolve('a')
|
|
|
|
item: editor1
|
|
|
|
pane: atom.workspace.getActivePane()
|
|
|
|
index: 0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2014-02-04 07:00:50 +04:00
|
|
|
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-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem()).toBe editor
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane().items).toEqual [editor]
|
|
|
|
expect(workspace.getActivePane().activate).toHaveBeenCalled()
|
2014-02-04 07:00:50 +04:00
|
|
|
|
|
|
|
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 ->
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem()).toBe editor2
|
2014-02-04 07:00:50 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', searchAllPanes: true)
|
|
|
|
|
|
|
|
runs ->
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane()).toBe pane1
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem()).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 ->
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem()).toBe editor
|
2014-01-22 01:17:49 +04:00
|
|
|
|
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", ->
|
2014-09-04 16:57:46 +04:00
|
|
|
pane1 = workspace.getActivePane()
|
2014-02-04 07:00:50 +04:00
|
|
|
pane2 = pane1.splitRight()
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane()).toBe pane2
|
2014-02-04 07:00:50 +04:00
|
|
|
|
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-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane()).toBe pane1
|
2014-02-04 07:00:50 +04:00
|
|
|
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 ->
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane()).toBe pane1
|
2014-02-04 22:07:17 +04:00
|
|
|
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
|
2014-09-04 16:57:46 +04:00
|
|
|
pane1 = workspace.getActivePane()
|
2014-05-05 20:09:25 +04:00
|
|
|
pane2 = pane1.splitLeft()
|
|
|
|
pane3 = pane2.splitDown()
|
|
|
|
pane1.activate()
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane()).toBe pane1
|
2014-05-05 20:09:25 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', split: 'left').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane()).toBe pane1
|
2014-05-05 20:09:25 +04:00
|
|
|
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-09-04 16:57:46 +04:00
|
|
|
pane1 = workspace.getActivePane()
|
2014-02-04 22:07:17 +04:00
|
|
|
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-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane()).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-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-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane()).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
|
2014-09-04 16:57:46 +04:00
|
|
|
pane1 = workspace.getActivePane()
|
2014-05-02 20:28:34 +04:00
|
|
|
pane2 = pane1.splitRight()
|
|
|
|
pane3 = pane2.splitDown()
|
|
|
|
pane1.activate()
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane()).toBe pane1
|
2014-05-02 20:28:34 +04:00
|
|
|
pane4 = null
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', split: 'right').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
pane4 = workspace.getPanes().filter((p) -> p != pane1)[0]
|
2014-09-04 16:57:46 +04:00
|
|
|
expect(workspace.getActivePane()).toBe pane4
|
2014-05-02 20:28:34 +04:00
|
|
|
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:\/\//)
|
2014-10-01 03:09:35 +04:00
|
|
|
workspace.addOpener(fooOpener)
|
|
|
|
workspace.addOpener(barOpener)
|
2014-02-13 04:56:00 +04:00
|
|
|
|
|
|
|
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-09-04 05:26:07 +04:00
|
|
|
it "notifies ::onDidAddTextEditor observers", ->
|
2014-04-08 21:52:19 +04:00
|
|
|
absolutePath = require.resolve('./fixtures/dir/a')
|
|
|
|
newEditorHandler = jasmine.createSpy('newEditorHandler')
|
2014-09-04 05:26:07 +04:00
|
|
|
workspace.onDidAddTextEditor newEditorHandler
|
2014-04-08 21:52:19 +04:00
|
|
|
|
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open(absolutePath).then (e) -> editor = e
|
|
|
|
|
|
|
|
runs ->
|
2014-09-04 05:26:07 +04:00
|
|
|
expect(newEditorHandler.argsForCall[0][0].textEditor).toBe editor
|
2014-04-08 21:52:19 +04:00
|
|
|
|
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", ->
|
2014-09-04 16:57:46 +04:00
|
|
|
pane = workspace.getActivePane()
|
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
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem().getUri()).toBeUndefined()
|
2014-04-22 22:24:27 +04:00
|
|
|
pane.destroyActiveItem()
|
2014-04-23 01:15:07 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.reopenItem()
|
|
|
|
|
|
|
|
runs ->
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem().getUri()).not.toBeUndefined()
|
2014-04-22 22:24:27 +04:00
|
|
|
|
|
|
|
# destroy all items
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem().getUri()).toBe atom.project.resolve('file1')
|
2014-04-22 22:24:27 +04:00
|
|
|
pane.destroyActiveItem()
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem().getUri()).toBe atom.project.resolve('b')
|
2014-04-22 22:24:27 +04:00
|
|
|
pane.destroyActiveItem()
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem().getUri()).toBe atom.project.resolve('a')
|
2014-04-22 22:24:27 +04:00
|
|
|
pane.destroyActiveItem()
|
|
|
|
|
|
|
|
# reopens items with uris
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem()).toBeUndefined()
|
2014-04-23 01:15:07 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.reopenItem()
|
|
|
|
|
|
|
|
runs ->
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem().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 ->
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem().getUri()).toBe atom.project.resolve('b')
|
2014-04-23 01:15:07 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.reopenItem()
|
|
|
|
|
|
|
|
runs ->
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getActivePaneItem().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()
|
2014-09-04 05:26:19 +04:00
|
|
|
runs -> expect(workspace.getActivePaneItem().getText()).toMatch /Copyright/
|
2014-04-08 21:52:19 +04:00
|
|
|
|
2014-08-29 04:28:10 +04:00
|
|
|
describe "::observeTextEditors()", ->
|
|
|
|
it "invokes the observer with current and future text editors", ->
|
|
|
|
observed = []
|
|
|
|
|
|
|
|
waitsForPromise -> workspace.open()
|
|
|
|
waitsForPromise -> workspace.open()
|
|
|
|
waitsForPromise -> workspace.openLicense()
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
workspace.observeTextEditors (editor) -> observed.push(editor)
|
|
|
|
|
|
|
|
waitsForPromise -> workspace.open()
|
|
|
|
|
|
|
|
expect(observed).toEqual workspace.getTextEditors()
|
|
|
|
|
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 ->
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getTextEditors()).toHaveLength 1
|
2014-04-08 21:52:19 +04:00
|
|
|
editor.destroy()
|
2014-09-04 05:26:19 +04:00
|
|
|
expect(workspace.getTextEditors()).toHaveLength 0
|
2014-04-08 21:52:19 +04:00
|
|
|
|
2014-06-24 04:36:14 +04:00
|
|
|
it "stores the active grammars used by all the open editors", ->
|
2014-06-24 03:55:44 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.packages.activatePackage('language-javascript')
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2014-06-24 19:14:11 +04:00
|
|
|
atom.packages.activatePackage('language-coffee-script')
|
|
|
|
|
2014-09-05 03:04:32 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.packages.activatePackage('language-todo')
|
|
|
|
|
2014-06-24 19:14:11 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open('sample.coffee')
|
2014-06-24 03:55:44 +04:00
|
|
|
|
|
|
|
runs ->
|
2014-09-05 03:04:32 +04:00
|
|
|
atom.workspace.getActiveEditor().setText """
|
|
|
|
i = /test/; #FIXME
|
|
|
|
"""
|
2014-06-24 19:14:11 +04:00
|
|
|
|
2014-06-24 03:55:44 +04:00
|
|
|
state = atom.workspace.serialize()
|
2014-09-05 03:04:32 +04:00
|
|
|
expect(state.packagesWithActiveGrammars).toEqual ['language-coffee-script', 'language-javascript', 'language-todo']
|
2014-06-24 04:36:14 +04:00
|
|
|
|
|
|
|
jsPackage = atom.packages.getLoadedPackage('language-javascript')
|
2014-06-24 19:14:11 +04:00
|
|
|
coffeePackage = atom.packages.getLoadedPackage('language-coffee-script')
|
2014-06-24 04:36:14 +04:00
|
|
|
spyOn(jsPackage, 'loadGrammarsSync')
|
2014-06-24 19:14:11 +04:00
|
|
|
spyOn(coffeePackage, 'loadGrammarsSync')
|
|
|
|
|
2014-06-24 04:36:14 +04:00
|
|
|
workspace2 = Workspace.deserialize(state)
|
2014-06-24 04:41:33 +04:00
|
|
|
expect(jsPackage.loadGrammarsSync.callCount).toBe 1
|
2014-06-24 19:14:11 +04:00
|
|
|
expect(coffeePackage.loadGrammarsSync.callCount).toBe 1
|
2014-09-25 02:26:54 +04:00
|
|
|
|
|
|
|
describe "document.title", ->
|
|
|
|
describe "when the project has no path", ->
|
|
|
|
it "sets the title to 'untitled'", ->
|
2014-11-27 19:09:33 +03:00
|
|
|
atom.project.setPaths([])
|
2014-10-14 04:48:06 +04:00
|
|
|
expect(document.title).toBe 'untitled - Atom'
|
2014-09-25 02:26:54 +04:00
|
|
|
|
|
|
|
describe "when the project has a path", ->
|
|
|
|
beforeEach ->
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open('b')
|
|
|
|
|
|
|
|
describe "when there is an active pane item", ->
|
|
|
|
it "sets the title to the pane item's title plus the project path", ->
|
|
|
|
item = atom.workspace.getActivePaneItem()
|
2014-10-14 04:48:06 +04:00
|
|
|
expect(document.title).toBe "#{item.getTitle()} - #{atom.project.getPaths()[0]} - Atom"
|
2014-09-25 02:26:54 +04:00
|
|
|
|
|
|
|
describe "when the title of the active pane item changes", ->
|
|
|
|
it "updates the window title based on the item's new title", ->
|
|
|
|
editor = atom.workspace.getActivePaneItem()
|
|
|
|
editor.buffer.setPath(path.join(temp.dir, 'hi'))
|
2014-10-14 04:48:06 +04:00
|
|
|
expect(document.title).toBe "#{editor.getTitle()} - #{atom.project.getPaths()[0]} - Atom"
|
2014-09-25 02:26:54 +04:00
|
|
|
|
|
|
|
describe "when the active pane's item changes", ->
|
|
|
|
it "updates the title to the new item's title plus the project path", ->
|
|
|
|
atom.workspace.getActivePane().activateNextItem()
|
|
|
|
item = atom.workspace.getActivePaneItem()
|
2014-10-14 04:48:06 +04:00
|
|
|
expect(document.title).toBe "#{item.getTitle()} - #{atom.project.getPaths()[0]} - Atom"
|
2014-09-25 02:26:54 +04:00
|
|
|
|
|
|
|
describe "when the last pane item is removed", ->
|
|
|
|
it "updates the title to contain the project's path", ->
|
|
|
|
atom.workspace.getActivePane().destroy()
|
|
|
|
expect(atom.workspace.getActivePaneItem()).toBeUndefined()
|
2014-10-14 04:48:06 +04:00
|
|
|
expect(document.title).toBe "#{atom.project.getPaths()[0]} - Atom"
|
2014-09-25 02:26:54 +04:00
|
|
|
|
|
|
|
describe "when an inactive pane's item changes", ->
|
|
|
|
it "does not update the title", ->
|
|
|
|
pane = atom.workspace.getActivePane()
|
|
|
|
pane.splitRight()
|
|
|
|
initialTitle = document.title
|
|
|
|
pane.activateNextItem()
|
|
|
|
expect(document.title).toBe initialTitle
|
|
|
|
|
|
|
|
describe "when the workspace is deserialized", ->
|
|
|
|
beforeEach ->
|
|
|
|
waitsForPromise -> atom.workspace.open('a')
|
|
|
|
|
|
|
|
it "updates the title to contain the project's path", ->
|
|
|
|
document.title = null
|
|
|
|
workspace2 = atom.workspace.testSerialization()
|
|
|
|
item = atom.workspace.getActivePaneItem()
|
2014-10-14 04:48:06 +04:00
|
|
|
expect(document.title).toBe "#{item.getTitle()} - #{atom.project.getPaths()[0]} - Atom"
|
2014-09-25 02:26:54 +04:00
|
|
|
workspace2.destroy()
|
2014-09-25 03:00:05 +04:00
|
|
|
|
|
|
|
describe "document edited status", ->
|
|
|
|
[item1, item2] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
waitsForPromise -> atom.workspace.open('a')
|
|
|
|
waitsForPromise -> atom.workspace.open('b')
|
|
|
|
runs ->
|
|
|
|
[item1, item2] = atom.workspace.getPaneItems()
|
|
|
|
spyOn(atom, 'setDocumentEdited')
|
|
|
|
|
|
|
|
it "calls atom.setDocumentEdited when the active item changes", ->
|
|
|
|
expect(atom.workspace.getActivePaneItem()).toBe item2
|
|
|
|
item1.insertText('a')
|
|
|
|
expect(item1.isModified()).toBe true
|
|
|
|
atom.workspace.getActivePane().activateNextItem()
|
|
|
|
|
|
|
|
expect(atom.setDocumentEdited).toHaveBeenCalledWith(true)
|
|
|
|
|
|
|
|
it "calls atom.setDocumentEdited when the active item's modified status changes", ->
|
|
|
|
expect(atom.workspace.getActivePaneItem()).toBe item2
|
|
|
|
item2.insertText('a')
|
|
|
|
advanceClock(item2.getBuffer().getStoppedChangingDelay())
|
|
|
|
|
|
|
|
expect(item2.isModified()).toBe true
|
|
|
|
expect(atom.setDocumentEdited).toHaveBeenCalledWith(true)
|
|
|
|
|
|
|
|
item2.undo()
|
|
|
|
advanceClock(item2.getBuffer().getStoppedChangingDelay())
|
|
|
|
|
|
|
|
expect(item2.isModified()).toBe false
|
|
|
|
expect(atom.setDocumentEdited).toHaveBeenCalledWith(false)
|
2014-10-15 04:45:13 +04:00
|
|
|
|
|
|
|
describe "adding panels", ->
|
2014-11-28 20:56:02 +03:00
|
|
|
class TestItem
|
|
|
|
|
|
|
|
class TestItemElement extends HTMLElement
|
|
|
|
constructor: ->
|
|
|
|
setModel: (@model) ->
|
|
|
|
getModel: -> @model
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
atom.views.addViewProvider(
|
|
|
|
modelConstructor: TestItem
|
|
|
|
viewConstructor: TestItemElement
|
|
|
|
)
|
2014-10-15 04:45:13 +04:00
|
|
|
|
|
|
|
describe '::addLeftPanel(model)', ->
|
2014-10-17 03:17:44 +04:00
|
|
|
it 'adds a panel to the correct panel container', ->
|
2014-11-28 20:56:02 +03:00
|
|
|
expect(atom.workspace.getLeftPanels().length).toBe(0)
|
2014-10-17 03:17:44 +04:00
|
|
|
atom.workspace.panelContainers.left.onDidAddPanel addPanelSpy = jasmine.createSpy()
|
2014-11-28 20:56:02 +03:00
|
|
|
|
|
|
|
model = new TestItem
|
|
|
|
panel = atom.workspace.addLeftPanel(item: model)
|
2014-10-15 04:45:13 +04:00
|
|
|
|
|
|
|
expect(panel).toBeDefined()
|
2014-10-17 03:17:44 +04:00
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
|
|
|
|
2014-11-28 20:56:02 +03:00
|
|
|
itemView = atom.workspace.getLeftPanels()[0].getItemView()
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
|
|
|
expect(itemView.getModel()).toBe(model)
|
|
|
|
|
2014-10-17 03:17:44 +04:00
|
|
|
describe '::addRightPanel(model)', ->
|
|
|
|
it 'adds a panel to the correct panel container', ->
|
2014-11-28 20:56:02 +03:00
|
|
|
expect(atom.workspace.getRightPanels().length).toBe(0)
|
2014-10-17 03:17:44 +04:00
|
|
|
atom.workspace.panelContainers.right.onDidAddPanel addPanelSpy = jasmine.createSpy()
|
2014-11-28 20:56:02 +03:00
|
|
|
|
|
|
|
model = new TestItem
|
|
|
|
panel = atom.workspace.addRightPanel(item: model)
|
2014-10-17 03:17:44 +04:00
|
|
|
|
|
|
|
expect(panel).toBeDefined()
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
|
|
|
|
2014-11-28 20:56:02 +03:00
|
|
|
itemView = atom.workspace.getRightPanels()[0].getItemView()
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
|
|
|
expect(itemView.getModel()).toBe(model)
|
|
|
|
|
2014-10-17 03:17:44 +04:00
|
|
|
describe '::addTopPanel(model)', ->
|
|
|
|
it 'adds a panel to the correct panel container', ->
|
2014-11-28 20:56:02 +03:00
|
|
|
expect(atom.workspace.getTopPanels().length).toBe(0)
|
2014-10-17 03:17:44 +04:00
|
|
|
atom.workspace.panelContainers.top.onDidAddPanel addPanelSpy = jasmine.createSpy()
|
2014-11-28 20:56:02 +03:00
|
|
|
|
|
|
|
model = new TestItem
|
|
|
|
panel = atom.workspace.addTopPanel(item: model)
|
2014-10-17 03:17:44 +04:00
|
|
|
|
|
|
|
expect(panel).toBeDefined()
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
|
|
|
|
2014-11-28 20:56:02 +03:00
|
|
|
itemView = atom.workspace.getTopPanels()[0].getItemView()
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
|
|
|
expect(itemView.getModel()).toBe(model)
|
|
|
|
|
2014-10-17 03:17:44 +04:00
|
|
|
describe '::addBottomPanel(model)', ->
|
|
|
|
it 'adds a panel to the correct panel container', ->
|
2014-11-28 20:56:02 +03:00
|
|
|
expect(atom.workspace.getBottomPanels().length).toBe(0)
|
2014-10-17 03:17:44 +04:00
|
|
|
atom.workspace.panelContainers.bottom.onDidAddPanel addPanelSpy = jasmine.createSpy()
|
2014-11-28 20:56:02 +03:00
|
|
|
|
|
|
|
model = new TestItem
|
|
|
|
panel = atom.workspace.addBottomPanel(item: model)
|
2014-10-17 03:17:44 +04:00
|
|
|
|
|
|
|
expect(panel).toBeDefined()
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
2014-11-04 22:43:51 +03:00
|
|
|
|
2014-11-28 20:56:02 +03:00
|
|
|
itemView = atom.workspace.getBottomPanels()[0].getItemView()
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
|
|
|
expect(itemView.getModel()).toBe(model)
|
|
|
|
|
2014-11-04 22:43:51 +03:00
|
|
|
describe '::addModalPanel(model)', ->
|
|
|
|
it 'adds a panel to the correct panel container', ->
|
2014-11-28 20:56:02 +03:00
|
|
|
expect(atom.workspace.getModalPanels().length).toBe(0)
|
2014-11-04 22:43:51 +03:00
|
|
|
atom.workspace.panelContainers.modal.onDidAddPanel addPanelSpy = jasmine.createSpy()
|
2014-11-28 20:56:02 +03:00
|
|
|
|
|
|
|
model = new TestItem
|
|
|
|
panel = atom.workspace.addModalPanel(item: model)
|
2014-11-04 22:43:51 +03:00
|
|
|
|
|
|
|
expect(panel).toBeDefined()
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
2014-11-28 20:56:02 +03:00
|
|
|
|
|
|
|
itemView = atom.workspace.getModalPanels()[0].getItemView()
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
|
|
|
expect(itemView.getModel()).toBe(model)
|