2017-03-03 02:40:57 +03:00
|
|
|
'use strict'
|
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
/* global advanceClock, HTMLElement, waits */
|
|
|
|
|
|
|
|
const path = require('path')
|
|
|
|
const temp = require('temp').track()
|
|
|
|
const TextEditor = require('../src/text-editor')
|
|
|
|
const Workspace = require('../src/workspace')
|
|
|
|
const Project = require('../src/project')
|
|
|
|
const platform = require('./spec-helper-platform')
|
|
|
|
const _ = require('underscore-plus')
|
|
|
|
const fstream = require('fstream')
|
|
|
|
const fs = require('fs-plus')
|
|
|
|
const AtomEnvironment = require('../src/atom-environment')
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('Workspace', () => {
|
|
|
|
let workspace
|
|
|
|
let setDocumentEdited
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
beforeEach(() => {
|
|
|
|
workspace = atom.workspace
|
2017-03-03 02:12:12 +03:00
|
|
|
workspace.resetFontSize()
|
|
|
|
spyOn(atom.applicationDelegate, 'confirm')
|
|
|
|
setDocumentEdited = spyOn(atom.applicationDelegate, 'setWindowDocumentEdited')
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.project.setPaths([atom.project.getDirectories()[0].resolve('dir')])
|
|
|
|
waits(1)
|
2017-03-16 21:48:38 +03:00
|
|
|
|
2017-03-23 20:39:02 +03:00
|
|
|
waitsForPromise(() => atom.workspace.itemLocationStore.clear())
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => temp.cleanupSync())
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('serialization', () => {
|
|
|
|
const simulateReload = () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const workspaceState = atom.workspace.serialize()
|
|
|
|
const projectState = atom.project.serialize({isUnloading: true})
|
|
|
|
atom.workspace.destroy()
|
|
|
|
atom.project.destroy()
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.project = new Project({
|
|
|
|
notificationManager: atom.notifications,
|
|
|
|
packageManager: atom.packages,
|
|
|
|
confirm: atom.confirm.bind(atom),
|
|
|
|
applicationDelegate: atom.applicationDelegate
|
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.project.deserialize(projectState)
|
2017-03-03 01:31:20 +03:00
|
|
|
atom.workspace = new Workspace({
|
2017-03-03 02:12:12 +03:00
|
|
|
config: atom.config,
|
|
|
|
project: atom.project,
|
|
|
|
packageManager: atom.packages,
|
|
|
|
grammarRegistry: atom.grammars,
|
|
|
|
deserializerManager: atom.deserializers,
|
2017-03-03 01:31:20 +03:00
|
|
|
notificationManager: atom.notifications,
|
|
|
|
applicationDelegate: atom.applicationDelegate,
|
2017-03-03 02:12:12 +03:00
|
|
|
viewRegistry: atom.views,
|
|
|
|
assert: atom.assert.bind(atom),
|
2017-03-03 01:31:20 +03:00
|
|
|
textEditorRegistry: atom.textEditors
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-11 21:20:16 +03:00
|
|
|
atom.workspace.initialize()
|
2017-03-03 02:12:12 +03:00
|
|
|
return atom.workspace.deserialize(workspaceState, atom.deserializers)
|
|
|
|
}
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the workspace contains text editors', () => {
|
|
|
|
it('constructs the view with the same panes', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const pane1 = atom.workspace.getActivePane()
|
|
|
|
const pane2 = pane1.splitRight({copyActiveItem: true})
|
|
|
|
const pane3 = pane2.splitRight({copyActiveItem: true})
|
|
|
|
let pane4 = null
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.workspace.open(null).then(editor => editor.setText('An untitled editor.')))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.open('b').then(editor => pane2.activateItem(editor.copy()))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.open('../sample.js').then(editor => pane3.activateItem(editor))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane3.activeItem.setCursorScreenPosition([2, 4])
|
2017-03-03 02:40:57 +03:00
|
|
|
pane4 = pane2.splitDown()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.open('../sample.txt').then(editor => pane4.activateItem(editor))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane4.getActiveItem().setCursorScreenPosition([0, 2])
|
|
|
|
pane2.activate()
|
|
|
|
|
|
|
|
simulateReload()
|
|
|
|
|
|
|
|
expect(atom.workspace.getTextEditors().length).toBe(5)
|
2017-03-03 02:40:57 +03:00
|
|
|
const [editor1, editor2, untitledEditor, editor3, editor4] = atom.workspace.getTextEditors()
|
|
|
|
const firstDirectory = atom.project.getDirectories()[0]
|
|
|
|
expect(firstDirectory).toBeDefined()
|
|
|
|
expect(editor1.getPath()).toBe(firstDirectory.resolve('b'))
|
|
|
|
expect(editor2.getPath()).toBe(firstDirectory.resolve('../sample.txt'))
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(editor2.getCursorScreenPosition()).toEqual([0, 2])
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(editor3.getPath()).toBe(firstDirectory.resolve('b'))
|
|
|
|
expect(editor4.getPath()).toBe(firstDirectory.resolve('../sample.js'))
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(editor4.getCursorScreenPosition()).toEqual([2, 4])
|
|
|
|
expect(untitledEditor.getPath()).toBeUndefined()
|
|
|
|
expect(untitledEditor.getText()).toBe('An untitled editor.')
|
|
|
|
|
|
|
|
expect(atom.workspace.getActiveTextEditor().getPath()).toBe(editor3.getPath())
|
|
|
|
const pathEscaped = fs.tildify(escapeStringRegex(atom.project.getPaths()[0]))
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(document.title).toMatch(new RegExp(`^${path.basename(editor3.getLongTitle())} \\u2014 ${pathEscaped}`))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('where there are no open panes or editors', () => {
|
|
|
|
it('constructs the view with no open editors', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.workspace.getActivePane().destroy()
|
|
|
|
expect(atom.workspace.getTextEditors().length).toBe(0)
|
|
|
|
simulateReload()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(atom.workspace.getTextEditors().length).toBe(0)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-16 21:48:38 +03:00
|
|
|
|
|
|
|
describe('where a dock contains an editor', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
atom.workspace.getRightDock().paneContainer.destroy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('constructs the view with the same panes', () => {
|
|
|
|
const pane1 = atom.workspace.getRightDock().getActivePane()
|
|
|
|
const pane2 = pane1.splitRight({copyActiveItem: true})
|
|
|
|
const pane3 = pane2.splitRight({copyActiveItem: true})
|
|
|
|
let pane4 = null
|
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-24 04:28:12 +03:00
|
|
|
atom.workspace.open(null, {location: 'right'}).then(editor => editor.setText('An untitled editor.'))
|
2017-03-16 21:48:38 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-24 04:28:12 +03:00
|
|
|
atom.workspace.open('b', {location: 'right'}).then(editor => pane2.activateItem(editor.copy()))
|
2017-03-16 21:48:38 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-24 04:28:12 +03:00
|
|
|
atom.workspace.open('../sample.js', {location: 'right'}).then(editor => pane3.activateItem(editor))
|
2017-03-16 21:48:38 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
runs(() => {
|
|
|
|
pane3.activeItem.setCursorScreenPosition([2, 4])
|
|
|
|
pane4 = pane2.splitDown()
|
|
|
|
})
|
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-24 04:28:12 +03:00
|
|
|
atom.workspace.open('../sample.txt', {location: 'right'}).then(editor => pane4.activateItem(editor))
|
2017-03-16 21:48:38 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
runs(() => {
|
|
|
|
pane4.getActiveItem().setCursorScreenPosition([0, 2])
|
|
|
|
pane2.activate()
|
|
|
|
|
|
|
|
simulateReload()
|
|
|
|
|
|
|
|
expect(atom.workspace.getTextEditors().length).toBe(5)
|
|
|
|
const [editor1, editor2, untitledEditor, editor3, editor4] = atom.workspace.getTextEditors()
|
|
|
|
const firstDirectory = atom.project.getDirectories()[0]
|
|
|
|
expect(firstDirectory).toBeDefined()
|
|
|
|
expect(editor1.getPath()).toBe(firstDirectory.resolve('b'))
|
|
|
|
expect(editor2.getPath()).toBe(firstDirectory.resolve('../sample.txt'))
|
|
|
|
expect(editor2.getCursorScreenPosition()).toEqual([0, 2])
|
|
|
|
expect(editor3.getPath()).toBe(firstDirectory.resolve('b'))
|
|
|
|
expect(editor4.getPath()).toBe(firstDirectory.resolve('../sample.js'))
|
|
|
|
expect(editor4.getCursorScreenPosition()).toEqual([2, 4])
|
|
|
|
expect(untitledEditor.getPath()).toBeUndefined()
|
|
|
|
expect(untitledEditor.getText()).toBe('An untitled editor.')
|
|
|
|
|
|
|
|
expect(atom.workspace.getRightDock().getActiveTextEditor().getPath()).toBe(editor3.getPath())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::open(uri, options)', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let openEvents = null
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
beforeEach(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
openEvents = []
|
|
|
|
workspace.onDidOpen(event => openEvents.push(event))
|
2017-03-03 02:40:57 +03:00
|
|
|
spyOn(workspace.getActivePane(), 'activate').andCallThrough()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03: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', () => {
|
|
|
|
let editor1
|
|
|
|
let editor2
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open().then(editor => { editor1 = editor }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(editor1.getPath()).toBeUndefined()
|
|
|
|
expect(workspace.getActivePane().items).toEqual([editor1])
|
|
|
|
expect(workspace.getActivePaneItem()).toBe(editor1)
|
|
|
|
expect(workspace.getActivePane().activate).toHaveBeenCalled()
|
|
|
|
expect(openEvents).toEqual([{uri: undefined, pane: workspace.getActivePane(), item: editor1, index: 0}])
|
2017-03-03 02:40:57 +03:00
|
|
|
openEvents = []
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open().then(editor => { editor2 = editor }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(editor2.getPath()).toBeUndefined()
|
|
|
|
expect(workspace.getActivePane().items).toEqual([editor1, editor2])
|
|
|
|
expect(workspace.getActivePaneItem()).toBe(editor2)
|
|
|
|
expect(workspace.getActivePane().activate).toHaveBeenCalled()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(openEvents).toEqual([{uri: undefined, pane: workspace.getActivePane(), item: editor2, index: 1}])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03: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', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
let editor1 = null
|
|
|
|
let editor2 = null
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
workspace.open('a').then(o => {
|
2017-03-03 02:12:12 +03:00
|
|
|
editor1 = o
|
2017-03-03 02:40:57 +03:00
|
|
|
return workspace.open('b').then(o => {
|
2017-03-03 02:12:12 +03:00
|
|
|
editor2 = o
|
2017-03-03 02:40:57 +03:00
|
|
|
return workspace.open('a').then(o => { editor = o })
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(editor).toBe(editor1)
|
|
|
|
expect(workspace.getActivePaneItem()).toBe(editor)
|
|
|
|
expect(workspace.getActivePane().activate).toHaveBeenCalled()
|
2017-03-03 02:40:57 +03:00
|
|
|
const firstDirectory = atom.project.getDirectories()[0]
|
|
|
|
expect(firstDirectory).toBeDefined()
|
|
|
|
expect(openEvents).toEqual([
|
2017-03-03 01:31:20 +03:00
|
|
|
{
|
2017-03-03 02:40:57 +03:00
|
|
|
uri: firstDirectory.resolve('a'),
|
2017-03-03 01:31:20 +03:00
|
|
|
item: editor1,
|
|
|
|
pane: atom.workspace.getActivePane(),
|
|
|
|
index: 0
|
|
|
|
},
|
|
|
|
{
|
2017-03-03 02:40:57 +03:00
|
|
|
uri: firstDirectory.resolve('b'),
|
2017-03-03 01:31:20 +03:00
|
|
|
item: editor2,
|
|
|
|
pane: atom.workspace.getActivePane(),
|
|
|
|
index: 1
|
|
|
|
},
|
|
|
|
{
|
2017-03-03 02:40:57 +03:00
|
|
|
uri: firstDirectory.resolve('a'),
|
2017-03-03 01:31:20 +03:00
|
|
|
item: editor1,
|
|
|
|
pane: atom.workspace.getActivePane(),
|
|
|
|
index: 0
|
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
])
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-16 21:48:38 +03:00
|
|
|
|
|
|
|
it('finds items in docks', () => {
|
|
|
|
const dock = atom.workspace.getRightDock()
|
|
|
|
const ITEM_URI = 'atom://test'
|
|
|
|
const item = {
|
|
|
|
getURI: () => ITEM_URI,
|
|
|
|
getDefaultLocation: jasmine.createSpy().andReturn('left'),
|
|
|
|
getElement: () => document.createElement('div')
|
|
|
|
}
|
|
|
|
dock.getActivePane().addItem(item)
|
|
|
|
expect(dock.getPaneItems()).toHaveLength(1)
|
|
|
|
waitsForPromise(() => atom.workspace.open(ITEM_URI, {searchAllPanes: true}))
|
|
|
|
runs(() => {
|
|
|
|
expect(item.getDefaultLocation).not.toHaveBeenCalled()
|
|
|
|
expect(atom.workspace.getPaneItems()).toHaveLength(1)
|
|
|
|
expect(dock.getPaneItems()).toHaveLength(1)
|
|
|
|
expect(dock.getPaneItems()[0]).toBe(item)
|
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03: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', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('a').then(o => { editor = o }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
|
|
|
const firstDirectory = atom.project.getDirectories()[0]
|
|
|
|
expect(firstDirectory).toBeDefined()
|
|
|
|
expect(editor.getURI()).toBe(firstDirectory.resolve('a'))
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePaneItem()).toBe(editor)
|
|
|
|
expect(workspace.getActivePane().items).toEqual([editor])
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(workspace.getActivePane().activate).toHaveBeenCalled()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-16 21:48:38 +03:00
|
|
|
|
|
|
|
it("uses the location specified by the model's `getDefaultLocation()` method", () => {
|
|
|
|
const item = {
|
|
|
|
getDefaultLocation: jasmine.createSpy().andReturn('right'),
|
|
|
|
getElement: () => document.createElement('div')
|
|
|
|
}
|
|
|
|
const opener = jasmine.createSpy().andReturn(item)
|
|
|
|
const dock = atom.workspace.getRightDock()
|
2017-03-23 20:39:02 +03:00
|
|
|
spyOn(atom.workspace.itemLocationStore, 'load').andReturn(Promise.resolve())
|
2017-03-16 21:48:38 +03:00
|
|
|
spyOn(atom.workspace, 'getOpeners').andReturn([opener])
|
|
|
|
expect(dock.getPaneItems()).toHaveLength(0)
|
|
|
|
waitsForPromise(() => atom.workspace.open('a'))
|
|
|
|
runs(() => {
|
|
|
|
expect(dock.getPaneItems()).toHaveLength(1)
|
|
|
|
expect(opener).toHaveBeenCalled()
|
|
|
|
expect(item.getDefaultLocation).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('prefers the last location the user used for that item', () => {
|
|
|
|
const ITEM_URI = 'atom://test'
|
|
|
|
const item = {
|
|
|
|
getURI: () => ITEM_URI,
|
|
|
|
getDefaultLocation: jasmine.createSpy().andReturn('left'),
|
|
|
|
getElement: () => document.createElement('div')
|
|
|
|
}
|
|
|
|
const opener = uri => uri === ITEM_URI ? item : null
|
|
|
|
const dock = atom.workspace.getRightDock()
|
2017-03-23 20:39:02 +03:00
|
|
|
spyOn(atom.workspace.itemLocationStore, 'load').andCallFake(uri =>
|
2017-03-16 21:48:38 +03:00
|
|
|
uri === 'atom://test' ? Promise.resolve('right') : Promise.resolve()
|
|
|
|
)
|
|
|
|
spyOn(atom.workspace, 'getOpeners').andReturn([opener])
|
|
|
|
expect(dock.getPaneItems()).toHaveLength(0)
|
|
|
|
waitsForPromise(() => atom.workspace.open(ITEM_URI))
|
|
|
|
runs(() => {
|
|
|
|
expect(dock.getPaneItems()).toHaveLength(1)
|
|
|
|
expect(dock.getPaneItems()[0]).toBe(item)
|
|
|
|
expect(item.getDefaultLocation).not.toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe("when the 'searchAllPanes' option is true", () => {
|
|
|
|
describe('when an editor for the given uri is already open on an inactive pane', () => {
|
|
|
|
it('activates the existing editor on the inactive pane, then activates that pane', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor1 = null
|
|
|
|
let editor2 = null
|
|
|
|
const pane1 = workspace.getActivePane()
|
|
|
|
const pane2 = workspace.getActivePane().splitRight()
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane1.activate()
|
2017-03-03 02:40:57 +03:00
|
|
|
return workspace.open('a').then(o => { editor1 = o })
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane2.activate()
|
2017-03-03 02:40:57 +03:00
|
|
|
return workspace.open('b').then(o => { editor2 = o })
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
runs(() => expect(workspace.getActivePaneItem()).toBe(editor2))
|
|
|
|
|
|
|
|
waitsForPromise(() => workspace.open('a', {searchAllPanes: true}))
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePane()).toBe(pane1)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(workspace.getActivePaneItem()).toBe(editor1)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-16 21:48:38 +03:00
|
|
|
|
|
|
|
it('activates the dock with the matching item', () => {
|
|
|
|
const dock = atom.workspace.getRightDock()
|
|
|
|
const ITEM_URI = 'atom://test'
|
|
|
|
const item = {
|
|
|
|
getURI: () => ITEM_URI,
|
|
|
|
getDefaultLocation: jasmine.createSpy().andReturn('left'),
|
|
|
|
getElement: () => document.createElement('div')
|
|
|
|
}
|
|
|
|
dock.getActivePane().addItem(item)
|
|
|
|
spyOn(dock, 'activate')
|
|
|
|
waitsForPromise(() => atom.workspace.open(ITEM_URI, {searchAllPanes: true}))
|
|
|
|
runs(() => {
|
|
|
|
expect(dock.activate).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03: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', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {searchAllPanes: true}).then(o => { editor = o }))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(workspace.getActivePaneItem()).toBe(editor))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03: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', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const pane1 = workspace.getActivePane()
|
|
|
|
const pane2 = pane1.splitRight()
|
|
|
|
expect(workspace.getActivePane()).toBe(pane2)
|
|
|
|
|
|
|
|
let editor = null
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {split: 'left'}).then(o => { editor = o }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePane()).toBe(pane1)
|
|
|
|
expect(pane1.items).toEqual([editor])
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(pane2.items).toEqual([])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
// Focus right pane and reopen the file on the left
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane2.focus()
|
2017-03-03 02:40:57 +03:00
|
|
|
return workspace.open('a', {split: 'left'}).then(o => { editor = o })
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePane()).toBe(pane1)
|
|
|
|
expect(pane1.items).toEqual([editor])
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(pane2.items).toEqual([])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when a pane axis is the leftmost sibling of the current pane', () => {
|
|
|
|
it('opens the new item in the current pane', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
const pane1 = workspace.getActivePane()
|
|
|
|
const pane2 = pane1.splitLeft()
|
|
|
|
pane2.splitDown()
|
|
|
|
pane1.activate()
|
|
|
|
expect(workspace.getActivePane()).toBe(pane1)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {split: 'left'}).then(o => { editor = o }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePane()).toBe(pane1)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(pane1.items).toEqual([editor])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe("when the 'split' option is 'right'", () => {
|
|
|
|
it('opens the editor in the rightmost pane of the current pane axis', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
const pane1 = workspace.getActivePane()
|
|
|
|
let pane2 = null
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {split: 'right'}).then(o => { editor = o }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane2 = workspace.getPanes().filter(p => p !== pane1)[0]
|
|
|
|
expect(workspace.getActivePane()).toBe(pane2)
|
|
|
|
expect(pane1.items).toEqual([])
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(pane2.items).toEqual([editor])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
// Focus right pane and reopen the file on the right
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane1.focus()
|
2017-03-03 02:40:57 +03:00
|
|
|
return workspace.open('a', {split: 'right'}).then(o => { editor = o })
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePane()).toBe(pane2)
|
|
|
|
expect(pane1.items).toEqual([])
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(pane2.items).toEqual([editor])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when a pane axis is the rightmost sibling of the current pane', () => {
|
|
|
|
it('opens the new item in a new pane split to the right of the current pane', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
const pane1 = workspace.getActivePane()
|
|
|
|
const pane2 = pane1.splitRight()
|
|
|
|
pane2.splitDown()
|
|
|
|
pane1.activate()
|
|
|
|
expect(workspace.getActivePane()).toBe(pane1)
|
|
|
|
let pane4 = null
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {split: 'right'}).then(o => { editor = o }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane4 = workspace.getPanes().filter(p => p !== pane1)[0]
|
|
|
|
expect(workspace.getActivePane()).toBe(pane4)
|
|
|
|
expect(pane4.items).toEqual([editor])
|
|
|
|
expect(workspace.paneContainer.root.children[0]).toBe(pane1)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(workspace.paneContainer.root.children[1]).toBe(pane4)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe("when the 'split' option is 'up'", () => {
|
|
|
|
it('opens the editor in the topmost pane of the current pane axis', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const pane1 = workspace.getActivePane()
|
|
|
|
const pane2 = pane1.splitDown()
|
|
|
|
expect(workspace.getActivePane()).toBe(pane2)
|
|
|
|
|
|
|
|
let editor = null
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {split: 'up'}).then(o => { editor = o }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePane()).toBe(pane1)
|
|
|
|
expect(pane1.items).toEqual([editor])
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(pane2.items).toEqual([])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
// Focus bottom pane and reopen the file on the top
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane2.focus()
|
2017-03-03 02:40:57 +03:00
|
|
|
return workspace.open('a', {split: 'up'}).then(o => { editor = o })
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePane()).toBe(pane1)
|
|
|
|
expect(pane1.items).toEqual([editor])
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(pane2.items).toEqual([])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when a pane axis is the topmost sibling of the current pane', () => {
|
|
|
|
it('opens the new item in the current pane', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
const pane1 = workspace.getActivePane()
|
|
|
|
const pane2 = pane1.splitUp()
|
|
|
|
pane2.splitRight()
|
|
|
|
pane1.activate()
|
|
|
|
expect(workspace.getActivePane()).toBe(pane1)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {split: 'up'}).then(o => { editor = o }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePane()).toBe(pane1)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(pane1.items).toEqual([editor])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe("when the 'split' option is 'down'", () => {
|
|
|
|
it('opens the editor in the bottommost pane of the current pane axis', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
const pane1 = workspace.getActivePane()
|
|
|
|
let pane2 = null
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {split: 'down'}).then(o => { editor = o }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane2 = workspace.getPanes().filter(p => p !== pane1)[0]
|
|
|
|
expect(workspace.getActivePane()).toBe(pane2)
|
|
|
|
expect(pane1.items).toEqual([])
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(pane2.items).toEqual([editor])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
// Focus bottom pane and reopen the file on the right
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane1.focus()
|
2017-03-03 02:40:57 +03:00
|
|
|
return workspace.open('a', {split: 'down'}).then(o => { editor = o })
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePane()).toBe(pane2)
|
|
|
|
expect(pane1.items).toEqual([])
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(pane2.items).toEqual([editor])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
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', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
const pane1 = workspace.getActivePane()
|
|
|
|
const pane2 = pane1.splitDown()
|
|
|
|
pane1.activate()
|
|
|
|
expect(workspace.getActivePane()).toBe(pane1)
|
|
|
|
let pane4 = null
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {split: 'down'}).then(o => { editor = o }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
pane4 = workspace.getPanes().filter(p => p !== pane1)[0]
|
|
|
|
expect(workspace.getActivePane()).toBe(pane4)
|
|
|
|
expect(pane4.items).toEqual([editor])
|
|
|
|
expect(workspace.paneContainer.root.children[0]).toBe(pane1)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(workspace.paneContainer.root.children[1]).toBe(pane2)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when an initialLine and initialColumn are specified', () => {
|
|
|
|
it('moves the cursor to the indicated location', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {initialLine: 1, initialColumn: 5}))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
runs(() => expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual([1, 5]))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {initialLine: 2, initialColumn: 4}))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
runs(() => expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual([2, 4]))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {initialLine: 0, initialColumn: 0}))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
runs(() => expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual([0, 0]))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {initialLine: NaN, initialColumn: 4}))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
runs(() => expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual([0, 4]))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {initialLine: 2, initialColumn: NaN}))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
runs(() => expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual([2, 0]))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('a', {initialLine: Infinity, initialColumn: Infinity}))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual([2, 11]))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the file is over 2MB', () => {
|
|
|
|
it('opens the editor with largeFileMode: true', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
spyOn(fs, 'getSizeSync').andReturn(2 * 1048577) // 2MB
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('sample.js').then(e => { editor = e }))
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(editor.largeFileMode).toBe(true))
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the file is over user-defined limit', () => {
|
|
|
|
const shouldPromptForFileOfSize = (size, shouldPrompt) => {
|
2017-03-03 02:12:12 +03:00
|
|
|
spyOn(fs, 'getSizeSync').andReturn(size * 1048577)
|
|
|
|
atom.applicationDelegate.confirm.andCallFake(() => selectedButtonIndex)
|
|
|
|
atom.applicationDelegate.confirm()
|
|
|
|
var selectedButtonIndex = 1 // cancel
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('sample.js').then(e => { editor = e }))
|
2017-03-03 01:31:20 +03:00
|
|
|
if (shouldPrompt) {
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(editor).toBeUndefined()
|
|
|
|
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.applicationDelegate.confirm.reset()
|
2017-03-03 02:40:57 +03:00
|
|
|
selectedButtonIndex = 0
|
2017-03-03 02:12:12 +03:00
|
|
|
}) // open the file
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('sample.js').then(e => { editor = e }))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(editor.largeFileMode).toBe(true)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
} else {
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(editor).not.toBeUndefined())
|
2017-03-03 01:31:20 +03:00
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
}
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('prompts the user to make sure they want to open a file this big', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.config.set('core.warnOnLargeFileLimit', 20)
|
2017-03-03 02:40:57 +03:00
|
|
|
shouldPromptForFileOfSize(20, true)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it("doesn't prompt on files below the limit", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.config.set('core.warnOnLargeFileLimit', 30)
|
2017-03-03 02:40:57 +03:00
|
|
|
shouldPromptForFileOfSize(20, false)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('prompts for smaller files with a lower limit', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.config.set('core.warnOnLargeFileLimit', 5)
|
2017-03-03 02:40:57 +03:00
|
|
|
shouldPromptForFileOfSize(10, true)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when passed a path that matches a custom opener', () => {
|
|
|
|
it('returns the resource returned by the custom opener', () => {
|
|
|
|
const fooOpener = (pathToOpen, options) => {
|
|
|
|
if (pathToOpen != null ? pathToOpen.match(/\.foo/) : undefined) {
|
|
|
|
return {foo: pathToOpen, options}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const barOpener = (pathToOpen) => {
|
|
|
|
if (pathToOpen != null ? pathToOpen.match(/^bar:\/\//) : undefined) {
|
|
|
|
return {bar: pathToOpen}
|
|
|
|
}
|
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
workspace.addOpener(fooOpener)
|
|
|
|
workspace.addOpener(barOpener)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => {
|
|
|
|
const pathToOpen = atom.project.getDirectories()[0].resolve('a.foo')
|
2017-03-03 02:12:12 +03:00
|
|
|
return workspace.open(pathToOpen, {hey: 'there'}).then(item => expect(item).toEqual({foo: pathToOpen, options: {hey: 'there'}}))
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:12:12 +03:00
|
|
|
workspace.open('bar://baz').then(item => expect(item).toEqual({bar: 'bar://baz'})))
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it("adds the file to the application's recent documents list", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
if (process.platform !== 'darwin') { return } // Feature only supported on macOS
|
|
|
|
spyOn(atom.applicationDelegate, 'addRecentDocument')
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
runs(() => expect(atom.applicationDelegate.addRecentDocument).not.toHaveBeenCalled())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('something://a/url'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
runs(() => expect(atom.applicationDelegate.addRecentDocument).not.toHaveBeenCalled())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open(__filename))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(atom.applicationDelegate.addRecentDocument).toHaveBeenCalledWith(__filename))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('notifies ::onDidAddTextEditor observers', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const absolutePath = require.resolve('./fixtures/dir/a')
|
|
|
|
const newEditorHandler = jasmine.createSpy('newEditorHandler')
|
|
|
|
workspace.onDidAddTextEditor(newEditorHandler)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open(absolutePath).then(e => { editor = e }))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(newEditorHandler.argsForCall[0][0].textEditor).toBe(editor))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when there is an error opening the file', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let notificationSpy = null
|
|
|
|
beforeEach(() => atom.notifications.onDidAddNotification(notificationSpy = jasmine.createSpy()))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when a file does not exist', () => {
|
|
|
|
it('creates an empty buffer for the specified path', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('not-a-file.md'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const editor = workspace.getActiveTextEditor()
|
|
|
|
expect(notificationSpy).not.toHaveBeenCalled()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(editor.getPath()).toContain('not-a-file.md')
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the user does not have access to the file', () => {
|
2017-03-03 01:31:20 +03:00
|
|
|
beforeEach(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
spyOn(fs, 'openSync').andCallFake(path => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const error = new Error(`EACCES, permission denied '${path}'`)
|
|
|
|
error.path = path
|
|
|
|
error.code = 'EACCES'
|
|
|
|
throw error
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('creates a notification', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('file1'))
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(notificationSpy).toHaveBeenCalled()
|
|
|
|
const notification = notificationSpy.mostRecentCall.args[0]
|
|
|
|
expect(notification.getType()).toBe('warning')
|
|
|
|
expect(notification.getMessage()).toContain('Permission denied')
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(notification.getMessage()).toContain('file1')
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the the operation is not permitted', () => {
|
2017-03-03 01:31:20 +03:00
|
|
|
beforeEach(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
spyOn(fs, 'openSync').andCallFake(path => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const error = new Error(`EPERM, operation not permitted '${path}'`)
|
|
|
|
error.path = path
|
|
|
|
error.code = 'EPERM'
|
|
|
|
throw error
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('creates a notification', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('file1'))
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(notificationSpy).toHaveBeenCalled()
|
|
|
|
const notification = notificationSpy.mostRecentCall.args[0]
|
|
|
|
expect(notification.getType()).toBe('warning')
|
|
|
|
expect(notification.getMessage()).toContain('Unable to open')
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(notification.getMessage()).toContain('file1')
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the the file is already open in windows', () => {
|
2017-03-03 01:31:20 +03:00
|
|
|
beforeEach(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
spyOn(fs, 'openSync').andCallFake(path => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const error = new Error(`EBUSY, resource busy or locked '${path}'`)
|
|
|
|
error.path = path
|
|
|
|
error.code = 'EBUSY'
|
|
|
|
throw error
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('creates a notification', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('file1'))
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(notificationSpy).toHaveBeenCalled()
|
|
|
|
const notification = notificationSpy.mostRecentCall.args[0]
|
|
|
|
expect(notification.getType()).toBe('warning')
|
|
|
|
expect(notification.getMessage()).toContain('Unable to open')
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(notification.getMessage()).toContain('file1')
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when there is an unhandled error', () => {
|
2017-03-03 01:31:20 +03:00
|
|
|
beforeEach(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
spyOn(fs, 'openSync').andCallFake(path => {
|
2017-03-03 02:12:12 +03:00
|
|
|
throw new Error('I dont even know what is happening right now!!')
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-25 01:35:52 +03:00
|
|
|
it('rejects the promise', () => {
|
|
|
|
waitsFor((done) => {
|
|
|
|
workspace.open('file1').catch(error => {
|
|
|
|
expect(error.message).toBe('I dont even know what is happening right now!!')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the file is already open in pending state', () => {
|
|
|
|
it('should terminate the pending state', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
let pane = null
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.workspace.open('sample.js', {pending: true}).then(o => {
|
2017-03-03 02:12:12 +03:00
|
|
|
editor = o
|
2017-03-03 02:40:57 +03:00
|
|
|
pane = atom.workspace.getActivePane()
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
runs(() => expect(pane.getPendingItem()).toEqual(editor))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.workspace.open('sample.js'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(pane.getPendingItem()).toBeNull())
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when opening will switch from a pending tab to a permanent tab', () => {
|
|
|
|
it('keeps the pending tab open', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor1 = null
|
|
|
|
let editor2 = null
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.workspace.open('sample.txt').then(o => { editor1 = o })
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.workspace.open('sample2.txt', {pending: true}).then(o => { editor2 = o })
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const pane = atom.workspace.getActivePane()
|
|
|
|
pane.activateItem(editor1)
|
|
|
|
expect(pane.getItems().length).toBe(2)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(pane.getItems()).toEqual([editor1, editor2])
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when replacing a pending item which is the last item in a second pane', () => {
|
|
|
|
it('does not destroy the pane even if core.destroyEmptyPanes is on', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.config.set('core.destroyEmptyPanes', true)
|
|
|
|
let editor1 = null
|
|
|
|
let editor2 = null
|
|
|
|
const leftPane = atom.workspace.getActivePane()
|
|
|
|
let rightPane = null
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.workspace.open('sample.js', {pending: true, split: 'right'}).then(o => {
|
2017-03-03 02:12:12 +03:00
|
|
|
editor1 = o
|
|
|
|
rightPane = atom.workspace.getActivePane()
|
2017-03-03 02:40:57 +03:00
|
|
|
spyOn(rightPane, 'destroyed')
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(leftPane).not.toBe(rightPane)
|
|
|
|
expect(atom.workspace.getActivePane()).toBe(rightPane)
|
|
|
|
expect(atom.workspace.getActivePane().getItems().length).toBe(1)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(rightPane.getPendingItem()).toBe(editor1)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.workspace.open('sample.txt', {pending: true}).then(o => { editor2 = o })
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(rightPane.getPendingItem()).toBe(editor2)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(rightPane.destroyed.callCount).toBe(0)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-31 03:37:55 +03:00
|
|
|
describe('::hide(uri)', () => {
|
|
|
|
let item
|
|
|
|
const URI = 'atom://hide-test'
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const el = document.createElement('div')
|
|
|
|
item = {
|
|
|
|
getTitle: () => 'Item',
|
|
|
|
getElement: () => el,
|
|
|
|
getURI: () => URI
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('removes matching items from the center', () => {
|
|
|
|
const pane = atom.workspace.getActivePane()
|
|
|
|
pane.addItem(item)
|
|
|
|
atom.workspace.hide(URI)
|
|
|
|
expect(pane.getItems().length).toBe(0)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('hides the dock when an item matches', () => {
|
|
|
|
const dock = atom.workspace.getLeftDock()
|
|
|
|
const pane = dock.getActivePane()
|
|
|
|
pane.addItem(item)
|
|
|
|
dock.activate()
|
|
|
|
expect(dock.isOpen()).toBe(true)
|
|
|
|
const itemFound = atom.workspace.hide(URI)
|
|
|
|
expect(itemFound).toBe(true)
|
|
|
|
expect(dock.isOpen()).toBe(false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('::toggle(uri)', () => {
|
|
|
|
it('shows the item and dock if no item matches', () => {
|
|
|
|
const URI = 'atom://hide-test'
|
|
|
|
workspace.addOpener(uri => {
|
|
|
|
if (uri === URI) {
|
|
|
|
const el = document.createElement('div')
|
|
|
|
return {
|
|
|
|
getDefaultLocation: () => 'left',
|
|
|
|
getTitle: () => 'Item',
|
|
|
|
getElement: () => el,
|
|
|
|
getURI: () => URI
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
const dock = workspace.getLeftDock()
|
|
|
|
expect(dock.isOpen()).toBe(false)
|
|
|
|
waitsFor(done => {
|
|
|
|
workspace.onDidOpen(({item}) => {
|
|
|
|
expect(item.getURI()).toBe(URI)
|
|
|
|
expect(dock.isOpen()).toBe(true)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
workspace.toggle(URI)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('the grammar-used hook', () => {
|
|
|
|
it('fires when opening a file or changing the grammar of an open file', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
let javascriptGrammarUsed = false
|
|
|
|
let coffeescriptGrammarUsed = false
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.packages.triggerDeferredActivationHooks()
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
|
|
|
atom.packages.onDidTriggerActivationHook('language-javascript:grammar-used', () => { javascriptGrammarUsed = true })
|
|
|
|
atom.packages.onDidTriggerActivationHook('language-coffee-script:grammar-used', () => { coffeescriptGrammarUsed = true })
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => atom.workspace.open('sample.js', {autoIndent: false}).then(o => { editor = o }))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.packages.activatePackage('language-javascript'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsFor(() => javascriptGrammarUsed)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.packages.activatePackage('language-coffee-script'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
runs(() => editor.setGrammar(atom.grammars.selectGrammar('.coffee')))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsFor(() => coffeescriptGrammarUsed)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::reopenItem()', () => {
|
|
|
|
it("opens the uri associated with the last closed pane that isn't currently open", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const pane = workspace.getActivePane()
|
2017-03-03 01:31:20 +03:00
|
|
|
waitsForPromise(() =>
|
|
|
|
workspace.open('a').then(() =>
|
|
|
|
workspace.open('b').then(() =>
|
|
|
|
workspace.open('file1').then(() => workspace.open())
|
|
|
|
)
|
|
|
|
)
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 01:31:20 +03:00
|
|
|
// does not reopen items with no uri
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).toBeUndefined()
|
2017-03-03 02:40:57 +03:00
|
|
|
pane.destroyActiveItem()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.reopenItem())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
const firstDirectory = atom.project.getDirectories()[0]
|
|
|
|
expect(firstDirectory).toBeDefined()
|
|
|
|
|
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).not.toBeUndefined()
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
// destroy all items
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).toBe(firstDirectory.resolve('file1'))
|
2017-03-03 02:12:12 +03:00
|
|
|
pane.destroyActiveItem()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).toBe(firstDirectory.resolve('b'))
|
2017-03-03 02:12:12 +03:00
|
|
|
pane.destroyActiveItem()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(workspace.getActivePaneItem().getURI()).toBe(firstDirectory.resolve('a'))
|
2017-03-03 02:12:12 +03:00
|
|
|
pane.destroyActiveItem()
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
// reopens items with uris
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(workspace.getActivePaneItem()).toBeUndefined()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.reopenItem())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(workspace.getActivePaneItem().getURI()).toBe(firstDirectory.resolve('a')))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
// does not reopen items that are already open
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open('b'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(workspace.getActivePaneItem().getURI()).toBe(firstDirectory.resolve('b')))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.reopenItem())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(workspace.getActivePaneItem().getURI()).toBe(firstDirectory.resolve('file1')))
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::increase/decreaseFontSize()', () => {
|
|
|
|
it('increases/decreases the font size without going below 1', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
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()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(atom.config.get('editor.fontSize')).toBe(1)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::resetFontSize()', () => {
|
|
|
|
it("resets the font size to the window's starting font size", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const originalFontSize = atom.config.get('editor.fontSize')
|
|
|
|
|
|
|
|
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()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(atom.config.get('editor.fontSize')).toBe(originalFontSize)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('does nothing if the font size has not been changed', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const originalFontSize = atom.config.get('editor.fontSize')
|
|
|
|
|
|
|
|
workspace.resetFontSize()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(atom.config.get('editor.fontSize')).toBe(originalFontSize)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it("resets the font size when the editor's font size changes", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const originalFontSize = atom.config.get('editor.fontSize')
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
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()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(atom.config.get('editor.fontSize')).toBe(originalFontSize)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::openLicense()', () => {
|
|
|
|
it('opens the license as plain-text in a buffer', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.openLicense())
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(workspace.getActivePaneItem().getText()).toMatch(/Copyright/))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::isTextEditor(obj)', () => {
|
|
|
|
it('returns true when the passed object is an instance of `TextEditor`', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.isTextEditor(new TextEditor())).toBe(true)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(workspace.isTextEditor({getText: () => null})).toBe(false)
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.isTextEditor(null)).toBe(false)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(workspace.isTextEditor(undefined)).toBe(false)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::observeTextEditors()', () => {
|
|
|
|
it('invokes the observer with current and future text editors', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const observed = []
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => workspace.open())
|
|
|
|
waitsForPromise(() => workspace.open())
|
|
|
|
waitsForPromise(() => workspace.openLicense())
|
|
|
|
|
|
|
|
runs(() => workspace.observeTextEditors(editor => observed.push(editor)))
|
|
|
|
|
|
|
|
waitsForPromise(() => workspace.open())
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(observed).toEqual(workspace.getTextEditors())
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when an editor is destroyed', () => {
|
|
|
|
it('removes the editor', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => workspace.open('a').then(e => { editor = e }))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(workspace.getTextEditors()).toHaveLength(1)
|
|
|
|
editor.destroy()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(workspace.getTextEditors()).toHaveLength(0)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when an editor is copied because its pane is split', () => {
|
|
|
|
it('sets up the new editor to be configured by the text editor registry', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.packages.activatePackage('language-javascript'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() =>
|
|
|
|
workspace.open('a').then(editor => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.textEditors.setGrammarOverride(editor, 'source.js')
|
|
|
|
expect(editor.getGrammar().name).toBe('JavaScript')
|
|
|
|
|
|
|
|
workspace.getActivePane().splitRight({copyActiveItem: true})
|
|
|
|
const newEditor = workspace.getActiveTextEditor()
|
|
|
|
expect(newEditor).not.toBe(editor)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(newEditor.getGrammar().name).toBe('JavaScript')
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('stores the active grammars used by all the open editors', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.packages.activatePackage('language-javascript'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.packages.activatePackage('language-coffee-script'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.packages.activatePackage('language-todo'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.workspace.open('sample.coffee'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(function () {
|
2017-03-03 01:31:20 +03:00
|
|
|
atom.workspace.getActiveTextEditor().setText(`\
|
|
|
|
i = /test/; #FIXME\
|
|
|
|
`
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-11 21:20:16 +03:00
|
|
|
const atom2 = new AtomEnvironment({applicationDelegate: atom.applicationDelegate})
|
|
|
|
atom2.initialize({
|
2017-03-03 01:31:20 +03:00
|
|
|
window: document.createElement('div'),
|
|
|
|
document: Object.assign(
|
|
|
|
document.createElement('div'),
|
|
|
|
{
|
|
|
|
body: document.createElement('div'),
|
2017-03-03 02:12:12 +03:00
|
|
|
head: document.createElement('div')
|
2017-03-03 01:31:20 +03:00
|
|
|
}
|
|
|
|
)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
atom2.packages.loadPackage('language-javascript')
|
|
|
|
atom2.packages.loadPackage('language-coffee-script')
|
|
|
|
atom2.packages.loadPackage('language-todo')
|
|
|
|
atom2.project.deserialize(atom.project.serialize())
|
|
|
|
atom2.workspace.deserialize(atom.workspace.serialize(), atom2.deserializers)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
expect(atom2.grammars.getGrammars().map(grammar => grammar.name).sort()).toEqual([
|
|
|
|
'CoffeeScript',
|
|
|
|
'CoffeeScript (Literate)',
|
|
|
|
'JavaScript',
|
|
|
|
'Null Grammar',
|
|
|
|
'Regular Expression Replacement (JavaScript)',
|
|
|
|
'Regular Expressions (JavaScript)',
|
|
|
|
'TODO'
|
2017-03-03 02:12:12 +03:00
|
|
|
])
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
atom2.destroy()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('document.title', () => {
|
|
|
|
describe('when there is no item open', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
it('sets the title to the project path', () => expect(document.title).toMatch(escapeStringRegex(fs.tildify(atom.project.getPaths()[0]))))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it("sets the title to 'untitled' if there is no project path", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.project.setPaths([])
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(document.title).toMatch(/^untitled/)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe("when the active pane item's path is not inside a project path", () => {
|
2017-03-03 01:31:20 +03:00
|
|
|
beforeEach(() =>
|
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.open('b').then(() => atom.project.setPaths([]))
|
|
|
|
)
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it("sets the title to the pane item's title plus the item's path", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const item = atom.workspace.getActivePaneItem()
|
|
|
|
const pathEscaped = fs.tildify(escapeStringRegex(path.dirname(item.getPath())))
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(document.title).toMatch(new RegExp(`^${item.getTitle()} \\u2014 ${pathEscaped}`))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the title of the active pane item changes', () => {
|
|
|
|
it("updates the window title based on the item's new title", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const editor = atom.workspace.getActivePaneItem()
|
|
|
|
editor.buffer.setPath(path.join(temp.dir, 'hi'))
|
|
|
|
const pathEscaped = fs.tildify(escapeStringRegex(path.dirname(editor.getPath())))
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(document.title).toMatch(new RegExp(`^${editor.getTitle()} \\u2014 ${pathEscaped}`))
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe("when the active pane's item changes", () => {
|
|
|
|
it("updates the title to the new item's title plus the project path", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.workspace.getActivePane().activateNextItem()
|
|
|
|
const item = atom.workspace.getActivePaneItem()
|
|
|
|
const pathEscaped = fs.tildify(escapeStringRegex(path.dirname(item.getPath())))
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(document.title).toMatch(new RegExp(`^${item.getTitle()} \\u2014 ${pathEscaped}`))
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe("when an inactive pane's item changes", () => {
|
|
|
|
it('does not update the title', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const pane = atom.workspace.getActivePane()
|
|
|
|
pane.splitRight()
|
|
|
|
const initialTitle = document.title
|
|
|
|
pane.activateNextItem()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(document.title).toBe(initialTitle)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the active pane item is inside a project path', () => {
|
2017-03-03 01:31:20 +03:00
|
|
|
beforeEach(() =>
|
|
|
|
waitsForPromise(() => atom.workspace.open('b'))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when there is an active pane item', () => {
|
|
|
|
it("sets the title to the pane item's title plus the project path", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const item = atom.workspace.getActivePaneItem()
|
|
|
|
const pathEscaped = fs.tildify(escapeStringRegex(atom.project.getPaths()[0]))
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(document.title).toMatch(new RegExp(`^${item.getTitle()} \\u2014 ${pathEscaped}`))
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the title of the active pane item changes', () => {
|
|
|
|
it("updates the window title based on the item's new title", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const editor = atom.workspace.getActivePaneItem()
|
|
|
|
editor.buffer.setPath(path.join(atom.project.getPaths()[0], 'hi'))
|
|
|
|
const pathEscaped = fs.tildify(escapeStringRegex(atom.project.getPaths()[0]))
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(document.title).toMatch(new RegExp(`^${editor.getTitle()} \\u2014 ${pathEscaped}`))
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe("when the active pane's item changes", () => {
|
|
|
|
it("updates the title to the new item's title plus the project path", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.workspace.getActivePane().activateNextItem()
|
|
|
|
const item = atom.workspace.getActivePaneItem()
|
|
|
|
const pathEscaped = fs.tildify(escapeStringRegex(atom.project.getPaths()[0]))
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(document.title).toMatch(new RegExp(`^${item.getTitle()} \\u2014 ${pathEscaped}`))
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the last pane item is removed', () => {
|
|
|
|
it("updates the title to the project's first path", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.workspace.getActivePane().destroy()
|
|
|
|
expect(atom.workspace.getActivePaneItem()).toBeUndefined()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(document.title).toMatch(escapeStringRegex(fs.tildify(atom.project.getPaths()[0])))
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe("when an inactive pane's item changes", () => {
|
|
|
|
it('does not update the title', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const pane = atom.workspace.getActivePane()
|
|
|
|
pane.splitRight()
|
|
|
|
const initialTitle = document.title
|
|
|
|
pane.activateNextItem()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(document.title).toBe(initialTitle)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the workspace is deserialized', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
beforeEach(() => waitsForPromise(() => atom.workspace.open('a')))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it("updates the title to contain the project's path", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
document.title = null
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-11 21:20:16 +03:00
|
|
|
const atom2 = new AtomEnvironment({applicationDelegate: atom.applicationDelegate})
|
|
|
|
atom2.initialize({
|
2017-03-03 01:31:20 +03:00
|
|
|
window: document.createElement('div'),
|
|
|
|
document: Object.assign(
|
|
|
|
document.createElement('div'),
|
|
|
|
{
|
|
|
|
body: document.createElement('div'),
|
2017-03-03 02:12:12 +03:00
|
|
|
head: document.createElement('div')
|
2017-03-03 01:31:20 +03:00
|
|
|
}
|
|
|
|
)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
atom2.project.deserialize(atom.project.serialize())
|
|
|
|
atom2.workspace.deserialize(atom.workspace.serialize(), atom2.deserializers)
|
|
|
|
const item = atom2.workspace.getActivePaneItem()
|
|
|
|
const pathEscaped = fs.tildify(escapeStringRegex(atom.project.getPaths()[0]))
|
|
|
|
expect(document.title).toMatch(new RegExp(`^${item.getLongTitle()} \\u2014 ${pathEscaped}`))
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
atom2.destroy()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('document edited status', () => {
|
|
|
|
let item1
|
|
|
|
let item2
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
beforeEach(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.workspace.open('a'))
|
|
|
|
waitsForPromise(() => atom.workspace.open('b'))
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
|
|
|
[item1, item2] = atom.workspace.getPaneItems()
|
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('calls setDocumentEdited when the active item changes', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(atom.workspace.getActivePaneItem()).toBe(item2)
|
|
|
|
item1.insertText('a')
|
|
|
|
expect(item1.isModified()).toBe(true)
|
|
|
|
atom.workspace.getActivePane().activateNextItem()
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(setDocumentEdited).toHaveBeenCalledWith(true)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it("calls atom.setDocumentEdited when the active item's modified status changes", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(atom.workspace.getActivePaneItem()).toBe(item2)
|
|
|
|
item2.insertText('a')
|
|
|
|
advanceClock(item2.getBuffer().getStoppedChangingDelay())
|
|
|
|
|
|
|
|
expect(item2.isModified()).toBe(true)
|
|
|
|
expect(setDocumentEdited).toHaveBeenCalledWith(true)
|
|
|
|
|
|
|
|
item2.undo()
|
|
|
|
advanceClock(item2.getBuffer().getStoppedChangingDelay())
|
|
|
|
|
|
|
|
expect(item2.isModified()).toBe(false)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(setDocumentEdited).toHaveBeenCalledWith(false)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('adding panels', () => {
|
2017-03-03 01:31:20 +03:00
|
|
|
class TestItem {}
|
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
// Don't use ES6 classes because then we'll have to call `super()` which we can't do with
|
|
|
|
// HTMLElement
|
|
|
|
function TestItemElement () { this.constructor = TestItemElement }
|
|
|
|
function Ctor () { this.constructor = TestItemElement }
|
|
|
|
Ctor.prototype = HTMLElement.prototype
|
|
|
|
TestItemElement.prototype = new Ctor()
|
|
|
|
TestItemElement.__super__ = HTMLElement.prototype
|
|
|
|
TestItemElement.prototype.initialize = function (model) { this.model = model; return this }
|
|
|
|
TestItemElement.prototype.getModel = function () { return this.model }
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
beforeEach(() =>
|
|
|
|
atom.views.addViewProvider(TestItem, model => new TestItemElement().initialize(model))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::addLeftPanel(model)', () => {
|
|
|
|
it('adds a panel to the correct panel container', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addPanelSpy
|
|
|
|
expect(atom.workspace.getLeftPanels().length).toBe(0)
|
|
|
|
atom.workspace.panelContainers.left.onDidAddPanel(addPanelSpy = jasmine.createSpy())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const model = new TestItem()
|
|
|
|
const panel = atom.workspace.addLeftPanel({item: model})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(panel).toBeDefined()
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const itemView = atom.views.getView(atom.workspace.getLeftPanels()[0].getItem())
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(itemView.getModel()).toBe(model)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::addRightPanel(model)', () => {
|
|
|
|
it('adds a panel to the correct panel container', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addPanelSpy
|
|
|
|
expect(atom.workspace.getRightPanels().length).toBe(0)
|
|
|
|
atom.workspace.panelContainers.right.onDidAddPanel(addPanelSpy = jasmine.createSpy())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const model = new TestItem()
|
|
|
|
const panel = atom.workspace.addRightPanel({item: model})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(panel).toBeDefined()
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const itemView = atom.views.getView(atom.workspace.getRightPanels()[0].getItem())
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(itemView.getModel()).toBe(model)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::addTopPanel(model)', () => {
|
|
|
|
it('adds a panel to the correct panel container', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addPanelSpy
|
|
|
|
expect(atom.workspace.getTopPanels().length).toBe(0)
|
|
|
|
atom.workspace.panelContainers.top.onDidAddPanel(addPanelSpy = jasmine.createSpy())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const model = new TestItem()
|
|
|
|
const panel = atom.workspace.addTopPanel({item: model})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(panel).toBeDefined()
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const itemView = atom.views.getView(atom.workspace.getTopPanels()[0].getItem())
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(itemView.getModel()).toBe(model)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::addBottomPanel(model)', () => {
|
|
|
|
it('adds a panel to the correct panel container', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addPanelSpy
|
|
|
|
expect(atom.workspace.getBottomPanels().length).toBe(0)
|
|
|
|
atom.workspace.panelContainers.bottom.onDidAddPanel(addPanelSpy = jasmine.createSpy())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const model = new TestItem()
|
|
|
|
const panel = atom.workspace.addBottomPanel({item: model})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(panel).toBeDefined()
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const itemView = atom.views.getView(atom.workspace.getBottomPanels()[0].getItem())
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(itemView.getModel()).toBe(model)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::addHeaderPanel(model)', () => {
|
|
|
|
it('adds a panel to the correct panel container', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addPanelSpy
|
|
|
|
expect(atom.workspace.getHeaderPanels().length).toBe(0)
|
|
|
|
atom.workspace.panelContainers.header.onDidAddPanel(addPanelSpy = jasmine.createSpy())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const model = new TestItem()
|
|
|
|
const panel = atom.workspace.addHeaderPanel({item: model})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(panel).toBeDefined()
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const itemView = atom.views.getView(atom.workspace.getHeaderPanels()[0].getItem())
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(itemView.getModel()).toBe(model)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::addFooterPanel(model)', () => {
|
|
|
|
it('adds a panel to the correct panel container', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addPanelSpy
|
|
|
|
expect(atom.workspace.getFooterPanels().length).toBe(0)
|
|
|
|
atom.workspace.panelContainers.footer.onDidAddPanel(addPanelSpy = jasmine.createSpy())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const model = new TestItem()
|
|
|
|
const panel = atom.workspace.addFooterPanel({item: model})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(panel).toBeDefined()
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const itemView = atom.views.getView(atom.workspace.getFooterPanels()[0].getItem())
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(itemView.getModel()).toBe(model)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::addModalPanel(model)', () => {
|
|
|
|
it('adds a panel to the correct panel container', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addPanelSpy
|
|
|
|
expect(atom.workspace.getModalPanels().length).toBe(0)
|
|
|
|
atom.workspace.panelContainers.modal.onDidAddPanel(addPanelSpy = jasmine.createSpy())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const model = new TestItem()
|
|
|
|
const panel = atom.workspace.addModalPanel({item: model})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(panel).toBeDefined()
|
|
|
|
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const itemView = atom.views.getView(atom.workspace.getModalPanels()[0].getItem())
|
|
|
|
expect(itemView instanceof TestItemElement).toBe(true)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(itemView.getModel()).toBe(model)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::panelForItem(item)', () => {
|
|
|
|
it('returns the panel associated with the item', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const item = new TestItem()
|
|
|
|
const panel = atom.workspace.addLeftPanel({item})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const itemWithNoPanel = new TestItem()
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(atom.workspace.panelForItem(item)).toBe(panel)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(atom.workspace.panelForItem(itemWithNoPanel)).toBe(null)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::scan(regex, options, callback)', () => {
|
|
|
|
describe('when called with a regex', () => {
|
|
|
|
it('calls the callback with all regex results in all files in the project', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const results = []
|
2017-03-03 01:31:20 +03:00
|
|
|
waitsForPromise(() =>
|
2017-03-10 06:29:45 +03:00
|
|
|
atom.workspace.scan(
|
|
|
|
/(a)+/, {leadingContextLineCount: 1, trailingContextLineCount: 1},
|
|
|
|
result => results.push(result))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(results).toHaveLength(3)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(results[0].filePath).toBe(atom.project.getDirectories()[0].resolve('a'))
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(results[0].matches).toHaveLength(3)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(results[0].matches[0]).toEqual({
|
2017-03-03 01:31:20 +03:00
|
|
|
matchText: 'aaa',
|
|
|
|
lineText: 'aaa bbb',
|
|
|
|
lineTextOffset: 0,
|
2017-03-10 11:31:59 +03:00
|
|
|
range: [[0, 0], [0, 3]],
|
|
|
|
leadingContextLines: [],
|
2017-03-10 06:29:45 +03:00
|
|
|
trailingContextLines: ['cc aa cc']
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('works with with escaped literals (like $ and ^)', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const results = []
|
2017-03-10 06:29:45 +03:00
|
|
|
waitsForPromise(() => atom.workspace.scan(
|
|
|
|
/\$\w+/, {leadingContextLineCount: 1, trailingContextLineCount: 1},
|
|
|
|
result => results.push(result)))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(results.length).toBe(1)
|
|
|
|
const {filePath, matches} = results[0]
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(filePath).toBe(atom.project.getDirectories()[0].resolve('a'))
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(matches).toHaveLength(1)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(matches[0]).toEqual({
|
2017-03-03 01:31:20 +03:00
|
|
|
matchText: '$bill',
|
|
|
|
lineText: 'dollar$bill',
|
|
|
|
lineTextOffset: 0,
|
2017-03-10 11:31:59 +03:00
|
|
|
range: [[2, 6], [2, 11]],
|
2017-03-10 06:29:45 +03:00
|
|
|
leadingContextLines: ['cc aa cc'],
|
2017-03-10 11:31:59 +03:00
|
|
|
trailingContextLines: []
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('works on evil filenames', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.config.set('core.excludeVcsIgnoredPaths', false)
|
|
|
|
platform.generateEvilFiles()
|
|
|
|
atom.project.setPaths([path.join(__dirname, 'fixtures', 'evil-files')])
|
|
|
|
const paths = []
|
|
|
|
let matches = []
|
2017-03-03 01:31:20 +03:00
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.workspace.scan(/evil/, result => {
|
2017-03-03 02:12:12 +03:00
|
|
|
paths.push(result.filePath)
|
2017-03-03 02:40:57 +03:00
|
|
|
matches = matches.concat(result.matches)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
_.each(matches, m => expect(m.matchText).toEqual('evil'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
if (platform.isWindows()) {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(paths.length).toBe(3)
|
|
|
|
expect(paths[0]).toMatch(/a_file_with_utf8.txt$/)
|
|
|
|
expect(paths[1]).toMatch(/file with spaces.txt$/)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(path.basename(paths[2])).toBe('utfa\u0306.md')
|
2017-03-03 01:31:20 +03:00
|
|
|
} else {
|
2017-03-03 02:12:12 +03:00
|
|
|
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)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(path.basename(paths[4])).toBe('utfa\u0306.md')
|
2017-03-03 01:31:20 +03:00
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('ignores case if the regex includes the `i` flag', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const results = []
|
|
|
|
waitsForPromise(() => atom.workspace.scan(/DOLLAR/i, result => results.push(result)))
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(results).toHaveLength(1))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the core.excludeVcsIgnoredPaths config is truthy', () => {
|
|
|
|
let projectPath
|
|
|
|
let ignoredPath
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
beforeEach(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const sourceProjectPath = path.join(__dirname, 'fixtures', 'git', 'working-dir')
|
|
|
|
projectPath = path.join(temp.mkdirSync('atom'))
|
|
|
|
|
|
|
|
const writerStream = fstream.Writer(projectPath)
|
|
|
|
fstream.Reader(sourceProjectPath).pipe(writerStream)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsFor(done => {
|
2017-03-03 02:12:12 +03:00
|
|
|
writerStream.on('close', done)
|
2017-03-03 02:40:57 +03:00
|
|
|
writerStream.on('error', done)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
fs.rename(path.join(projectPath, 'git.git'), path.join(projectPath, '.git'))
|
|
|
|
ignoredPath = path.join(projectPath, 'ignored.txt')
|
2017-03-03 02:40:57 +03:00
|
|
|
fs.writeFileSync(ignoredPath, 'this match should not be included')
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
afterEach(() => {
|
|
|
|
if (fs.existsSync(projectPath)) {
|
|
|
|
fs.removeSync(projectPath)
|
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('excludes ignored files', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.project.setPaths([projectPath])
|
|
|
|
atom.config.set('core.excludeVcsIgnoredPaths', true)
|
|
|
|
const resultHandler = jasmine.createSpy('result found')
|
2017-03-03 01:31:20 +03:00
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.scan(/match/, results => resultHandler())
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(resultHandler).not.toHaveBeenCalled())
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('includes only files when a directory filter is specified', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const projectPath = path.join(path.join(__dirname, 'fixtures', 'dir'))
|
|
|
|
atom.project.setPaths([projectPath])
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const filePath = path.join(projectPath, 'a-dir', 'oh-git')
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const paths = []
|
|
|
|
let matches = []
|
2017-03-03 01:31:20 +03:00
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.workspace.scan(/aaa/, {paths: [`a-dir${path.sep}`]}, result => {
|
2017-03-03 02:12:12 +03:00
|
|
|
paths.push(result.filePath)
|
2017-03-03 02:40:57 +03:00
|
|
|
matches = matches.concat(result.matches)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(paths.length).toBe(1)
|
|
|
|
expect(paths[0]).toBe(filePath)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(matches.length).toBe(1)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it("includes files and folders that begin with a '.'", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const projectPath = temp.mkdirSync('atom-spec-workspace')
|
|
|
|
const filePath = path.join(projectPath, '.text')
|
|
|
|
fs.writeFileSync(filePath, 'match this')
|
|
|
|
atom.project.setPaths([projectPath])
|
|
|
|
const paths = []
|
|
|
|
let matches = []
|
2017-03-03 01:31:20 +03:00
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.workspace.scan(/match this/, result => {
|
2017-03-03 02:12:12 +03:00
|
|
|
paths.push(result.filePath)
|
2017-03-03 02:40:57 +03:00
|
|
|
matches = matches.concat(result.matches)
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(paths.length).toBe(1)
|
|
|
|
expect(paths[0]).toBe(filePath)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(matches.length).toBe(1)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('excludes values in core.ignoredNames', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const ignoredNames = atom.config.get('core.ignoredNames')
|
|
|
|
ignoredNames.push('a')
|
|
|
|
atom.config.set('core.ignoredNames', ignoredNames)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const resultHandler = jasmine.createSpy('result found')
|
2017-03-03 01:31:20 +03:00
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.scan(/dollar/, results => resultHandler())
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(resultHandler).not.toHaveBeenCalled())
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('scans buffer contents if the buffer is modified', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
const results = []
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.workspace.open('a').then(o => {
|
2017-03-03 02:12:12 +03:00
|
|
|
editor = o
|
2017-03-03 02:40:57 +03:00
|
|
|
editor.setText('Elephant')
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.workspace.scan(/a|Elephant/, result => results.push(result)))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(results).toHaveLength(3)
|
|
|
|
const resultForA = _.find(results, ({filePath}) => path.basename(filePath) === 'a')
|
|
|
|
expect(resultForA.matches).toHaveLength(1)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(resultForA.matches[0].matchText).toBe('Elephant')
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('ignores buffers outside the project', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
const results = []
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.workspace.open(temp.openSync().path).then(o => {
|
2017-03-03 02:12:12 +03:00
|
|
|
editor = o
|
2017-03-03 02:40:57 +03:00
|
|
|
editor.setText('Elephant')
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.workspace.scan(/Elephant/, result => results.push(result)))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(results).toHaveLength(0))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the project has multiple root directories', () => {
|
|
|
|
let dir1
|
|
|
|
let dir2
|
|
|
|
let file1
|
|
|
|
let file2
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
beforeEach(() => {
|
|
|
|
dir1 = atom.project.getPaths()[0]
|
2017-03-03 02:12:12 +03:00
|
|
|
file1 = path.join(dir1, 'a-dir', 'oh-git')
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
dir2 = temp.mkdirSync('a-second-dir')
|
|
|
|
const aDir2 = path.join(dir2, 'a-dir')
|
|
|
|
file2 = path.join(aDir2, 'a-file')
|
|
|
|
fs.mkdirSync(aDir2)
|
|
|
|
fs.writeFileSync(file2, 'ccc aaaa')
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.project.addPath(dir2)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it("searches matching files in all of the project's root directories", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const resultPaths = []
|
2017-03-03 01:31:20 +03:00
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.scan(/aaaa/, ({filePath}) => resultPaths.push(filePath))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(resultPaths.sort()).toEqual([file1, file2].sort()))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when an inclusion path starts with the basename of a root directory', () => {
|
|
|
|
it('interprets the inclusion path as starting from that directory', () => {
|
|
|
|
waitsForPromise(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const resultPaths = []
|
2017-03-03 01:31:20 +03:00
|
|
|
return atom.workspace
|
2017-03-03 02:40:57 +03:00
|
|
|
.scan(/aaaa/, {paths: ['dir']}, ({filePath}) => {
|
|
|
|
if (!resultPaths.includes(filePath)) {
|
|
|
|
resultPaths.push(filePath)
|
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
.then(() => expect(resultPaths).toEqual([file1]))
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const resultPaths = []
|
2017-03-03 01:31:20 +03:00
|
|
|
return atom.workspace
|
2017-03-03 02:40:57 +03:00
|
|
|
.scan(/aaaa/, {paths: [path.join('dir', 'a-dir')]}, ({filePath}) => {
|
|
|
|
if (!resultPaths.includes(filePath)) {
|
|
|
|
resultPaths.push(filePath)
|
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
.then(() => expect(resultPaths).toEqual([file1]))
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const resultPaths = []
|
2017-03-03 01:31:20 +03:00
|
|
|
return atom.workspace
|
2017-03-03 02:40:57 +03:00
|
|
|
.scan(/aaaa/, {paths: [path.basename(dir2)]}, ({filePath}) => {
|
|
|
|
if (!resultPaths.includes(filePath)) {
|
|
|
|
resultPaths.push(filePath)
|
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
.then(() => expect(resultPaths).toEqual([file2]))
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const resultPaths = []
|
2017-03-03 01:31:20 +03:00
|
|
|
return atom.workspace
|
2017-03-03 02:40:57 +03:00
|
|
|
.scan(/aaaa/, {paths: [path.join(path.basename(dir2), 'a-dir')]}, ({filePath}) => {
|
|
|
|
if (!resultPaths.includes(filePath)) {
|
|
|
|
resultPaths.push(filePath)
|
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
.then(() => expect(resultPaths).toEqual([file2]))
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when a custom directory searcher is registered', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let fakeSearch = null
|
2017-03-03 01:31:20 +03:00
|
|
|
// Function that is invoked once all of the fields on fakeSearch are set.
|
2017-03-03 02:12:12 +03:00
|
|
|
let onFakeSearchCreated = null
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
class FakeSearch {
|
2017-03-03 02:12:12 +03:00
|
|
|
constructor (options) {
|
2017-03-03 01:31:20 +03:00
|
|
|
// Note that hoisting resolve and reject in this way is generally frowned upon.
|
2017-03-03 02:12:12 +03:00
|
|
|
this.options = options
|
2017-03-03 02:40:57 +03:00
|
|
|
this.promise = new Promise((resolve, reject) => {
|
2017-03-03 02:12:12 +03:00
|
|
|
this.hoistedResolve = resolve
|
|
|
|
this.hoistedReject = reject
|
2017-03-03 02:40:57 +03:00
|
|
|
if (typeof onFakeSearchCreated === 'function') {
|
|
|
|
onFakeSearchCreated(this)
|
|
|
|
}
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
then (...args) {
|
|
|
|
return this.promise.then.apply(this.promise, args)
|
2017-03-03 01:31:20 +03:00
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
cancel () {
|
|
|
|
this.cancelled = true
|
2017-03-03 01:31:20 +03:00
|
|
|
// According to the spec for a DirectorySearcher, invoking `cancel()` should
|
|
|
|
// resolve the thenable rather than reject it.
|
2017-03-03 02:40:57 +03:00
|
|
|
this.hoistedResolve()
|
2017-03-03 01:31:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
beforeEach(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
fakeSearch = null
|
|
|
|
onFakeSearchCreated = null
|
2017-03-03 01:31:20 +03:00
|
|
|
atom.packages.serviceHub.provide('atom.directory-searcher', '0.1.0', {
|
2017-03-03 02:12:12 +03:00
|
|
|
canSearchDirectory (directory) { return directory.getPath() === dir1 },
|
2017-03-03 02:40:57 +03:00
|
|
|
search (directory, regex, options) {
|
|
|
|
fakeSearch = new FakeSearch(options)
|
|
|
|
return fakeSearch
|
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsFor(() => atom.workspace.directorySearchers.length > 0)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('can override the DefaultDirectorySearcher on a per-directory basis', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const foreignFilePath = 'ssh://foreign-directory:8080/hello.txt'
|
|
|
|
const numPathsSearchedInDir2 = 1
|
|
|
|
const numPathsToPretendToSearchInCustomDirectorySearcher = 10
|
2017-03-03 01:31:20 +03:00
|
|
|
const searchResult = {
|
|
|
|
filePath: foreignFilePath,
|
|
|
|
matches: [
|
|
|
|
{
|
|
|
|
lineText: 'Hello world',
|
|
|
|
lineTextOffset: 0,
|
|
|
|
matchText: 'Hello',
|
2017-03-03 02:12:12 +03:00
|
|
|
range: [[0, 0], [0, 5]]
|
|
|
|
}
|
2017-03-03 01:31:20 +03:00
|
|
|
]
|
2017-03-03 02:12:12 +03:00
|
|
|
}
|
2017-03-03 02:40:57 +03:00
|
|
|
onFakeSearchCreated = fakeSearch => {
|
2017-03-03 02:12:12 +03:00
|
|
|
fakeSearch.options.didMatch(searchResult)
|
|
|
|
fakeSearch.options.didSearchPaths(numPathsToPretendToSearchInCustomDirectorySearcher)
|
2017-03-03 02:40:57 +03:00
|
|
|
fakeSearch.hoistedResolve()
|
2017-03-03 02:12:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const resultPaths = []
|
|
|
|
const onPathsSearched = jasmine.createSpy('onPathsSearched')
|
2017-03-03 01:31:20 +03:00
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.scan(/aaaa/, {onPathsSearched}, ({filePath}) => resultPaths.push(filePath))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(resultPaths.sort()).toEqual([foreignFilePath, file2].sort())
|
2017-03-03 01:31:20 +03:00
|
|
|
// 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.
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(onPathsSearched.callCount).toBe(2)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(onPathsSearched.mostRecentCall.args[0]).toBe(
|
2017-03-03 02:12:12 +03:00
|
|
|
numPathsToPretendToSearchInCustomDirectorySearcher + numPathsSearchedInDir2)
|
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('can be cancelled when the object returned by scan() has its cancel() method invoked', () => {
|
|
|
|
const thenable = atom.workspace.scan(/aaaa/, () => {})
|
2017-03-03 02:12:12 +03:00
|
|
|
let resultOfPromiseSearch = null
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsFor('fakeSearch to be defined', () => fakeSearch != null)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(fakeSearch.cancelled).toBe(undefined)
|
|
|
|
thenable.cancel()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(fakeSearch.cancelled).toBe(true)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => thenable.then(promiseResult => { resultOfPromiseSearch = promiseResult }))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(resultOfPromiseSearch).toBe('cancelled'))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('will have the side-effect of failing the overall search if it fails', () => {
|
2017-03-03 01:31:20 +03:00
|
|
|
// This provider's search should be cancelled when the first provider fails
|
2017-03-03 02:12:12 +03:00
|
|
|
let cancelableSearch
|
|
|
|
let fakeSearch2 = null
|
2017-03-03 01:31:20 +03:00
|
|
|
atom.packages.serviceHub.provide('atom.directory-searcher', '0.1.0', {
|
2017-03-03 02:12:12 +03:00
|
|
|
canSearchDirectory (directory) { return directory.getPath() === dir2 },
|
2017-03-03 02:40:57 +03:00
|
|
|
search (directory, regex, options) {
|
|
|
|
fakeSearch2 = new FakeSearch(options)
|
|
|
|
return fakeSearch2
|
|
|
|
}
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
let didReject = false
|
2017-03-03 02:40:57 +03:00
|
|
|
const promise = cancelableSearch = atom.workspace.scan(/aaaa/, () => {})
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsFor('fakeSearch to be defined', () => fakeSearch != null)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
runs(() => fakeSearch.hoistedReject())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => cancelableSearch.catch(() => { didReject = true }))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsFor(done => promise.then(null, done))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(didReject).toBe(true)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(fakeSearch2.cancelled).toBe(true)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
}) // Cancels other ongoing searches
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::replace(regex, replacementText, paths, iterator)', () => {
|
|
|
|
let filePath
|
|
|
|
let commentFilePath
|
|
|
|
let sampleContent
|
|
|
|
let sampleCommentContent
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
beforeEach(() => {
|
|
|
|
atom.project.setPaths([atom.project.getDirectories()[0].resolve('../')])
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
filePath = atom.project.getDirectories()[0].resolve('sample.js')
|
|
|
|
commentFilePath = atom.project.getDirectories()[0].resolve('sample-with-comments.js')
|
2017-03-03 02:12:12 +03:00
|
|
|
sampleContent = fs.readFileSync(filePath).toString()
|
2017-03-03 02:40:57 +03:00
|
|
|
sampleCommentContent = fs.readFileSync(commentFilePath).toString()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
afterEach(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
fs.writeFileSync(filePath, sampleContent)
|
2017-03-03 02:40:57 +03:00
|
|
|
fs.writeFileSync(commentFilePath, sampleCommentContent)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe("when a file doesn't exist", () => {
|
|
|
|
it('calls back with an error', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const errors = []
|
|
|
|
const missingPath = path.resolve('/not-a-file.js')
|
|
|
|
expect(fs.existsSync(missingPath)).toBeFalsy()
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.replace(/items/gi, 'items', [missingPath], (result, error) => errors.push(error))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(errors).toHaveLength(1)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(errors[0].path).toBe(missingPath)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when called with unopened files', () => {
|
|
|
|
it('replaces properly', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const results = []
|
2017-03-03 01:31:20 +03:00
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.replace(/items/gi, 'items', [filePath], result => results.push(result))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(results).toHaveLength(1)
|
|
|
|
expect(results[0].filePath).toBe(filePath)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(results[0].replacements).toBe(6)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when a buffer is already open', () => {
|
|
|
|
it('replaces properly and saves when not modified', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
const results = []
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => atom.workspace.open('sample.js').then(o => { editor = o }))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
runs(() => expect(editor.isModified()).toBeFalsy())
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.replace(/items/gi, 'items', [filePath], result => results.push(result))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(results).toHaveLength(1)
|
|
|
|
expect(results[0].filePath).toBe(filePath)
|
|
|
|
expect(results[0].replacements).toBe(6)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(editor.isModified()).toBeFalsy()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('does not replace when the path is not specified', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const results = []
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.workspace.open('sample-with-comments.js'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.replace(/items/gi, 'items', [commentFilePath], result => results.push(result))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(results).toHaveLength(1)
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(results[0].filePath).toBe(commentFilePath)
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('does NOT save when modified', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
|
|
|
const results = []
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => atom.workspace.open('sample.js').then(o => { editor = o }))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
editor.buffer.setTextInRange([[0, 0], [0, 0]], 'omg')
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(editor.isModified()).toBeTruthy()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
|
|
|
atom.workspace.replace(/items/gi, 'okthen', [filePath], result => results.push(result))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(results).toHaveLength(1)
|
|
|
|
expect(results[0].filePath).toBe(filePath)
|
|
|
|
expect(results[0].replacements).toBe(6)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(editor.isModified()).toBeTruthy()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-18 04:09:06 +03:00
|
|
|
describe('::saveFocusedPaneItem', () => {
|
|
|
|
let editor, workspaceElement
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
workspaceElement = atom.views.getView(atom.workspace)
|
|
|
|
document.body.appendChild(workspaceElement)
|
|
|
|
waitsForPromise(() => atom.workspace.open('a').then(o => { editor = o }))
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
workspaceElement.remove()
|
|
|
|
})
|
|
|
|
|
|
|
|
it("calls the focused item's save method", () => {
|
|
|
|
spyOn(editor, 'save')
|
|
|
|
editor.getElement().focus()
|
|
|
|
atom.workspace.saveFocusedPaneItem()
|
|
|
|
expect(editor.save).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
it("doesn't save the active editor if it's not focused", () => {
|
|
|
|
spyOn(editor, 'save')
|
|
|
|
const input = document.createElement('input')
|
|
|
|
document.body.appendChild(input)
|
|
|
|
input.focus()
|
|
|
|
expect(document.activeElement).toBe(input)
|
|
|
|
atom.workspace.saveFocusedPaneItem()
|
|
|
|
expect(editor.save).not.toHaveBeenCalled()
|
|
|
|
input.remove()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::saveActivePaneItem()', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
2017-03-03 01:31:20 +03:00
|
|
|
beforeEach(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => atom.workspace.open('sample.js').then(o => { editor = o }))
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when there is an error', () => {
|
|
|
|
it('emits a warning notification when the file cannot be saved', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addedSpy
|
2017-03-03 02:40:57 +03:00
|
|
|
spyOn(editor, 'save').andCallFake(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
throw new Error("'/some/file' is a directory")
|
|
|
|
})
|
|
|
|
|
|
|
|
atom.notifications.onDidAddNotification(addedSpy = jasmine.createSpy())
|
|
|
|
atom.workspace.saveActivePaneItem()
|
|
|
|
expect(addedSpy).toHaveBeenCalled()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(addedSpy.mostRecentCall.args[0].getType()).toBe('warning')
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('emits a warning notification when the directory cannot be written to', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addedSpy
|
2017-03-03 02:40:57 +03:00
|
|
|
spyOn(editor, 'save').andCallFake(() => {
|
2017-03-03 02:12:12 +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()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(addedSpy.mostRecentCall.args[0].getType()).toBe('warning')
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('emits a warning notification when the user does not have permission', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addedSpy
|
2017-03-03 02:40:57 +03:00
|
|
|
spyOn(editor, 'save').andCallFake(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const 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()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(addedSpy.mostRecentCall.args[0].getType()).toBe('warning')
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('emits a warning notification when the operation is not permitted', () => {
|
|
|
|
spyOn(editor, 'save').andCallFake(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const 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
|
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('emits a warning notification when the file is already open by another app', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addedSpy
|
2017-03-03 02:40:57 +03:00
|
|
|
spyOn(editor, 'save').andCallFake(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const 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
|
|
|
|
})
|
|
|
|
|
|
|
|
atom.notifications.onDidAddNotification(addedSpy = jasmine.createSpy())
|
|
|
|
atom.workspace.saveActivePaneItem()
|
|
|
|
expect(addedSpy).toHaveBeenCalled()
|
|
|
|
|
|
|
|
const notificaiton = addedSpy.mostRecentCall.args[0]
|
|
|
|
expect(notificaiton.getType()).toBe('warning')
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(notificaiton.getMessage()).toContain('Unable to save')
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('emits a warning notification when the file system is read-only', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let addedSpy
|
2017-03-03 02:40:57 +03:00
|
|
|
spyOn(editor, 'save').andCallFake(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
const 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
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
|
|
|
|
atom.notifications.onDidAddNotification(addedSpy = jasmine.createSpy())
|
|
|
|
atom.workspace.saveActivePaneItem()
|
|
|
|
expect(addedSpy).toHaveBeenCalled()
|
|
|
|
|
|
|
|
const notification = addedSpy.mostRecentCall.args[0]
|
|
|
|
expect(notification.getType()).toBe('warning')
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(notification.getMessage()).toContain('Unable to save')
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('emits a warning notification when the file cannot be saved', () => {
|
|
|
|
spyOn(editor, 'save').andCallFake(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
throw new Error('no one knows')
|
|
|
|
})
|
|
|
|
|
|
|
|
const save = () => atom.workspace.saveActivePaneItem()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(save).toThrow()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('::closeActivePaneItemOrEmptyPaneOrWindow', () => {
|
|
|
|
beforeEach(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
spyOn(atom, 'close')
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => atom.workspace.open())
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('closes the active pane item, or the active pane if it is empty, or the current window if there is only the empty root pane', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.config.set('core.destroyEmptyPanes', false)
|
|
|
|
|
|
|
|
const pane1 = atom.workspace.getActivePane()
|
|
|
|
const pane2 = pane1.splitRight({copyActiveItem: true})
|
|
|
|
|
2017-03-16 00:46:03 +03:00
|
|
|
expect(atom.workspace.getCenter().getPanes().length).toBe(2)
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(pane2.getItems().length).toBe(1)
|
|
|
|
atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow()
|
|
|
|
|
2017-03-16 00:46:03 +03:00
|
|
|
expect(atom.workspace.getCenter().getPanes().length).toBe(2)
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(pane2.getItems().length).toBe(0)
|
|
|
|
|
|
|
|
atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow()
|
|
|
|
|
2017-03-16 00:46:03 +03:00
|
|
|
expect(atom.workspace.getCenter().getPanes().length).toBe(1)
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(pane1.getItems().length).toBe(1)
|
|
|
|
|
|
|
|
atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow()
|
2017-03-16 00:46:03 +03:00
|
|
|
expect(atom.workspace.getCenter().getPanes().length).toBe(1)
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(pane1.getItems().length).toBe(0)
|
|
|
|
|
|
|
|
atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow()
|
2017-03-16 00:46:03 +03:00
|
|
|
expect(atom.workspace.getCenter().getPanes().length).toBe(1)
|
2017-03-03 02:12:12 +03:00
|
|
|
|
|
|
|
atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow()
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(atom.close).toHaveBeenCalled()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('when the core.allowPendingPaneItems option is falsey', () => {
|
|
|
|
it('does not open item with `pending: true` option as pending', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let pane = null
|
|
|
|
atom.config.set('core.allowPendingPaneItems', false)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
waitsForPromise(() =>
|
2017-03-03 02:40:57 +03:00
|
|
|
atom.workspace.open('sample.js', {pending: true}).then(() => {
|
|
|
|
pane = atom.workspace.getActivePane()
|
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(pane.getPendingItem()).toBeFalsy())
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('grammar activation', () => {
|
|
|
|
it('notifies the workspace of which grammar is used', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.packages.triggerDeferredActivationHooks()
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
const javascriptGrammarUsed = jasmine.createSpy('js grammar used')
|
|
|
|
const rubyGrammarUsed = jasmine.createSpy('ruby grammar used')
|
|
|
|
const cGrammarUsed = jasmine.createSpy('c grammar used')
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.packages.onDidTriggerActivationHook('language-javascript:grammar-used', javascriptGrammarUsed)
|
|
|
|
atom.packages.onDidTriggerActivationHook('language-ruby:grammar-used', rubyGrammarUsed)
|
|
|
|
atom.packages.onDidTriggerActivationHook('language-c:grammar-used', cGrammarUsed)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.packages.activatePackage('language-ruby'))
|
|
|
|
waitsForPromise(() => atom.packages.activatePackage('language-javascript'))
|
|
|
|
waitsForPromise(() => atom.packages.activatePackage('language-c'))
|
|
|
|
waitsForPromise(() => atom.workspace.open('sample-with-comments.js'))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => {
|
2017-03-03 01:31:20 +03:00
|
|
|
// Hooks are triggered when opening new editors
|
2017-03-03 02:12:12 +03:00
|
|
|
expect(javascriptGrammarUsed).toHaveBeenCalled()
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
// Hooks are triggered when changing existing editors grammars
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.workspace.getActiveTextEditor().setGrammar(atom.grammars.grammarForScopeName('source.c'))
|
|
|
|
expect(cGrammarUsed).toHaveBeenCalled()
|
2017-03-03 01:31:20 +03:00
|
|
|
|
|
|
|
// Hooks are triggered when editors are added in other ways.
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.workspace.getActivePane().splitRight({copyActiveItem: true})
|
|
|
|
atom.workspace.getActiveTextEditor().setGrammar(atom.grammars.grammarForScopeName('source.ruby'))
|
2017-03-03 02:40:57 +03:00
|
|
|
expect(rubyGrammarUsed).toHaveBeenCalled()
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe('.checkoutHeadRevision()', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
let editor = null
|
2017-03-03 02:40:57 +03:00
|
|
|
beforeEach(() => {
|
2017-03-03 02:12:12 +03:00
|
|
|
atom.config.set('editor.confirmCheckoutHeadRevision', false)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => atom.workspace.open('sample-with-comments.js').then(o => { editor = o }))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
it('reverts to the version of its file checked into the project repository', () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
editor.setCursorBufferPosition([0, 0])
|
|
|
|
editor.insertText('---\n')
|
|
|
|
expect(editor.lineTextForBufferRow(0)).toBe('---')
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:12:12 +03:00
|
|
|
waitsForPromise(() => atom.workspace.checkoutHeadRevision(editor))
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
runs(() => expect(editor.lineTextForBufferRow(0)).toBe(''))
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
describe("when there's no repository for the editor's file", () => {
|
|
|
|
it("doesn't do anything", () => {
|
2017-03-03 02:12:12 +03:00
|
|
|
editor = new TextEditor()
|
|
|
|
editor.setText('stuff')
|
|
|
|
atom.workspace.checkoutHeadRevision(editor)
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
waitsForPromise(() => atom.workspace.checkoutHeadRevision(editor))
|
2017-03-03 01:31:20 +03:00
|
|
|
})
|
2017-03-03 02:40:57 +03:00
|
|
|
})
|
2017-03-03 02:12:12 +03:00
|
|
|
})
|
|
|
|
})
|
2017-03-03 01:31:20 +03:00
|
|
|
|
2017-03-03 02:40:57 +03:00
|
|
|
const escapeStringRegex = str => str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
|