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'
|
2015-10-02 21:12:16 +03:00
|
|
|
Project = require '../src/project'
|
2015-01-08 04:14:26 +03:00
|
|
|
Pane = require '../src/pane'
|
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", ->
|
2015-10-03 01:18:51 +03:00
|
|
|
[workspace, setDocumentEdited] = []
|
2014-01-21 21:48:29 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2015-10-12 11:39:35 +03:00
|
|
|
workspace = atom.workspace
|
|
|
|
workspace.resetFontSize()
|
2015-10-14 03:54:48 +03:00
|
|
|
spyOn(atom.applicationDelegate, "confirm")
|
|
|
|
setDocumentEdited = spyOn(atom.applicationDelegate, 'setWindowDocumentEdited')
|
2015-01-10 01:54:54 +03:00
|
|
|
atom.project.setPaths([atom.project.getDirectories()[0]?.resolve('dir')])
|
2015-07-23 21:31:09 +03:00
|
|
|
waits(1)
|
2014-01-21 21:48:29 +04:00
|
|
|
|
2015-09-03 18:32:04 +03:00
|
|
|
describe "serialization", ->
|
|
|
|
simulateReload = ->
|
|
|
|
workspaceState = atom.workspace.serialize()
|
|
|
|
projectState = atom.project.serialize()
|
|
|
|
atom.workspace.destroy()
|
|
|
|
atom.project.destroy()
|
2015-10-12 11:39:35 +03:00
|
|
|
atom.project = new Project({notificationManager: atom.notifications, packageManager: atom.packages, confirm: atom.confirm.bind(atom)})
|
2015-10-02 21:12:16 +03:00
|
|
|
atom.project.deserialize(projectState, atom.deserializers)
|
2015-10-03 01:18:51 +03:00
|
|
|
atom.workspace = new Workspace({
|
|
|
|
config: atom.config, project: atom.project, packageManager: atom.packages,
|
2015-10-12 11:39:35 +03:00
|
|
|
grammarRegistry: atom.grammars, deserializerManager: atom.deserializers,
|
|
|
|
notificationManager: atom.notifications, clipboard: atom.clipboard,
|
2015-10-14 03:54:48 +03:00
|
|
|
applicationDelegate: atom.applicationDelegate,
|
2015-10-12 11:39:35 +03:00
|
|
|
viewRegistry: atom.views, assert: atom.assert.bind(atom),
|
2015-10-03 01:18:51 +03:00
|
|
|
})
|
|
|
|
atom.workspace.deserialize(workspaceState, atom.deserializers)
|
2015-09-03 18:32:04 +03:00
|
|
|
|
|
|
|
describe "when the workspace contains text editors", ->
|
|
|
|
it "constructs the view with the same panes", ->
|
|
|
|
pane1 = atom.workspace.getActivePane()
|
|
|
|
pane2 = pane1.splitRight(copyActiveItem: true)
|
|
|
|
pane3 = pane2.splitRight(copyActiveItem: true)
|
|
|
|
pane4 = null
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open('b').then (editor) ->
|
|
|
|
pane2.activateItem(editor.copy())
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open('../sample.js').then (editor) ->
|
|
|
|
pane3.activateItem(editor)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
pane3.activeItem.setCursorScreenPosition([2, 4])
|
|
|
|
pane4 = pane2.splitDown()
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open('../sample.txt').then (editor) ->
|
|
|
|
pane4.activateItem(editor)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
pane4.getActiveItem().setCursorScreenPosition([0, 2])
|
|
|
|
pane2.activate()
|
|
|
|
|
|
|
|
simulateReload()
|
|
|
|
|
|
|
|
expect(atom.workspace.getTextEditors().length).toBe 4
|
|
|
|
[editor1, editor2, editor3, editor4] = atom.workspace.getTextEditors()
|
|
|
|
|
|
|
|
expect(editor1.getPath()).toBe atom.project.getDirectories()[0]?.resolve('b')
|
|
|
|
expect(editor2.getPath()).toBe atom.project.getDirectories()[0]?.resolve('../sample.txt')
|
|
|
|
expect(editor2.getCursorScreenPosition()).toEqual [0, 2]
|
|
|
|
expect(editor3.getPath()).toBe atom.project.getDirectories()[0]?.resolve('b')
|
|
|
|
expect(editor4.getPath()).toBe atom.project.getDirectories()[0]?.resolve('../sample.js')
|
|
|
|
expect(editor4.getCursorScreenPosition()).toEqual [2, 4]
|
|
|
|
|
|
|
|
expect(atom.workspace.getActiveTextEditor().getPath()).toBe editor3.getPath()
|
|
|
|
expect(document.title).toBe "#{path.basename(editor3.getPath())} - #{atom.project.getPaths()[0]} - Atom"
|
|
|
|
|
|
|
|
describe "where there are no open panes or editors", ->
|
|
|
|
it "constructs the view with no open editors", ->
|
|
|
|
atom.workspace.getActivePane().destroy()
|
|
|
|
expect(atom.workspace.getTextEditors().length).toBe 0
|
|
|
|
simulateReload()
|
|
|
|
expect(atom.workspace.getTextEditors().length).toBe 0
|
|
|
|
|
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 [
|
|
|
|
{
|
2015-01-10 01:54:54 +03:00
|
|
|
uri: atom.project.getDirectories()[0]?.resolve('a')
|
2014-09-04 16:57:59 +04:00
|
|
|
item: editor1
|
|
|
|
pane: atom.workspace.getActivePane()
|
|
|
|
index: 0
|
|
|
|
}
|
|
|
|
{
|
2015-01-10 01:54:54 +03:00
|
|
|
uri: atom.project.getDirectories()[0]?.resolve('b')
|
2014-09-04 16:57:59 +04:00
|
|
|
item: editor2
|
|
|
|
pane: atom.workspace.getActivePane()
|
|
|
|
index: 1
|
|
|
|
}
|
|
|
|
{
|
2015-01-10 01:54:54 +03:00
|
|
|
uri: atom.project.getDirectories()[0]?.resolve('a')
|
2014-09-04 16:57:59 +04:00
|
|
|
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 ->
|
2015-01-13 05:06:31 +03:00
|
|
|
expect(editor.getURI()).toBe atom.project.getDirectories()[0]?.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 ->
|
2015-04-07 06:45:02 +03:00
|
|
|
pane2 = workspace.getPanes().filter((p) -> p isnt 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 ->
|
2015-04-07 06:45:02 +03:00
|
|
|
pane4 = workspace.getPanes().filter((p) -> p isnt 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
|
|
|
|
|
2015-09-24 11:32:09 +03:00
|
|
|
describe "when the 'split' option is 'up'", ->
|
|
|
|
it "opens the editor in the topmost pane of the current pane axis", ->
|
|
|
|
pane1 = workspace.getActivePane()
|
|
|
|
pane2 = pane1.splitDown()
|
|
|
|
expect(workspace.getActivePane()).toBe pane2
|
|
|
|
|
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', split: 'up').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.getActivePane()).toBe pane1
|
|
|
|
expect(pane1.items).toEqual [editor]
|
|
|
|
expect(pane2.items).toEqual []
|
|
|
|
|
|
|
|
# Focus bottom pane and reopen the file on the top
|
|
|
|
waitsForPromise ->
|
|
|
|
pane2.focus()
|
|
|
|
workspace.open('a', split: 'up').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.getActivePane()).toBe pane1
|
|
|
|
expect(pane1.items).toEqual [editor]
|
|
|
|
expect(pane2.items).toEqual []
|
|
|
|
|
|
|
|
describe "when a pane axis is the topmost sibling of the current pane", ->
|
|
|
|
it "opens the new item in the current pane", ->
|
|
|
|
editor = null
|
|
|
|
pane1 = workspace.getActivePane()
|
|
|
|
pane2 = pane1.splitUp()
|
|
|
|
pane3 = pane2.splitRight()
|
|
|
|
pane1.activate()
|
|
|
|
expect(workspace.getActivePane()).toBe pane1
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', split: 'up').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.getActivePane()).toBe pane1
|
|
|
|
expect(pane1.items).toEqual [editor]
|
|
|
|
|
|
|
|
describe "when the 'split' option is 'down'", ->
|
|
|
|
it "opens the editor in the bottommost pane of the current pane axis", ->
|
|
|
|
editor = null
|
|
|
|
pane1 = workspace.getActivePane()
|
|
|
|
pane2 = null
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', split: 'down').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
pane2 = workspace.getPanes().filter((p) -> p isnt pane1)[0]
|
|
|
|
expect(workspace.getActivePane()).toBe pane2
|
|
|
|
expect(pane1.items).toEqual []
|
|
|
|
expect(pane2.items).toEqual [editor]
|
|
|
|
|
|
|
|
# Focus bottom pane and reopen the file on the right
|
|
|
|
waitsForPromise ->
|
|
|
|
pane1.focus()
|
|
|
|
workspace.open('a', split: 'down').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.getActivePane()).toBe pane2
|
|
|
|
expect(pane1.items).toEqual []
|
|
|
|
expect(pane2.items).toEqual [editor]
|
|
|
|
|
|
|
|
describe "when a pane axis is the bottommost sibling of the current pane", ->
|
|
|
|
it "opens the new item in a new pane split to the bottom of the current pane", ->
|
|
|
|
editor = null
|
|
|
|
pane1 = workspace.getActivePane()
|
|
|
|
pane2 = pane1.splitDown()
|
|
|
|
pane1.activate()
|
|
|
|
expect(workspace.getActivePane()).toBe pane1
|
|
|
|
pane4 = null
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', split: 'down').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
pane4 = workspace.getPanes().filter((p) -> p isnt pane1)[0]
|
|
|
|
expect(workspace.getActivePane()).toBe pane4
|
|
|
|
expect(pane4.items).toEqual [editor]
|
|
|
|
expect(workspace.paneContainer.root.children[0]).toBe pane1
|
|
|
|
expect(workspace.paneContainer.root.children[1]).toBe pane2
|
|
|
|
|
2015-08-10 20:27:15 +03:00
|
|
|
describe "when an initialLine and initialColumn are specified", ->
|
|
|
|
it "moves the cursor to the indicated location", ->
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', initialLine: 1, initialColumn: 5)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [1, 5]
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', initialLine: 2, initialColumn: 4)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [2, 4]
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', initialLine: 0, initialColumn: 0)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [0, 0]
|
|
|
|
|
2015-08-10 20:32:38 +03:00
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', initialLine: NaN, initialColumn: 4)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [0, 4]
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', initialLine: 2, initialColumn: NaN)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [2, 0]
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('a', initialLine: Infinity, initialColumn: Infinity)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [2, 11]
|
|
|
|
|
2015-06-09 00:50:27 +03:00
|
|
|
describe "when the file is over 2MB", ->
|
2015-06-06 00:25:48 +03:00
|
|
|
it "opens the editor with largeFileMode: true", ->
|
|
|
|
spyOn(fs, 'getSizeSync').andReturn 2 * 1048577 # 2MB
|
|
|
|
|
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('sample.js').then (e) -> editor = e
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(editor.displayBuffer.largeFileMode).toBe true
|
|
|
|
|
2015-06-09 00:50:27 +03:00
|
|
|
describe "when the file is over 20MB", ->
|
|
|
|
it "prompts the user to make sure they want to open a file this big", ->
|
|
|
|
spyOn(fs, 'getSizeSync').andReturn 20 * 1048577 # 20MB
|
2015-10-14 03:54:48 +03:00
|
|
|
atom.applicationDelegate.confirm.andCallFake -> selectedButtonIndex
|
|
|
|
atom.applicationDelegate.confirm()
|
2015-06-09 00:50:27 +03:00
|
|
|
selectedButtonIndex = 1 # cancel
|
|
|
|
|
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('sample.js').then (e) -> editor = e
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(editor).toBeUndefined()
|
2015-10-14 03:54:48 +03:00
|
|
|
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
|
2015-06-09 00:50:27 +03:00
|
|
|
|
2015-10-14 03:54:48 +03:00
|
|
|
atom.applicationDelegate.confirm.reset()
|
2015-06-09 00:50:27 +03:00
|
|
|
selectedButtonIndex = 0 # open the file
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('sample.js').then (e) -> editor = e
|
|
|
|
|
|
|
|
runs ->
|
2015-10-14 03:54:48 +03:00
|
|
|
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
|
2015-06-09 00:50:27 +03:00
|
|
|
expect(editor.displayBuffer.largeFileMode).toBe true
|
|
|
|
|
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", ->
|
2015-04-07 06:45:02 +03:00
|
|
|
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 ->
|
2015-01-10 01:54:54 +03:00
|
|
|
pathToOpen = atom.project.getDirectories()[0]?.resolve('a.foo')
|
2014-02-13 04:56:00 +04:00
|
|
|
workspace.open(pathToOpen, hey: "there").then (item) ->
|
2015-04-07 06:45:02 +03:00
|
|
|
expect(item).toEqual {foo: pathToOpen, options: {hey: "there"}}
|
2014-02-13 04:56:00 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open("bar://baz").then (item) ->
|
2015-04-07 06:45:02 +03:00
|
|
|
expect(item).toEqual {bar: "bar://baz"}
|
2014-02-13 04:56:00 +04:00
|
|
|
|
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
|
|
|
|
2015-01-08 01:58:36 +03:00
|
|
|
describe "when there is an error opening the file", ->
|
|
|
|
notificationSpy = null
|
|
|
|
beforeEach ->
|
|
|
|
atom.notifications.onDidAddNotification notificationSpy = jasmine.createSpy()
|
|
|
|
|
2015-01-08 02:38:51 +03:00
|
|
|
describe "when a file does not exist", ->
|
2015-01-14 01:19:27 +03:00
|
|
|
it "creates an empty buffer for the specified path", ->
|
2015-01-08 02:38:51 +03:00
|
|
|
waitsForPromise ->
|
2015-01-14 01:19:02 +03:00
|
|
|
workspace.open('not-a-file.md')
|
2015-01-08 02:38:51 +03:00
|
|
|
|
|
|
|
runs ->
|
2015-01-14 01:19:27 +03:00
|
|
|
editor = workspace.getActiveTextEditor()
|
|
|
|
expect(notificationSpy).not.toHaveBeenCalled()
|
|
|
|
expect(editor.getPath()).toContain 'not-a-file.md'
|
2015-01-08 02:38:51 +03:00
|
|
|
|
2015-01-08 03:01:23 +03:00
|
|
|
describe "when the user does not have access to the file", ->
|
|
|
|
beforeEach ->
|
2015-01-08 04:18:39 +03:00
|
|
|
spyOn(fs, 'openSync').andCallFake (path) ->
|
2015-01-08 03:01:23 +03:00
|
|
|
error = new Error("EACCES, permission denied '#{path}'")
|
|
|
|
error.path = path
|
|
|
|
error.code = 'EACCES'
|
|
|
|
throw error
|
|
|
|
|
|
|
|
it "creates a notification", ->
|
|
|
|
waitsForPromise ->
|
2015-01-14 01:19:02 +03:00
|
|
|
workspace.open('file1')
|
2015-01-08 03:01:23 +03:00
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(notificationSpy).toHaveBeenCalled()
|
|
|
|
notification = notificationSpy.mostRecentCall.args[0]
|
|
|
|
expect(notification.getType()).toBe 'warning'
|
|
|
|
expect(notification.getMessage()).toContain 'Permission denied'
|
|
|
|
expect(notification.getMessage()).toContain 'file1'
|
|
|
|
|
2015-01-16 21:45:48 +03:00
|
|
|
describe "when the the operation is not permitted", ->
|
|
|
|
beforeEach ->
|
|
|
|
spyOn(fs, 'openSync').andCallFake (path) ->
|
|
|
|
error = new Error("EPERM, operation not permitted '#{path}'")
|
|
|
|
error.path = path
|
|
|
|
error.code = 'EPERM'
|
|
|
|
throw error
|
|
|
|
|
|
|
|
it "creates a notification", ->
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('file1')
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(notificationSpy).toHaveBeenCalled()
|
|
|
|
notification = notificationSpy.mostRecentCall.args[0]
|
|
|
|
expect(notification.getType()).toBe 'warning'
|
|
|
|
expect(notification.getMessage()).toContain 'Unable to open'
|
|
|
|
expect(notification.getMessage()).toContain 'file1'
|
|
|
|
|
2015-01-16 22:07:32 +03:00
|
|
|
describe "when the the file is already open in windows", ->
|
|
|
|
beforeEach ->
|
|
|
|
spyOn(fs, 'openSync').andCallFake (path) ->
|
|
|
|
error = new Error("EBUSY, resource busy or locked '#{path}'")
|
|
|
|
error.path = path
|
|
|
|
error.code = 'EBUSY'
|
|
|
|
throw error
|
|
|
|
|
|
|
|
it "creates a notification", ->
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.open('file1')
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(notificationSpy).toHaveBeenCalled()
|
|
|
|
notification = notificationSpy.mostRecentCall.args[0]
|
|
|
|
expect(notification.getType()).toBe 'warning'
|
|
|
|
expect(notification.getMessage()).toContain 'Unable to open'
|
|
|
|
expect(notification.getMessage()).toContain 'file1'
|
|
|
|
|
2015-01-08 03:04:07 +03:00
|
|
|
describe "when there is an unhandled error", ->
|
|
|
|
beforeEach ->
|
2015-01-08 04:18:39 +03:00
|
|
|
spyOn(fs, 'openSync').andCallFake (path) ->
|
2015-01-08 03:04:07 +03:00
|
|
|
throw new Error("I dont even know what is happening right now!!")
|
|
|
|
|
|
|
|
it "creates a notification", ->
|
|
|
|
open = -> workspace.open('file1', workspace.getActivePane())
|
|
|
|
expect(open).toThrow()
|
2015-01-08 03:01:23 +03: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
|
2015-01-13 05:06:31 +03: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 ->
|
2015-01-13 05:06:31 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).not.toBeUndefined()
|
2014-04-22 22:24:27 +04:00
|
|
|
|
|
|
|
# destroy all items
|
2015-01-13 05:06:31 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.resolve('file1')
|
2014-04-22 22:24:27 +04:00
|
|
|
pane.destroyActiveItem()
|
2015-01-13 05:06:31 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.resolve('b')
|
2014-04-22 22:24:27 +04:00
|
|
|
pane.destroyActiveItem()
|
2015-01-13 05:06:31 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.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 ->
|
2015-01-13 05:06:31 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.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 ->
|
2015-01-13 05:06:31 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.resolve('b')
|
2014-04-23 01:15:07 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
workspace.reopenItem()
|
|
|
|
|
|
|
|
runs ->
|
2015-01-13 05:06:31 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.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
|
2015-04-28 12:49:22 +03:00
|
|
|
|
2015-04-28 01:25:01 +03:00
|
|
|
describe "::resetFontSize()", ->
|
|
|
|
it "resets the font size to the window's starting font size", ->
|
2015-04-29 05:58:35 +03:00
|
|
|
originalFontSize = atom.config.get('editor.fontSize')
|
2015-04-28 01:25:01 +03:00
|
|
|
|
|
|
|
workspace.increaseFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe originalFontSize + 1
|
|
|
|
workspace.resetFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe originalFontSize
|
|
|
|
workspace.decreaseFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe originalFontSize - 1
|
|
|
|
workspace.resetFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe originalFontSize
|
2014-02-22 00:08:26 +04:00
|
|
|
|
2015-04-28 12:49:22 +03:00
|
|
|
it "does nothing if the font size has not been changed", ->
|
2015-04-29 05:58:35 +03:00
|
|
|
originalFontSize = atom.config.get('editor.fontSize')
|
2015-04-28 12:49:22 +03:00
|
|
|
|
|
|
|
workspace.resetFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe originalFontSize
|
|
|
|
|
2015-04-29 05:58:35 +03:00
|
|
|
it "resets the font size when the editor's font size changes", ->
|
|
|
|
originalFontSize = atom.config.get('editor.fontSize')
|
|
|
|
|
|
|
|
atom.config.set('editor.fontSize', originalFontSize + 1)
|
|
|
|
workspace.resetFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe originalFontSize
|
|
|
|
atom.config.set('editor.fontSize', originalFontSize - 1)
|
|
|
|
workspace.resetFontSize()
|
|
|
|
expect(atom.config.get('editor.fontSize')).toBe originalFontSize
|
|
|
|
|
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')
|
|
|
|
|
2015-10-03 01:18:51 +03:00
|
|
|
workspace2 = new Workspace({
|
|
|
|
config: atom.config, project: atom.project, packageManager: atom.packages,
|
2015-10-10 03:18:26 +03:00
|
|
|
notificationManager: atom.notifications, deserializerManager: atom.deserializers,
|
|
|
|
clipboard: atom.clipboard, viewRegistry: atom.views, grammarRegistry: atom.grammars,
|
2015-10-14 03:54:48 +03:00
|
|
|
applicationDelegate: atom.applicationDelegate, assert: atom.assert.bind(atom)
|
2015-10-03 01:18:51 +03:00
|
|
|
})
|
|
|
|
workspace2.deserialize(state, atom.deserializers)
|
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
|
2015-10-03 01:18:51 +03:00
|
|
|
workspace2 = new Workspace({
|
|
|
|
config: atom.config, project: atom.project, packageManager: atom.packages,
|
2015-10-10 03:18:26 +03:00
|
|
|
notificationManager: atom.notifications, deserializerManager: atom.deserializers,
|
|
|
|
clipboard: atom.clipboard, viewRegistry: atom.views, grammarRegistry: atom.grammars,
|
2015-10-14 03:54:48 +03:00
|
|
|
applicationDelegate: atom.applicationDelegate, assert: atom.assert.bind(atom)
|
2015-10-03 01:18:51 +03:00
|
|
|
})
|
|
|
|
workspace2.deserialize(atom.workspace.serialize(), atom.deserializers)
|
2014-09-25 02:26:54 +04:00
|
|
|
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()
|
|
|
|
|
2015-10-03 01:18:51 +03:00
|
|
|
it "calls setDocumentEdited when the active item changes", ->
|
2014-09-25 03:00:05 +04:00
|
|
|
expect(atom.workspace.getActivePaneItem()).toBe item2
|
|
|
|
item1.insertText('a')
|
|
|
|
expect(item1.isModified()).toBe true
|
|
|
|
atom.workspace.getActivePane().activateNextItem()
|
|
|
|
|
2015-10-03 01:18:51 +03:00
|
|
|
expect(setDocumentEdited).toHaveBeenCalledWith(true)
|
2014-09-25 03:00:05 +04:00
|
|
|
|
|
|
|
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
|
2015-10-03 01:18:51 +03:00
|
|
|
expect(setDocumentEdited).toHaveBeenCalledWith(true)
|
2014-09-25 03:00:05 +04:00
|
|
|
|
|
|
|
item2.undo()
|
|
|
|
advanceClock(item2.getBuffer().getStoppedChangingDelay())
|
|
|
|
|
|
|
|
expect(item2.isModified()).toBe false
|
2015-10-03 01:18:51 +03:00
|
|
|
expect(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
|
|
|
|
2014-12-29 20:43:17 +03:00
|
|
|
describe "::scan(regex, options, callback)", ->
|
2014-12-29 20:35:07 +03:00
|
|
|
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)
|
2015-01-10 01:54:54 +03:00
|
|
|
expect(results[0].filePath).toBe atom.project.getDirectories()[0]?.resolve('a')
|
2014-12-29 20:35:07 +03:00
|
|
|
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]
|
2015-01-10 01:54:54 +03:00
|
|
|
expect(filePath).toBe atom.project.getDirectories()[0]?.resolve('a')
|
2014-12-29 20:35:07 +03:00
|
|
|
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 ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open('a').then (o) ->
|
2014-12-29 20:35:07 +03:00
|
|
|
editor = o
|
|
|
|
editor.setText("Elephant")
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /a|Elephant/, (result) -> results.push result
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 3
|
2015-04-07 06:45:02 +03:00
|
|
|
resultForA = _.find results, ({filePath}) -> path.basename(filePath) is 'a'
|
2014-12-29 20:35:07 +03:00
|
|
|
expect(resultForA.matches).toHaveLength 1
|
|
|
|
expect(resultForA.matches[0].matchText).toBe 'Elephant'
|
|
|
|
|
|
|
|
it "ignores buffers outside the project", ->
|
|
|
|
editor = null
|
|
|
|
results = []
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open(temp.openSync().path).then (o) ->
|
2014-12-29 20:35:07 +03:00
|
|
|
editor = o
|
|
|
|
editor.setText("Elephant")
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /Elephant/, (result) -> results.push result
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 0
|
2014-12-29 20:43:17 +03:00
|
|
|
|
2015-02-25 01:22:39 +03:00
|
|
|
describe "when the project has multiple root directories", ->
|
|
|
|
[dir1, dir2, file1, file2] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
[dir1] = atom.project.getPaths()
|
|
|
|
file1 = path.join(dir1, "a-dir", "oh-git")
|
|
|
|
|
|
|
|
dir2 = temp.mkdirSync("a-second-dir")
|
|
|
|
aDir2 = path.join(dir2, "a-dir")
|
|
|
|
file2 = path.join(aDir2, "a-file")
|
|
|
|
fs.mkdirSync(aDir2)
|
|
|
|
fs.writeFileSync(file2, "ccc aaaa")
|
|
|
|
|
|
|
|
atom.project.addPath(dir2)
|
|
|
|
|
|
|
|
it "searches matching files in all of the project's root directories", ->
|
|
|
|
resultPaths = []
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /aaaa/, ({filePath}) ->
|
|
|
|
resultPaths.push(filePath)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(resultPaths.sort()).toEqual([file1, file2].sort())
|
|
|
|
|
|
|
|
describe "when an inclusion path starts with the basename of a root directory", ->
|
|
|
|
it "interprets the inclusion path as starting from that directory", ->
|
|
|
|
waitsForPromise ->
|
|
|
|
resultPaths = []
|
|
|
|
atom.workspace
|
|
|
|
.scan /aaaa/, paths: ["dir"], ({filePath}) ->
|
|
|
|
resultPaths.push(filePath) unless filePath in resultPaths
|
|
|
|
.then ->
|
|
|
|
expect(resultPaths).toEqual([file1])
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
resultPaths = []
|
|
|
|
atom.workspace
|
|
|
|
.scan /aaaa/, paths: [path.join("dir", "a-dir")], ({filePath}) ->
|
|
|
|
resultPaths.push(filePath) unless filePath in resultPaths
|
|
|
|
.then ->
|
|
|
|
expect(resultPaths).toEqual([file1])
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
resultPaths = []
|
|
|
|
atom.workspace
|
|
|
|
.scan /aaaa/, paths: [path.basename(dir2)], ({filePath}) ->
|
|
|
|
resultPaths.push(filePath) unless filePath in resultPaths
|
|
|
|
.then ->
|
|
|
|
expect(resultPaths).toEqual([file2])
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
resultPaths = []
|
|
|
|
atom.workspace
|
|
|
|
.scan /aaaa/, paths: [path.join(path.basename(dir2), "a-dir")], ({filePath}) ->
|
|
|
|
resultPaths.push(filePath) unless filePath in resultPaths
|
|
|
|
.then ->
|
|
|
|
expect(resultPaths).toEqual([file2])
|
|
|
|
|
2015-06-11 01:30:25 +03:00
|
|
|
describe "when a custom directory searcher is registered", ->
|
|
|
|
fakeSearch = null
|
|
|
|
# Function that is invoked once all of the fields on fakeSearch are set.
|
|
|
|
onFakeSearchCreated = null
|
|
|
|
|
|
|
|
class FakeSearch
|
|
|
|
constructor: (@options) ->
|
|
|
|
# Note that hoisting resolve and reject in this way is generally frowned upon.
|
|
|
|
@promise = new Promise (resolve, reject) =>
|
|
|
|
@hoistedResolve = resolve
|
|
|
|
@hoistedReject = reject
|
|
|
|
onFakeSearchCreated?(this)
|
|
|
|
then: (args...) ->
|
|
|
|
@promise.then.apply(@promise, args)
|
|
|
|
cancel: ->
|
|
|
|
@cancelled = true
|
2015-06-10 15:25:24 +03:00
|
|
|
# According to the spec for a DirectorySearcher, invoking `cancel()` should
|
|
|
|
# resolve the thenable rather than reject it.
|
|
|
|
@hoistedResolve()
|
2015-06-11 01:30:25 +03:00
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
fakeSearch = null
|
|
|
|
onFakeSearchCreated = null
|
|
|
|
atom.packages.serviceHub.provide('atom.directory-searcher', '0.1.0', {
|
|
|
|
canSearchDirectory: (directory) -> directory.getPath() is dir1
|
|
|
|
search: (directory, regex, options) -> fakeSearch = new FakeSearch(options)
|
|
|
|
})
|
|
|
|
|
2015-10-03 02:38:25 +03:00
|
|
|
waitsFor ->
|
|
|
|
atom.workspace.directorySearchers.length > 0
|
|
|
|
|
2015-06-11 01:30:25 +03:00
|
|
|
it "can override the DefaultDirectorySearcher on a per-directory basis", ->
|
|
|
|
foreignFilePath = 'ssh://foreign-directory:8080/hello.txt'
|
|
|
|
numPathsSearchedInDir2 = 1
|
|
|
|
numPathsToPretendToSearchInCustomDirectorySearcher = 10
|
|
|
|
searchResult =
|
|
|
|
filePath: foreignFilePath,
|
|
|
|
matches: [
|
|
|
|
{
|
|
|
|
lineText: 'Hello world',
|
|
|
|
lineTextOffset: 0,
|
|
|
|
matchText: 'Hello',
|
|
|
|
range: [[0, 0], [0, 5]],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
onFakeSearchCreated = (fakeSearch) ->
|
|
|
|
fakeSearch.options.didMatch(searchResult)
|
|
|
|
fakeSearch.options.didSearchPaths(numPathsToPretendToSearchInCustomDirectorySearcher)
|
|
|
|
fakeSearch.hoistedResolve()
|
|
|
|
|
|
|
|
resultPaths = []
|
|
|
|
onPathsSearched = jasmine.createSpy('onPathsSearched')
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.scan /aaaa/, {onPathsSearched}, ({filePath}) ->
|
|
|
|
resultPaths.push(filePath)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(resultPaths.sort()).toEqual([foreignFilePath, file2].sort())
|
|
|
|
# onPathsSearched should be called once by each DirectorySearcher. The order is not
|
|
|
|
# guaranteed, so we can only verify the total number of paths searched is correct
|
|
|
|
# after the second call.
|
|
|
|
expect(onPathsSearched.callCount).toBe(2)
|
|
|
|
expect(onPathsSearched.mostRecentCall.args[0]).toBe(
|
|
|
|
numPathsToPretendToSearchInCustomDirectorySearcher + numPathsSearchedInDir2)
|
|
|
|
|
|
|
|
it "can be cancelled when the object returned by scan() has its cancel() method invoked", ->
|
|
|
|
thenable = atom.workspace.scan /aaaa/, ->
|
|
|
|
resultOfPromiseSearch = null
|
2015-09-04 20:22:11 +03:00
|
|
|
|
|
|
|
waitsFor 'fakeSearch to be defined', -> fakeSearch?
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(fakeSearch.cancelled).toBe(undefined)
|
|
|
|
thenable.cancel()
|
|
|
|
expect(fakeSearch.cancelled).toBe(true)
|
|
|
|
|
|
|
|
|
2015-06-11 01:30:25 +03:00
|
|
|
waitsForPromise ->
|
|
|
|
thenable.then (promiseResult) -> resultOfPromiseSearch = promiseResult
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(resultOfPromiseSearch).toBe('cancelled')
|
|
|
|
|
|
|
|
it "will have the side-effect of failing the overall search if it fails", ->
|
2015-09-04 01:55:30 +03:00
|
|
|
# This provider's search should be cancelled when the first provider fails
|
|
|
|
fakeSearch2 = null
|
|
|
|
atom.packages.serviceHub.provide('atom.directory-searcher', '0.1.0', {
|
|
|
|
canSearchDirectory: (directory) -> directory.getPath() is dir2
|
|
|
|
search: (directory, regex, options) -> fakeSearch2 = new FakeSearch(options)
|
|
|
|
})
|
2015-06-11 01:30:25 +03:00
|
|
|
|
|
|
|
didReject = false
|
2015-09-04 01:55:30 +03:00
|
|
|
promise = cancelableSearch = atom.workspace.scan /aaaa/, ->
|
|
|
|
waitsFor 'fakeSearch to be defined', -> fakeSearch?
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
fakeSearch.hoistedReject()
|
|
|
|
|
2015-06-11 01:30:25 +03:00
|
|
|
waitsForPromise ->
|
|
|
|
cancelableSearch.catch -> didReject = true
|
|
|
|
|
2015-09-04 01:55:30 +03:00
|
|
|
waitsFor (done) -> promise.then(null, done)
|
|
|
|
|
2015-06-11 01:30:25 +03:00
|
|
|
runs ->
|
|
|
|
expect(didReject).toBe(true)
|
2015-09-04 01:55:30 +03:00
|
|
|
expect(fakeSearch2.cancelled).toBe true # Cancels other ongoing searches
|
2015-06-11 01:30:25 +03:00
|
|
|
|
2014-12-29 20:43:17 +03:00
|
|
|
describe "::replace(regex, replacementText, paths, iterator)", ->
|
|
|
|
[filePath, commentFilePath, sampleContent, sampleCommentContent] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
2015-01-10 01:54:54 +03:00
|
|
|
atom.project.setPaths([atom.project.getDirectories()[0]?.resolve('../')])
|
2014-12-29 20:43:17 +03:00
|
|
|
|
2015-01-10 01:54:54 +03:00
|
|
|
filePath = atom.project.getDirectories()[0]?.resolve('sample.js')
|
|
|
|
commentFilePath = atom.project.getDirectories()[0]?.resolve('sample-with-comments.js')
|
2014-12-29 20:43:17 +03:00
|
|
|
sampleContent = fs.readFileSync(filePath).toString()
|
|
|
|
sampleCommentContent = fs.readFileSync(commentFilePath).toString()
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
fs.writeFileSync(filePath, sampleContent)
|
|
|
|
fs.writeFileSync(commentFilePath, sampleCommentContent)
|
|
|
|
|
|
|
|
describe "when a file doesn't exist", ->
|
|
|
|
it "calls back with an error", ->
|
|
|
|
errors = []
|
|
|
|
missingPath = path.resolve('/not-a-file.js')
|
|
|
|
expect(fs.existsSync(missingPath)).toBeFalsy()
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.replace /items/gi, 'items', [missingPath], (result, error) ->
|
|
|
|
errors.push(error)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(errors).toHaveLength 1
|
|
|
|
expect(errors[0].path).toBe missingPath
|
|
|
|
|
|
|
|
describe "when called with unopened files", ->
|
|
|
|
it "replaces properly", ->
|
|
|
|
results = []
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.replace /items/gi, 'items', [filePath], (result) ->
|
|
|
|
results.push(result)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 1
|
|
|
|
expect(results[0].filePath).toBe filePath
|
|
|
|
expect(results[0].replacements).toBe 6
|
|
|
|
|
|
|
|
describe "when a buffer is already open", ->
|
|
|
|
it "replaces properly and saves when not modified", ->
|
|
|
|
editor = null
|
|
|
|
results = []
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open('sample.js').then (o) -> editor = o
|
2014-12-29 20:43:17 +03:00
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(editor.isModified()).toBeFalsy()
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.replace /items/gi, 'items', [filePath], (result) ->
|
|
|
|
results.push(result)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 1
|
|
|
|
expect(results[0].filePath).toBe filePath
|
|
|
|
expect(results[0].replacements).toBe 6
|
|
|
|
|
|
|
|
expect(editor.isModified()).toBeFalsy()
|
|
|
|
|
|
|
|
it "does not replace when the path is not specified", ->
|
|
|
|
editor = null
|
|
|
|
results = []
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open('sample-with-comments.js').then (o) -> editor = o
|
2014-12-29 20:43:17 +03:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.replace /items/gi, 'items', [commentFilePath], (result) ->
|
|
|
|
results.push(result)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 1
|
|
|
|
expect(results[0].filePath).toBe commentFilePath
|
|
|
|
|
|
|
|
it "does NOT save when modified", ->
|
|
|
|
editor = null
|
|
|
|
results = []
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2015-10-03 06:13:42 +03:00
|
|
|
atom.workspace.open('sample.js').then (o) -> editor = o
|
2014-12-29 20:43:17 +03:00
|
|
|
|
|
|
|
runs ->
|
2015-05-22 23:29:12 +03:00
|
|
|
editor.buffer.setTextInRange([[0, 0], [0, 0]], 'omg')
|
2014-12-29 20:43:17 +03:00
|
|
|
expect(editor.isModified()).toBeTruthy()
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.replace /items/gi, 'okthen', [filePath], (result) ->
|
|
|
|
results.push(result)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 1
|
|
|
|
expect(results[0].filePath).toBe filePath
|
|
|
|
expect(results[0].replacements).toBe 6
|
|
|
|
|
|
|
|
expect(editor.isModified()).toBeTruthy()
|
2015-01-08 04:14:26 +03:00
|
|
|
|
|
|
|
describe "::saveActivePaneItem()", ->
|
2015-02-06 02:23:46 +03:00
|
|
|
editor = null
|
|
|
|
beforeEach ->
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open('sample.js').then (o) -> editor = o
|
|
|
|
|
2015-01-08 04:14:26 +03:00
|
|
|
describe "when there is an error", ->
|
|
|
|
it "emits a warning notification when the file cannot be saved", ->
|
2015-02-06 02:23:46 +03:00
|
|
|
spyOn(editor, 'save').andCallFake ->
|
2015-01-08 04:14:26 +03:00
|
|
|
throw new Error("'/some/file' is a directory")
|
|
|
|
|
|
|
|
atom.notifications.onDidAddNotification addedSpy = jasmine.createSpy()
|
|
|
|
atom.workspace.saveActivePaneItem()
|
|
|
|
expect(addedSpy).toHaveBeenCalled()
|
|
|
|
expect(addedSpy.mostRecentCall.args[0].getType()).toBe 'warning'
|
|
|
|
|
|
|
|
it "emits a warning notification when the directory cannot be written to", ->
|
2015-02-06 02:23:46 +03:00
|
|
|
spyOn(editor, 'save').andCallFake ->
|
2015-01-08 04:14:26 +03:00
|
|
|
throw new Error("ENOTDIR, not a directory '/Some/dir/and-a-file.js'")
|
|
|
|
|
|
|
|
atom.notifications.onDidAddNotification addedSpy = jasmine.createSpy()
|
|
|
|
atom.workspace.saveActivePaneItem()
|
|
|
|
expect(addedSpy).toHaveBeenCalled()
|
|
|
|
expect(addedSpy.mostRecentCall.args[0].getType()).toBe 'warning'
|
|
|
|
|
|
|
|
it "emits a warning notification when the user does not have permission", ->
|
2015-02-06 02:23:46 +03:00
|
|
|
spyOn(editor, 'save').andCallFake ->
|
2015-01-08 04:14:26 +03:00
|
|
|
error = new Error("EACCES, permission denied '/Some/dir/and-a-file.js'")
|
|
|
|
error.code = 'EACCES'
|
|
|
|
error.path = '/Some/dir/and-a-file.js'
|
|
|
|
throw error
|
|
|
|
|
|
|
|
atom.notifications.onDidAddNotification addedSpy = jasmine.createSpy()
|
|
|
|
atom.workspace.saveActivePaneItem()
|
|
|
|
expect(addedSpy).toHaveBeenCalled()
|
|
|
|
expect(addedSpy.mostRecentCall.args[0].getType()).toBe 'warning'
|
|
|
|
|
2015-01-16 21:45:48 +03:00
|
|
|
it "emits a warning notification when the operation is not permitted", ->
|
2015-02-06 02:23:46 +03:00
|
|
|
spyOn(editor, 'save').andCallFake ->
|
2015-01-16 21:45:48 +03:00
|
|
|
error = new Error("EPERM, operation not permitted '/Some/dir/and-a-file.js'")
|
|
|
|
error.code = 'EPERM'
|
|
|
|
error.path = '/Some/dir/and-a-file.js'
|
|
|
|
throw error
|
|
|
|
|
2015-01-16 22:07:32 +03:00
|
|
|
it "emits a warning notification when the file is already open by another app", ->
|
2015-02-06 02:23:46 +03:00
|
|
|
spyOn(editor, 'save').andCallFake ->
|
2015-01-16 22:07:32 +03:00
|
|
|
error = new Error("EBUSY, resource busy or locked '/Some/dir/and-a-file.js'")
|
|
|
|
error.code = 'EBUSY'
|
|
|
|
error.path = '/Some/dir/and-a-file.js'
|
|
|
|
throw error
|
|
|
|
|
2015-01-16 21:45:48 +03:00
|
|
|
atom.notifications.onDidAddNotification addedSpy = jasmine.createSpy()
|
|
|
|
atom.workspace.saveActivePaneItem()
|
|
|
|
expect(addedSpy).toHaveBeenCalled()
|
2015-01-16 22:07:32 +03:00
|
|
|
|
|
|
|
notificaiton = addedSpy.mostRecentCall.args[0]
|
|
|
|
expect(notificaiton.getType()).toBe 'warning'
|
|
|
|
expect(notificaiton.getMessage()).toContain 'Unable to save'
|
2015-01-16 21:45:48 +03:00
|
|
|
|
2015-01-20 12:52:12 +03:00
|
|
|
it "emits a warning notification when the file system is read-only", ->
|
2015-02-06 02:23:46 +03:00
|
|
|
spyOn(editor, 'save').andCallFake ->
|
2015-01-20 12:52:12 +03:00
|
|
|
error = new Error("EROFS, read-only file system '/Some/dir/and-a-file.js'")
|
|
|
|
error.code = 'EROFS'
|
|
|
|
error.path = '/Some/dir/and-a-file.js'
|
|
|
|
throw error
|
|
|
|
|
|
|
|
atom.notifications.onDidAddNotification addedSpy = jasmine.createSpy()
|
|
|
|
atom.workspace.saveActivePaneItem()
|
|
|
|
expect(addedSpy).toHaveBeenCalled()
|
|
|
|
|
|
|
|
notification = addedSpy.mostRecentCall.args[0]
|
|
|
|
expect(notification.getType()).toBe 'warning'
|
|
|
|
expect(notification.getMessage()).toContain 'Unable to save'
|
|
|
|
|
2015-01-08 04:14:26 +03:00
|
|
|
it "emits a warning notification when the file cannot be saved", ->
|
2015-02-06 02:23:46 +03:00
|
|
|
spyOn(editor, 'save').andCallFake ->
|
2015-01-08 04:14:26 +03:00
|
|
|
throw new Error("no one knows")
|
|
|
|
|
|
|
|
save = -> atom.workspace.saveActivePaneItem()
|
|
|
|
expect(save).toThrow()
|
2015-09-03 19:17:24 +03:00
|
|
|
|
|
|
|
describe "::destroyActivePaneItemOrEmptyPane", ->
|
|
|
|
beforeEach ->
|
|
|
|
waitsForPromise -> atom.workspace.open()
|
|
|
|
|
|
|
|
it "closes the active pane item until all that remains is a single empty pane", ->
|
|
|
|
atom.config.set('core.destroyEmptyPanes', false)
|
|
|
|
|
|
|
|
pane1 = atom.workspace.getActivePane()
|
|
|
|
pane2 = pane1.splitRight(copyActiveItem: true)
|
|
|
|
|
|
|
|
expect(atom.workspace.getPanes().length).toBe 2
|
|
|
|
expect(pane2.getItems().length).toBe 1
|
|
|
|
atom.workspace.destroyActivePaneItemOrEmptyPane()
|
|
|
|
|
|
|
|
expect(atom.workspace.getPanes().length).toBe 2
|
|
|
|
expect(pane2.getItems().length).toBe 0
|
|
|
|
|
|
|
|
atom.workspace.destroyActivePaneItemOrEmptyPane()
|
|
|
|
|
|
|
|
expect(atom.workspace.getPanes().length).toBe 1
|
|
|
|
expect(pane1.getItems().length).toBe 1
|
|
|
|
|
|
|
|
atom.workspace.destroyActivePaneItemOrEmptyPane()
|
|
|
|
expect(atom.workspace.getPanes().length).toBe 1
|
|
|
|
expect(pane1.getItems().length).toBe 0
|
|
|
|
|
|
|
|
atom.workspace.destroyActivePaneItemOrEmptyPane()
|
|
|
|
expect(atom.workspace.getPanes().length).toBe 1
|