mirror of
https://github.com/atom/atom.git
synced 2026-02-16 09:35:54 -05:00
Merge branch 'master' into wl-build-on-node-7
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
/** @babel */
|
||||
|
||||
import until from 'test-until'
|
||||
|
||||
export function beforeEach (fn) {
|
||||
global.beforeEach(function () {
|
||||
const result = fn()
|
||||
@@ -60,3 +62,9 @@ function waitsForPromise (fn) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function emitterEventPromise (emitter, event, timeout = 5000) {
|
||||
let emitted = false
|
||||
emitter.once(event, () => { emitted = true })
|
||||
return until(`${event} is emitted`, () => emitted, timeout)
|
||||
}
|
||||
|
||||
@@ -321,14 +321,6 @@ describe "AtomEnvironment", ->
|
||||
expect(atom.workspace.open).not.toHaveBeenCalled()
|
||||
|
||||
describe "adding a project folder", ->
|
||||
it "adds a second path to the project", ->
|
||||
initialPaths = atom.project.getPaths()
|
||||
tempDirectory = temp.mkdirSync("a-new-directory")
|
||||
spyOn(atom, "pickFolder").andCallFake (callback) ->
|
||||
callback([tempDirectory])
|
||||
atom.addProjectFolder()
|
||||
expect(atom.project.getPaths()).toEqual(initialPaths.concat([tempDirectory]))
|
||||
|
||||
it "does nothing if the user dismisses the file picker", ->
|
||||
initialPaths = atom.project.getPaths()
|
||||
tempDirectory = temp.mkdirSync("a-new-directory")
|
||||
@@ -336,6 +328,106 @@ describe "AtomEnvironment", ->
|
||||
atom.addProjectFolder()
|
||||
expect(atom.project.getPaths()).toEqual(initialPaths)
|
||||
|
||||
describe "when there is no saved state for the added folders", ->
|
||||
beforeEach ->
|
||||
spyOn(atom, 'loadState').andReturn(Promise.resolve(null))
|
||||
spyOn(atom, 'attemptRestoreProjectStateForPaths')
|
||||
|
||||
it "adds the selected folder to the project", ->
|
||||
initialPaths = atom.project.setPaths([])
|
||||
tempDirectory = temp.mkdirSync("a-new-directory")
|
||||
spyOn(atom, "pickFolder").andCallFake (callback) ->
|
||||
callback([tempDirectory])
|
||||
waitsForPromise ->
|
||||
atom.addProjectFolder()
|
||||
runs ->
|
||||
expect(atom.project.getPaths()).toEqual([tempDirectory])
|
||||
expect(atom.attemptRestoreProjectStateForPaths).not.toHaveBeenCalled()
|
||||
|
||||
describe "when there is saved state for the relevant directories", ->
|
||||
state = Symbol('savedState')
|
||||
|
||||
beforeEach ->
|
||||
spyOn(atom, "getStateKey").andCallFake (dirs) -> dirs.join(':')
|
||||
spyOn(atom, "loadState").andCallFake (key) ->
|
||||
if key is __dirname then Promise.resolve(state) else Promise.resolve(null)
|
||||
spyOn(atom, "attemptRestoreProjectStateForPaths")
|
||||
spyOn(atom, "pickFolder").andCallFake (callback) ->
|
||||
callback([__dirname])
|
||||
atom.project.setPaths([])
|
||||
|
||||
describe "when there are no project folders", ->
|
||||
it "attempts to restore the project state", ->
|
||||
waitsForPromise ->
|
||||
atom.addProjectFolder()
|
||||
runs ->
|
||||
expect(atom.attemptRestoreProjectStateForPaths).toHaveBeenCalledWith(state, [__dirname])
|
||||
expect(atom.project.getPaths()).toEqual([])
|
||||
|
||||
describe "when there are already project folders", ->
|
||||
openedPath = path.join(__dirname, 'fixtures')
|
||||
beforeEach ->
|
||||
atom.project.setPaths([openedPath])
|
||||
|
||||
it "does not attempt to restore the project state, instead adding the project paths", ->
|
||||
waitsForPromise ->
|
||||
atom.addProjectFolder()
|
||||
runs ->
|
||||
expect(atom.attemptRestoreProjectStateForPaths).not.toHaveBeenCalled()
|
||||
expect(atom.project.getPaths()).toEqual([openedPath, __dirname])
|
||||
|
||||
describe "attemptRestoreProjectStateForPaths(state, projectPaths, filesToOpen)", ->
|
||||
describe "when the window is clean (empty or has only unnamed, unmodified buffers)", ->
|
||||
beforeEach ->
|
||||
# Unnamed, unmodified buffer doesn't count toward "clean"-ness
|
||||
waitsForPromise -> atom.workspace.open()
|
||||
|
||||
it "automatically restores the saved state into the current environment", ->
|
||||
state = Symbol()
|
||||
spyOn(atom.workspace, 'open')
|
||||
spyOn(atom, 'restoreStateIntoThisEnvironment')
|
||||
|
||||
atom.attemptRestoreProjectStateForPaths(state, [__dirname], [__filename])
|
||||
expect(atom.restoreStateIntoThisEnvironment).toHaveBeenCalledWith(state)
|
||||
expect(atom.workspace.open.callCount).toBe(1)
|
||||
expect(atom.workspace.open).toHaveBeenCalledWith(__filename)
|
||||
|
||||
describe "when the window is dirty", ->
|
||||
editor = null
|
||||
|
||||
beforeEach ->
|
||||
waitsForPromise -> atom.workspace.open().then (e) ->
|
||||
editor = e
|
||||
editor.setText('new editor')
|
||||
|
||||
it "prompts the user to restore the state in a new window, discarding it and adding folder to current window", ->
|
||||
spyOn(atom, "confirm").andReturn(1)
|
||||
spyOn(atom.project, 'addPath')
|
||||
spyOn(atom.workspace, 'open')
|
||||
state = Symbol()
|
||||
|
||||
atom.attemptRestoreProjectStateForPaths(state, [__dirname], [__filename])
|
||||
expect(atom.confirm).toHaveBeenCalled()
|
||||
expect(atom.project.addPath.callCount).toBe(1)
|
||||
expect(atom.project.addPath).toHaveBeenCalledWith(__dirname)
|
||||
expect(atom.workspace.open.callCount).toBe(1)
|
||||
expect(atom.workspace.open).toHaveBeenCalledWith(__filename)
|
||||
|
||||
it "prompts the user to restore the state in a new window, opening a new window", ->
|
||||
spyOn(atom, "confirm").andReturn(0)
|
||||
spyOn(atom, "open")
|
||||
state = Symbol()
|
||||
|
||||
atom.attemptRestoreProjectStateForPaths(state, [__dirname], [__filename])
|
||||
expect(atom.confirm).toHaveBeenCalled()
|
||||
expect(atom.open).toHaveBeenCalledWith
|
||||
pathsToOpen: [__dirname, __filename]
|
||||
newWindow: true
|
||||
devMode: atom.inDevMode()
|
||||
safeMode: atom.inSafeMode()
|
||||
|
||||
|
||||
|
||||
describe "::unloadEditorWindow()", ->
|
||||
it "saves the BlobStore so it can be loaded after reload", ->
|
||||
configDirPath = temp.mkdirSync('atom-spec-environment')
|
||||
@@ -371,44 +463,91 @@ describe "AtomEnvironment", ->
|
||||
spyOn(atom.workspace, 'open')
|
||||
atom.project.setPaths([])
|
||||
|
||||
describe "when the opened path exists", ->
|
||||
it "adds it to the project's paths", ->
|
||||
pathToOpen = __filename
|
||||
atom.openLocations([{pathToOpen}])
|
||||
expect(atom.project.getPaths()[0]).toBe __dirname
|
||||
describe "when there is no saved state", ->
|
||||
beforeEach ->
|
||||
spyOn(atom, "loadState").andReturn(Promise.resolve(null))
|
||||
|
||||
describe "then a second path is opened with forceAddToWindow", ->
|
||||
it "adds the second path to the project's paths", ->
|
||||
firstPathToOpen = __dirname
|
||||
secondPathToOpen = path.resolve(__dirname, './fixtures')
|
||||
atom.openLocations([{pathToOpen: firstPathToOpen}])
|
||||
atom.openLocations([{pathToOpen: secondPathToOpen, forceAddToWindow: true}])
|
||||
expect(atom.project.getPaths()).toEqual([firstPathToOpen, secondPathToOpen])
|
||||
describe "when the opened path exists", ->
|
||||
it "adds it to the project's paths", ->
|
||||
pathToOpen = __filename
|
||||
waitsForPromise -> atom.openLocations([{pathToOpen}])
|
||||
runs -> expect(atom.project.getPaths()[0]).toBe __dirname
|
||||
|
||||
describe "when the opened path does not exist but its parent directory does", ->
|
||||
it "adds the parent directory to the project paths", ->
|
||||
pathToOpen = path.join(__dirname, 'this-path-does-not-exist.txt')
|
||||
atom.openLocations([{pathToOpen}])
|
||||
expect(atom.project.getPaths()[0]).toBe __dirname
|
||||
describe "then a second path is opened with forceAddToWindow", ->
|
||||
it "adds the second path to the project's paths", ->
|
||||
firstPathToOpen = __dirname
|
||||
secondPathToOpen = path.resolve(__dirname, './fixtures')
|
||||
waitsForPromise -> atom.openLocations([{pathToOpen: firstPathToOpen}])
|
||||
waitsForPromise -> atom.openLocations([{pathToOpen: secondPathToOpen, forceAddToWindow: true}])
|
||||
runs -> expect(atom.project.getPaths()).toEqual([firstPathToOpen, secondPathToOpen])
|
||||
|
||||
describe "when the opened path is a file", ->
|
||||
it "opens it in the workspace", ->
|
||||
pathToOpen = __filename
|
||||
atom.openLocations([{pathToOpen}])
|
||||
expect(atom.workspace.open.mostRecentCall.args[0]).toBe __filename
|
||||
describe "when the opened path does not exist but its parent directory does", ->
|
||||
it "adds the parent directory to the project paths", ->
|
||||
pathToOpen = path.join(__dirname, 'this-path-does-not-exist.txt')
|
||||
waitsForPromise -> atom.openLocations([{pathToOpen}])
|
||||
runs -> expect(atom.project.getPaths()[0]).toBe __dirname
|
||||
|
||||
describe "when the opened path is a directory", ->
|
||||
it "does not open it in the workspace", ->
|
||||
pathToOpen = __dirname
|
||||
atom.openLocations([{pathToOpen}])
|
||||
expect(atom.workspace.open.callCount).toBe 0
|
||||
describe "when the opened path is a file", ->
|
||||
it "opens it in the workspace", ->
|
||||
pathToOpen = __filename
|
||||
waitsForPromise -> atom.openLocations([{pathToOpen}])
|
||||
runs -> expect(atom.workspace.open.mostRecentCall.args[0]).toBe __filename
|
||||
|
||||
describe "when the opened path is a uri", ->
|
||||
it "adds it to the project's paths as is", ->
|
||||
pathToOpen = 'remote://server:7644/some/dir/path'
|
||||
spyOn(atom.project, 'addPath')
|
||||
atom.openLocations([{pathToOpen}])
|
||||
expect(atom.project.addPath).toHaveBeenCalledWith(pathToOpen)
|
||||
describe "when the opened path is a directory", ->
|
||||
it "does not open it in the workspace", ->
|
||||
pathToOpen = __dirname
|
||||
waitsForPromise -> atom.openLocations([{pathToOpen}])
|
||||
runs -> expect(atom.workspace.open.callCount).toBe 0
|
||||
|
||||
describe "when the opened path is a uri", ->
|
||||
it "adds it to the project's paths as is", ->
|
||||
pathToOpen = 'remote://server:7644/some/dir/path'
|
||||
spyOn(atom.project, 'addPath')
|
||||
waitsForPromise -> atom.openLocations([{pathToOpen}])
|
||||
runs -> expect(atom.project.addPath).toHaveBeenCalledWith(pathToOpen)
|
||||
|
||||
describe "when there is saved state for the relevant directories", ->
|
||||
state = Symbol('savedState')
|
||||
|
||||
beforeEach ->
|
||||
spyOn(atom, "getStateKey").andCallFake (dirs) -> dirs.join(':')
|
||||
spyOn(atom, "loadState").andCallFake (key) ->
|
||||
if key is __dirname then Promise.resolve(state) else Promise.resolve(null)
|
||||
spyOn(atom, "attemptRestoreProjectStateForPaths")
|
||||
|
||||
describe "when there are no project folders", ->
|
||||
it "attempts to restore the project state", ->
|
||||
pathToOpen = __dirname
|
||||
waitsForPromise -> atom.openLocations([{pathToOpen}])
|
||||
runs ->
|
||||
expect(atom.attemptRestoreProjectStateForPaths).toHaveBeenCalledWith(state, [pathToOpen], [])
|
||||
expect(atom.project.getPaths()).toEqual([])
|
||||
|
||||
it "opens the specified files", ->
|
||||
waitsForPromise -> atom.openLocations([{pathToOpen: __dirname}, {pathToOpen: __filename}])
|
||||
runs ->
|
||||
expect(atom.attemptRestoreProjectStateForPaths).toHaveBeenCalledWith(state, [__dirname], [__filename])
|
||||
expect(atom.project.getPaths()).toEqual([])
|
||||
|
||||
|
||||
describe "when there are already project folders", ->
|
||||
beforeEach ->
|
||||
atom.project.setPaths([__dirname])
|
||||
|
||||
it "does not attempt to restore the project state, instead adding the project paths", ->
|
||||
pathToOpen = path.join(__dirname, 'fixtures')
|
||||
waitsForPromise -> atom.openLocations([{pathToOpen, forceAddToWindow: true}])
|
||||
runs ->
|
||||
expect(atom.attemptRestoreProjectStateForPaths).not.toHaveBeenCalled()
|
||||
expect(atom.project.getPaths()).toEqual([__dirname, pathToOpen])
|
||||
|
||||
it "opens the specified files", ->
|
||||
pathToOpen = path.join(__dirname, 'fixtures')
|
||||
fileToOpen = path.join(pathToOpen, 'michelle-is-awesome.txt')
|
||||
waitsForPromise -> atom.openLocations([{pathToOpen}, {pathToOpen: fileToOpen}])
|
||||
runs ->
|
||||
expect(atom.attemptRestoreProjectStateForPaths).not.toHaveBeenCalledWith(state, [pathToOpen], [fileToOpen])
|
||||
expect(atom.project.getPaths()).toEqual([__dirname])
|
||||
|
||||
describe "::updateAvailable(info) (called via IPC from browser process)", ->
|
||||
subscription = null
|
||||
|
||||
@@ -7,7 +7,7 @@ import fs from 'fs-plus'
|
||||
import path from 'path'
|
||||
import AtomApplication from '../../src/main-process/atom-application'
|
||||
import parseCommandLine from '../../src/main-process/parse-command-line'
|
||||
import {timeoutPromise, conditionPromise} from '../async-spec-helpers'
|
||||
import {timeoutPromise, conditionPromise, emitterEventPromise} from '../async-spec-helpers'
|
||||
|
||||
const ATOM_RESOURCE_PATH = path.resolve(__dirname, '..', '..')
|
||||
|
||||
@@ -121,6 +121,7 @@ describe('AtomApplication', function () {
|
||||
|
||||
const atomApplication = buildAtomApplication()
|
||||
const window1 = atomApplication.launch(parseCommandLine([path.join(dirAPath, 'new-file')]))
|
||||
await emitterEventPromise(window1, 'window:locations-opened')
|
||||
await focusWindow(window1)
|
||||
|
||||
let activeEditorPath
|
||||
@@ -146,6 +147,7 @@ describe('AtomApplication', function () {
|
||||
|
||||
// Opens new windows when opening directories
|
||||
const window2 = atomApplication.launch(parseCommandLine([dirCPath]))
|
||||
await emitterEventPromise(window2, 'window:locations-opened')
|
||||
assert.notEqual(window2, window1)
|
||||
await focusWindow(window2)
|
||||
assert.deepEqual(await getTreeViewRootDirectories(window2), [dirCPath])
|
||||
@@ -365,6 +367,9 @@ describe('AtomApplication', function () {
|
||||
|
||||
const atomApplication2 = buildAtomApplication()
|
||||
const [app2Window1, app2Window2] = atomApplication2.launch(parseCommandLine([]))
|
||||
const p1 = emitterEventPromise(app2Window1, 'window:locations-opened', 15000)
|
||||
const p2 = emitterEventPromise(app2Window2, 'window:locations-opened', 15000)
|
||||
await Promise.all([p1, p2])
|
||||
await app2Window1.loadedPromise
|
||||
await app2Window2.loadedPromise
|
||||
|
||||
@@ -420,6 +425,7 @@ describe('AtomApplication', function () {
|
||||
|
||||
const atomApplication = buildAtomApplication()
|
||||
const window = atomApplication.launch(parseCommandLine([dirA, dirB]))
|
||||
await emitterEventPromise(window, 'window:locations-opened', 15000)
|
||||
await focusWindow(window)
|
||||
assert.deepEqual(await getTreeViewRootDirectories(window), [dirA, dirB])
|
||||
|
||||
|
||||
@@ -7,12 +7,13 @@ buildPane = ->
|
||||
applicationDelegate: atom.applicationDelegate,
|
||||
config: atom.config,
|
||||
deserializerManager: atom.deserializers,
|
||||
notificationManager: atom.notifications
|
||||
notificationManager: atom.notifications,
|
||||
viewRegistry: atom.views
|
||||
})
|
||||
|
||||
describe "PaneAxisElement", ->
|
||||
it "correctly subscribes and unsubscribes to the underlying model events on attach/detach", ->
|
||||
container = new PaneContainer(config: atom.config, applicationDelegate: atom.applicationDelegate)
|
||||
container = new PaneContainer(config: atom.config, applicationDelegate: atom.applicationDelegate, viewRegistry: atom.views)
|
||||
axis = new PaneAxis
|
||||
axis.setContainer(container)
|
||||
axisElement = atom.views.getView(axis)
|
||||
|
||||
@@ -2,6 +2,13 @@ PaneContainer = require '../src/pane-container'
|
||||
PaneAxisElement = require '../src/pane-axis-element'
|
||||
PaneAxis = require '../src/pane-axis'
|
||||
|
||||
params =
|
||||
location: 'center'
|
||||
config: atom.config
|
||||
confirm: atom.confirm.bind(atom)
|
||||
viewRegistry: atom.views
|
||||
applicationDelegate: atom.applicationDelegate
|
||||
|
||||
describe "PaneContainerElement", ->
|
||||
describe "when panes are added or removed", ->
|
||||
it "inserts or removes resize elements", ->
|
||||
@@ -42,7 +49,7 @@ describe "PaneContainerElement", ->
|
||||
]
|
||||
|
||||
it "transfers focus to the next pane if a focused pane is removed", ->
|
||||
container = new PaneContainer(config: atom.config, confirm: atom.confirm.bind(atom))
|
||||
container = new PaneContainer(params)
|
||||
containerElement = atom.views.getView(container)
|
||||
leftPane = container.getActivePane()
|
||||
leftPaneElement = atom.views.getView(leftPane)
|
||||
@@ -58,7 +65,7 @@ describe "PaneContainerElement", ->
|
||||
|
||||
describe "when a pane is split", ->
|
||||
it "builds appropriately-oriented atom-pane-axis elements", ->
|
||||
container = new PaneContainer(config: atom.config, confirm: atom.confirm.bind(atom))
|
||||
container = new PaneContainer(params)
|
||||
containerElement = atom.views.getView(container)
|
||||
|
||||
pane1 = container.getActivePane()
|
||||
@@ -84,7 +91,7 @@ describe "PaneContainerElement", ->
|
||||
[container, containerElement] = []
|
||||
|
||||
beforeEach ->
|
||||
container = new PaneContainer(config: atom.config, confirm: atom.confirm.bind(atom))
|
||||
container = new PaneContainer(params)
|
||||
containerElement = atom.views.getView(container)
|
||||
document.querySelector('#jasmine-content').appendChild(containerElement)
|
||||
|
||||
@@ -201,7 +208,7 @@ describe "PaneContainerElement", ->
|
||||
[leftPane, rightPane] = []
|
||||
|
||||
beforeEach ->
|
||||
container = new PaneContainer(config: atom.config, confirm: atom.confirm.bind(atom))
|
||||
container = new PaneContainer(params)
|
||||
leftPane = container.getActivePane()
|
||||
rightPane = leftPane.splitRight()
|
||||
|
||||
@@ -258,7 +265,7 @@ describe "PaneContainerElement", ->
|
||||
element.cloneNode(true)
|
||||
element
|
||||
|
||||
container = new PaneContainer(config: atom.config, confirm: atom.confirm.bind(atom))
|
||||
container = new PaneContainer(params)
|
||||
|
||||
[item1, item2, item3, item4, item5, item6, item7, item8, item9] =
|
||||
[buildElement('1'), buildElement('2'), buildElement('3'),
|
||||
|
||||
@@ -7,9 +7,11 @@ describe "PaneContainer", ->
|
||||
beforeEach ->
|
||||
confirm = spyOn(atom.applicationDelegate, 'confirm').andReturn(0)
|
||||
params = {
|
||||
location: 'center',
|
||||
config: atom.config,
|
||||
deserializerManager: atom.deserializers
|
||||
applicationDelegate: atom.applicationDelegate
|
||||
applicationDelegate: atom.applicationDelegate,
|
||||
viewRegistry: atom.views
|
||||
}
|
||||
|
||||
describe "serialization", ->
|
||||
|
||||
@@ -6,7 +6,12 @@ describe "PaneElement", ->
|
||||
beforeEach ->
|
||||
spyOn(atom.applicationDelegate, "open")
|
||||
|
||||
container = new PaneContainer(config: atom.config, confirm: atom.confirm.bind(atom))
|
||||
container = new PaneContainer
|
||||
location: 'center'
|
||||
config: atom.config
|
||||
confirm: atom.confirm.bind(atom)
|
||||
viewRegistry: atom.views
|
||||
applicationDelegate: atom.applicationDelegate
|
||||
containerElement = atom.views.getView(container)
|
||||
pane = container.getActivePane()
|
||||
paneElement = atom.views.getView(pane)
|
||||
|
||||
@@ -51,7 +51,10 @@ describe "Pane", ->
|
||||
[container, pane1, pane2] = []
|
||||
|
||||
beforeEach ->
|
||||
container = new PaneContainer(config: atom.config, applicationDelegate: atom.applicationDelegate)
|
||||
container = new PaneContainer
|
||||
location: 'center'
|
||||
config: atom.config
|
||||
applicationDelegate: atom.applicationDelegate
|
||||
container.getActivePane().splitRight()
|
||||
[pane1, pane2] = container.getPanes()
|
||||
|
||||
|
||||
@@ -5973,7 +5973,7 @@ describe "TextEditor", ->
|
||||
expect(editor.getGrammar().name).toBe 'CoffeeScript'
|
||||
|
||||
describe "softWrapAtPreferredLineLength", ->
|
||||
it "soft wraps the editor at the preferred line length unless the editor is narrower", ->
|
||||
it "soft wraps the editor at the preferred line length unless the editor is narrower or the editor is mini", ->
|
||||
editor.update({
|
||||
editorWidthInChars: 30
|
||||
softWrapped: true
|
||||
@@ -5986,6 +5986,9 @@ describe "TextEditor", ->
|
||||
editor.update({editorWidthInChars: 10})
|
||||
expect(editor.lineTextForScreenRow(0)).toBe 'var '
|
||||
|
||||
editor.update({mini: true})
|
||||
expect(editor.lineTextForScreenRow(0)).toBe 'var quicksort = function () {'
|
||||
|
||||
describe "softWrapHangingIndentLength", ->
|
||||
it "controls how much extra indentation is applied to soft-wrapped lines", ->
|
||||
editor.setText('123456789')
|
||||
|
||||
@@ -24,6 +24,8 @@ describe('Workspace', () => {
|
||||
setDocumentEdited = spyOn(atom.applicationDelegate, 'setWindowDocumentEdited')
|
||||
atom.project.setPaths([atom.project.getDirectories()[0].resolve('dir')])
|
||||
waits(1)
|
||||
|
||||
waitsForPromise(() => atom.workspace.itemLocationStore.clear())
|
||||
})
|
||||
|
||||
afterEach(() => temp.cleanupSync())
|
||||
@@ -117,6 +119,62 @@ describe('Workspace', () => {
|
||||
expect(atom.workspace.getTextEditors().length).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
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(() =>
|
||||
atom.workspace.open(null, {location: 'right'}).then(editor => editor.setText('An untitled editor.'))
|
||||
)
|
||||
|
||||
waitsForPromise(() =>
|
||||
atom.workspace.open('b', {location: 'right'}).then(editor => pane2.activateItem(editor.copy()))
|
||||
)
|
||||
|
||||
waitsForPromise(() =>
|
||||
atom.workspace.open('../sample.js', {location: 'right'}).then(editor => pane3.activateItem(editor))
|
||||
)
|
||||
|
||||
runs(() => {
|
||||
pane3.activeItem.setCursorScreenPosition([2, 4])
|
||||
pane4 = pane2.splitDown()
|
||||
})
|
||||
|
||||
waitsForPromise(() =>
|
||||
atom.workspace.open('../sample.txt', {location: 'right'}).then(editor => pane4.activateItem(editor))
|
||||
)
|
||||
|
||||
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())
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('::open(uri, options)', () => {
|
||||
@@ -202,6 +260,25 @@ describe('Workspace', () => {
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the active pane does not have an editor for the given uri', () => {
|
||||
@@ -218,6 +295,46 @@ describe('Workspace', () => {
|
||||
expect(workspace.getActivePane().activate).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
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()
|
||||
spyOn(atom.workspace.itemLocationStore, 'load').andReturn(Promise.resolve())
|
||||
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()
|
||||
spyOn(atom.workspace.itemLocationStore, 'load').andCallFake(uri =>
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -249,6 +366,22 @@ describe('Workspace', () => {
|
||||
expect(workspace.getActivePaneItem()).toBe(editor1)
|
||||
})
|
||||
})
|
||||
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no editor for the given uri is open in any pane', () => {
|
||||
@@ -685,9 +818,13 @@ describe('Workspace', () => {
|
||||
})
|
||||
)
|
||||
|
||||
it('creates a notification', () => {
|
||||
const open = () => workspace.open('file1', workspace.getActivePane())
|
||||
expect(open).toThrow()
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1986,24 +2123,24 @@ i = /test/; #FIXME\
|
||||
const pane1 = atom.workspace.getActivePane()
|
||||
const pane2 = pane1.splitRight({copyActiveItem: true})
|
||||
|
||||
expect(atom.workspace.getPanes().length).toBe(2)
|
||||
expect(atom.workspace.getCenter().getPanes().length).toBe(2)
|
||||
expect(pane2.getItems().length).toBe(1)
|
||||
atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow()
|
||||
|
||||
expect(atom.workspace.getPanes().length).toBe(2)
|
||||
expect(atom.workspace.getCenter().getPanes().length).toBe(2)
|
||||
expect(pane2.getItems().length).toBe(0)
|
||||
|
||||
atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow()
|
||||
|
||||
expect(atom.workspace.getPanes().length).toBe(1)
|
||||
expect(atom.workspace.getCenter().getPanes().length).toBe(1)
|
||||
expect(pane1.getItems().length).toBe(1)
|
||||
|
||||
atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow()
|
||||
expect(atom.workspace.getPanes().length).toBe(1)
|
||||
expect(atom.workspace.getCenter().getPanes().length).toBe(1)
|
||||
expect(pane1.getItems().length).toBe(0)
|
||||
|
||||
atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow()
|
||||
expect(atom.workspace.getPanes().length).toBe(1)
|
||||
expect(atom.workspace.getCenter().getPanes().length).toBe(1)
|
||||
|
||||
atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow()
|
||||
expect(atom.close).toHaveBeenCalled()
|
||||
|
||||
Reference in New Issue
Block a user