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-12-29 20:35:07 +03:00
|
|
|
platform = require './spec-helper-platform'
|
|
|
|
_ = require 'underscore-plus'
|
|
|
|
fstream = require 'fstream'
|
|
|
|
fs = require 'fs-plus'
|
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-12-04 19:57:33 +03:00
|
|
|
atom.workspace.getActiveTextEditor().setText """
|
2014-09-05 03:04:32 +04:00
|
|
|
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: ->
|
2014-12-02 04:17:13 +03:00
|
|
|
initialize: (@model) -> this
|
2014-11-28 20:56:02 +03:00
|
|
|
getModel: -> @model
|
|
|
|
|
|
|
|
beforeEach ->
|
2014-12-02 04:53:03 +03:00
|
|
|
atom.views.addViewProvider TestItem, (model) ->
|
|
|
|
new TestItemElement().initialize(model)
|
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-12-01 00:47:51 +03:00
|
|
|
itemView = atom.views.getView(atom.workspace.getLeftPanels()[0].getItem())
|
2014-11-28 20:56:02 +03:00
|
|
|
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-12-01 00:47:51 +03:00
|
|
|
itemView = atom.views.getView(atom.workspace.getRightPanels()[0].getItem())
|
2014-11-28 20:56:02 +03:00
|
|
|
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-12-01 00:47:51 +03:00
|
|
|
itemView = atom.views.getView(atom.workspace.getTopPanels()[0].getItem())
|
2014-11-28 20:56:02 +03:00
|
|
|
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-12-01 00:47:51 +03:00
|
|
|
itemView = atom.views.getView(atom.workspace.getBottomPanels()[0].getItem())
|
2014-11-28 20:56:02 +03:00
|
|
|
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
|
|
|
|
2014-12-01 00:47:51 +03:00
|
|
|
itemView = atom.views.getView(atom.workspace.getModalPanels()[0].getItem())
|
2014-11-28 20:56:02 +03:00
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
|
|
|
expect(itemView.getModel()).toBe(model)
|
2014-12-03 23:46:42 +03:00
|
|
|
|
|
|
|
describe "::panelForItem(item)", ->
|
|
|
|
it "returns the panel associated with the item", ->
|
|
|
|
item = new TestItem
|
|
|
|
panel = atom.workspace.addLeftPanel(item: item)
|
|
|
|
|
|
|
|
itemWithNoPanel = new TestItem
|
|
|
|
|
|
|
|
expect(atom.workspace.panelForItem(item)).toBe panel
|
|
|
|
expect(atom.workspace.panelForItem(itemWithNoPanel)).toBe null
|
2014-12-29 20:35:07 +03:00
|
|
|
|
|
|
|
describe "::scan(options, callback)", ->
|
|
|
|
describe "when called with a regex", ->
|
|
|
|
it "calls the callback with all regex results in all files in the project", ->
|
|
|
|
results = []
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /(a)+/, (result) ->
|
|
|
|
results.push(result)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength(3)
|
|
|
|
expect(results[0].filePath).toBe atom.project.resolve('a')
|
|
|
|
expect(results[0].matches).toHaveLength(3)
|
|
|
|
expect(results[0].matches[0]).toEqual
|
|
|
|
matchText: 'aaa'
|
|
|
|
lineText: 'aaa bbb'
|
|
|
|
lineTextOffset: 0
|
|
|
|
range: [[0, 0], [0, 3]]
|
|
|
|
|
|
|
|
it "works with with escaped literals (like $ and ^)", ->
|
|
|
|
results = []
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /\$\w+/, (result) -> results.push(result)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results.length).toBe 1
|
|
|
|
|
|
|
|
{filePath, matches} = results[0]
|
|
|
|
expect(filePath).toBe atom.project.resolve('a')
|
|
|
|
expect(matches).toHaveLength 1
|
|
|
|
expect(matches[0]).toEqual
|
|
|
|
matchText: '$bill'
|
|
|
|
lineText: 'dollar$bill'
|
|
|
|
lineTextOffset: 0
|
|
|
|
range: [[2, 6], [2, 11]]
|
|
|
|
|
|
|
|
it "works on evil filenames", ->
|
|
|
|
platform.generateEvilFiles()
|
|
|
|
atom.project.setPaths([path.join(__dirname, 'fixtures', 'evil-files')])
|
|
|
|
paths = []
|
|
|
|
matches = []
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /evil/, (result) ->
|
|
|
|
paths.push(result.filePath)
|
|
|
|
matches = matches.concat(result.matches)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
_.each(matches, (m) -> expect(m.matchText).toEqual 'evil')
|
|
|
|
|
|
|
|
if platform.isWindows()
|
|
|
|
expect(paths.length).toBe 3
|
|
|
|
expect(paths[0]).toMatch /a_file_with_utf8.txt$/
|
|
|
|
expect(paths[1]).toMatch /file with spaces.txt$/
|
|
|
|
expect(path.basename(paths[2])).toBe "utfa\u0306.md"
|
|
|
|
else
|
|
|
|
expect(paths.length).toBe 5
|
|
|
|
expect(paths[0]).toMatch /a_file_with_utf8.txt$/
|
|
|
|
expect(paths[1]).toMatch /file with spaces.txt$/
|
|
|
|
expect(paths[2]).toMatch /goddam\nnewlines$/m
|
|
|
|
expect(paths[3]).toMatch /quote".txt$/m
|
|
|
|
expect(path.basename(paths[4])).toBe "utfa\u0306.md"
|
|
|
|
|
|
|
|
it "ignores case if the regex includes the `i` flag", ->
|
|
|
|
results = []
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /DOLLAR/i, (result) -> results.push(result)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 1
|
|
|
|
|
|
|
|
describe "when the core.excludeVcsIgnoredPaths config is truthy", ->
|
|
|
|
[projectPath, ignoredPath] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
sourceProjectPath = path.join(__dirname, 'fixtures', 'git', 'working-dir')
|
|
|
|
projectPath = path.join(temp.mkdirSync("atom"))
|
|
|
|
|
|
|
|
writerStream = fstream.Writer(projectPath)
|
|
|
|
fstream.Reader(sourceProjectPath).pipe(writerStream)
|
|
|
|
|
|
|
|
waitsFor (done) ->
|
|
|
|
writerStream.on 'close', done
|
|
|
|
writerStream.on 'error', done
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
fs.rename(path.join(projectPath, 'git.git'), path.join(projectPath, '.git'))
|
|
|
|
ignoredPath = path.join(projectPath, 'ignored.txt')
|
|
|
|
fs.writeFileSync(ignoredPath, 'this match should not be included')
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
fs.removeSync(projectPath) if fs.existsSync(projectPath)
|
|
|
|
|
|
|
|
it "excludes ignored files", ->
|
|
|
|
atom.project.setPaths([projectPath])
|
|
|
|
atom.config.set('core.excludeVcsIgnoredPaths', true)
|
|
|
|
resultHandler = jasmine.createSpy("result found")
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /match/, (results) ->
|
|
|
|
resultHandler()
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(resultHandler).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "includes only files when a directory filter is specified", ->
|
|
|
|
projectPath = path.join(path.join(__dirname, 'fixtures', 'dir'))
|
|
|
|
atom.project.setPaths([projectPath])
|
|
|
|
|
|
|
|
filePath = path.join(projectPath, 'a-dir', 'oh-git')
|
|
|
|
|
|
|
|
paths = []
|
|
|
|
matches = []
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /aaa/, paths: ["a-dir#{path.sep}"], (result) ->
|
|
|
|
paths.push(result.filePath)
|
|
|
|
matches = matches.concat(result.matches)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(paths.length).toBe 1
|
|
|
|
expect(paths[0]).toBe filePath
|
|
|
|
expect(matches.length).toBe 1
|
|
|
|
|
|
|
|
it "includes files and folders that begin with a '.'", ->
|
|
|
|
projectPath = temp.mkdirSync()
|
|
|
|
filePath = path.join(projectPath, '.text')
|
|
|
|
fs.writeFileSync(filePath, 'match this')
|
|
|
|
atom.project.setPaths([projectPath])
|
|
|
|
paths = []
|
|
|
|
matches = []
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /match this/, (result) ->
|
|
|
|
paths.push(result.filePath)
|
|
|
|
matches = matches.concat(result.matches)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(paths.length).toBe 1
|
|
|
|
expect(paths[0]).toBe filePath
|
|
|
|
expect(matches.length).toBe 1
|
|
|
|
|
|
|
|
it "excludes values in core.ignoredNames", ->
|
|
|
|
projectPath = path.join(__dirname, 'fixtures', 'git', 'working-dir')
|
|
|
|
ignoredNames = atom.config.get("core.ignoredNames")
|
|
|
|
ignoredNames.push("a")
|
|
|
|
atom.config.set("core.ignoredNames", ignoredNames)
|
|
|
|
|
|
|
|
resultHandler = jasmine.createSpy("result found")
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /dollar/, (results) ->
|
|
|
|
resultHandler()
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(resultHandler).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "scans buffer contents if the buffer is modified", ->
|
|
|
|
editor = null
|
|
|
|
results = []
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open('a').then (o) ->
|
|
|
|
editor = o
|
|
|
|
editor.setText("Elephant")
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /a|Elephant/, (result) -> results.push result
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 3
|
|
|
|
resultForA = _.find results, ({filePath}) -> path.basename(filePath) == 'a'
|
|
|
|
expect(resultForA.matches).toHaveLength 1
|
|
|
|
expect(resultForA.matches[0].matchText).toBe 'Elephant'
|
|
|
|
|
|
|
|
it "ignores buffers outside the project", ->
|
|
|
|
editor = null
|
|
|
|
results = []
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open(temp.openSync().path).then (o) ->
|
|
|
|
editor = o
|
|
|
|
editor.setText("Elephant")
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /Elephant/, (result) -> results.push result
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 0
|