Merge branch 'master' into wl-build-on-node-7

This commit is contained in:
Wliu
2017-03-21 23:25:31 -04:00
committed by GitHub
96 changed files with 5676 additions and 4631 deletions

View File

@@ -126,6 +126,7 @@ describe "AtomEnvironment", ->
beforeEach ->
errors = []
spyOn(atom, 'isReleasedVersion').andReturn(true)
atom.onDidFailAssertion (error) -> errors.push(error)
describe "if the condition is false", ->
@@ -147,6 +148,11 @@ describe "AtomEnvironment", ->
atom.assert(false, "a == b", {foo: 'bar'})
expect(errors[0].metadata).toEqual {foo: 'bar'}
describe "when Atom has been built from source", ->
it "throws an error", ->
atom.isReleasedVersion.andReturn(false)
expect(-> atom.assert(false, 'testing')).toThrow('Assertion failed: testing')
describe "if the condition is true", ->
it "does nothing", ->
result = atom.assert(true, "a == b")
@@ -334,7 +340,8 @@ describe "AtomEnvironment", ->
it "saves the BlobStore so it can be loaded after reload", ->
configDirPath = temp.mkdirSync('atom-spec-environment')
fakeBlobStore = jasmine.createSpyObj("blob store", ["save"])
atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, enablePersistence: true, configDirPath, blobStore: fakeBlobStore, window, document})
atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, enablePersistence: true})
atomEnvironment.initialize({configDirPath, blobStore: fakeBlobStore, window, document})
atomEnvironment.unloadEditorWindow()
@@ -351,7 +358,8 @@ describe "AtomEnvironment", ->
head: document.createElement('head')
body: document.createElement('body')
}
atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window, document: fakeDocument})
atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate})
atomEnvironment.initialize({window, document: fakeDocument})
spyOn(atomEnvironment.packages, 'getAvailablePackagePaths').andReturn []
spyOn(atomEnvironment, 'displayWindow').andReturn Promise.resolve()
atomEnvironment.startEditorWindow()

View File

@@ -11,9 +11,8 @@ describe('AutoUpdateManager (renderer)', () => {
let autoUpdateManager
beforeEach(() => {
autoUpdateManager = new AutoUpdateManager({
applicationDelegate: atom.applicationDelegate
})
autoUpdateManager = new AutoUpdateManager({applicationDelegate: atom.applicationDelegate})
autoUpdateManager.initialize()
})
afterEach(() => {

View File

@@ -25,7 +25,8 @@ describe "CommandInstaller on #darwin", ->
it "shows an error dialog when installing commands interactively fails", ->
appDelegate = jasmine.createSpyObj("appDelegate", ["confirm"])
installer = new CommandInstaller("2.0.2", appDelegate)
installer = new CommandInstaller(appDelegate)
installer.initialize("2.0.2")
spyOn(installer, "installAtomCommand").andCallFake (__, callback) -> callback(new Error("an error"))
installer.installShellCommandsInteractively()
@@ -48,7 +49,8 @@ describe "CommandInstaller on #darwin", ->
it "shows a success dialog when installing commands interactively succeeds", ->
appDelegate = jasmine.createSpyObj("appDelegate", ["confirm"])
installer = new CommandInstaller("2.0.2", appDelegate)
installer = new CommandInstaller(appDelegate)
installer.initialize("2.0.2")
spyOn(installer, "installAtomCommand").andCallFake (__, callback) -> callback()
spyOn(installer, "installApmCommand").andCallFake (__, callback) -> callback()
@@ -61,7 +63,8 @@ describe "CommandInstaller on #darwin", ->
describe "when using a stable version of atom", ->
beforeEach ->
installer = new CommandInstaller("2.0.2")
installer = new CommandInstaller()
installer.initialize("2.0.2")
it "symlinks the atom command as 'atom'", ->
installedAtomPath = path.join(installationPath, 'atom')
@@ -91,7 +94,8 @@ describe "CommandInstaller on #darwin", ->
describe "when using a beta version of atom", ->
beforeEach ->
installer = new CommandInstaller("2.2.0-beta.0")
installer = new CommandInstaller()
installer.initialize("2.2.0-beta.0")
it "symlinks the atom command as 'atom-beta'", ->
installedAtomPath = path.join(installationPath, 'atom-beta')

View File

@@ -5,7 +5,8 @@ describe "ContextMenuManager", ->
beforeEach ->
{resourcePath} = atom.getLoadSettings()
contextMenu = new ContextMenuManager({resourcePath, keymapManager: atom.keymaps})
contextMenu = new ContextMenuManager({keymapManager: atom.keymaps})
contextMenu.initialize({resourcePath})
parent = document.createElement("div")
child = document.createElement("div")

View File

@@ -3,7 +3,10 @@ const DOMElementPool = require ('../src/dom-element-pool')
describe('DOMElementPool', function () {
let domElementPool
beforeEach(() => { domElementPool = new DOMElementPool() })
beforeEach(() => {
domElementPool = new DOMElementPool()
spyOn(atom, 'isReleasedVersion').andReturn(true)
})
it('builds DOM nodes, recycling them when they are freed', function () {
let elements

View File

@@ -14,78 +14,75 @@ describe "FileSystemBlobStore", ->
fs.removeSync(storageDirectory)
it "is empty when the file doesn't exist", ->
expect(blobStore.get("foo", "invalidation-key-1")).toBeUndefined()
expect(blobStore.get("bar", "invalidation-key-2")).toBeUndefined()
expect(blobStore.get("foo")).toBeUndefined()
expect(blobStore.get("bar")).toBeUndefined()
it "allows to read and write buffers from/to memory without persisting them", ->
blobStore.set("foo", "invalidation-key-1", new Buffer("foo"))
blobStore.set("bar", "invalidation-key-2", new Buffer("bar"))
blobStore.set("foo", new Buffer("foo"))
blobStore.set("bar", new Buffer("bar"))
expect(blobStore.get("foo", "invalidation-key-1")).toEqual(new Buffer("foo"))
expect(blobStore.get("bar", "invalidation-key-2")).toEqual(new Buffer("bar"))
expect(blobStore.get("foo")).toEqual(new Buffer("foo"))
expect(blobStore.get("bar")).toEqual(new Buffer("bar"))
expect(blobStore.get("foo", "unexisting-key")).toBeUndefined()
expect(blobStore.get("bar", "unexisting-key")).toBeUndefined()
expect(blobStore.get("baz")).toBeUndefined()
expect(blobStore.get("qux")).toBeUndefined()
it "persists buffers when saved and retrieves them on load, giving priority to in-memory ones", ->
blobStore.set("foo", "invalidation-key-1", new Buffer("foo"))
blobStore.set("bar", "invalidation-key-2", new Buffer("bar"))
blobStore.set("foo", new Buffer("foo"))
blobStore.set("bar", new Buffer("bar"))
blobStore.save()
blobStore = FileSystemBlobStore.load(storageDirectory)
expect(blobStore.get("foo", "invalidation-key-1")).toEqual(new Buffer("foo"))
expect(blobStore.get("bar", "invalidation-key-2")).toEqual(new Buffer("bar"))
expect(blobStore.get("foo", "unexisting-key")).toBeUndefined()
expect(blobStore.get("bar", "unexisting-key")).toBeUndefined()
expect(blobStore.get("foo")).toEqual(new Buffer("foo"))
expect(blobStore.get("bar")).toEqual(new Buffer("bar"))
expect(blobStore.get("baz")).toBeUndefined()
expect(blobStore.get("qux")).toBeUndefined()
blobStore.set("foo", "new-key", new Buffer("changed"))
blobStore.set("foo", new Buffer("changed"))
expect(blobStore.get("foo", "new-key")).toEqual(new Buffer("changed"))
expect(blobStore.get("foo", "invalidation-key-1")).toBeUndefined()
expect(blobStore.get("foo")).toEqual(new Buffer("changed"))
it "persists both in-memory and previously stored buffers when saved", ->
blobStore.set("foo", "invalidation-key-1", new Buffer("foo"))
blobStore.set("bar", "invalidation-key-2", new Buffer("bar"))
it "persists in-memory and previously stored buffers, and deletes unused keys when saved", ->
blobStore.set("foo", new Buffer("foo"))
blobStore.set("bar", new Buffer("bar"))
blobStore.save()
blobStore = FileSystemBlobStore.load(storageDirectory)
blobStore.set("bar", "invalidation-key-3", new Buffer("changed"))
blobStore.set("qux", "invalidation-key-4", new Buffer("qux"))
blobStore.set("bar", new Buffer("changed"))
blobStore.set("qux", new Buffer("qux"))
blobStore.save()
blobStore = FileSystemBlobStore.load(storageDirectory)
expect(blobStore.get("foo", "invalidation-key-1")).toEqual(new Buffer("foo"))
expect(blobStore.get("bar", "invalidation-key-3")).toEqual(new Buffer("changed"))
expect(blobStore.get("qux", "invalidation-key-4")).toEqual(new Buffer("qux"))
expect(blobStore.get("foo", "unexisting-key")).toBeUndefined()
expect(blobStore.get("bar", "invalidation-key-2")).toBeUndefined()
expect(blobStore.get("qux", "unexisting-key")).toBeUndefined()
expect(blobStore.get("foo")).toBeUndefined()
expect(blobStore.get("bar")).toEqual(new Buffer("changed"))
expect(blobStore.get("qux")).toEqual(new Buffer("qux"))
it "allows to delete keys from both memory and stored buffers", ->
blobStore.set("a", "invalidation-key-1", new Buffer("a"))
blobStore.set("b", "invalidation-key-2", new Buffer("b"))
blobStore.set("a", new Buffer("a"))
blobStore.set("b", new Buffer("b"))
blobStore.save()
blobStore = FileSystemBlobStore.load(storageDirectory)
blobStore.set("b", "invalidation-key-3", new Buffer("b"))
blobStore.set("c", "invalidation-key-4", new Buffer("c"))
blobStore.get("a") # prevent the key from being deleted on save
blobStore.set("b", new Buffer("b"))
blobStore.set("c", new Buffer("c"))
blobStore.delete("b")
blobStore.delete("c")
blobStore.save()
blobStore = FileSystemBlobStore.load(storageDirectory)
expect(blobStore.get("a", "invalidation-key-1")).toEqual(new Buffer("a"))
expect(blobStore.get("b", "invalidation-key-2")).toBeUndefined()
expect(blobStore.get("b", "invalidation-key-3")).toBeUndefined()
expect(blobStore.get("c", "invalidation-key-4")).toBeUndefined()
expect(blobStore.get("a")).toEqual(new Buffer("a"))
expect(blobStore.get("b")).toBeUndefined()
expect(blobStore.get("b")).toBeUndefined()
expect(blobStore.get("c")).toBeUndefined()
it "ignores errors when loading an invalid blob store", ->
blobStore.set("a", "invalidation-key-1", new Buffer("a"))
blobStore.set("b", "invalidation-key-2", new Buffer("b"))
blobStore.set("a", new Buffer("a"))
blobStore.set("b", new Buffer("b"))
blobStore.save()
# Simulate corruption
@@ -95,14 +92,14 @@ describe "FileSystemBlobStore", ->
blobStore = FileSystemBlobStore.load(storageDirectory)
expect(blobStore.get("a", "invalidation-key-1")).toBeUndefined()
expect(blobStore.get("b", "invalidation-key-2")).toBeUndefined()
expect(blobStore.get("a")).toBeUndefined()
expect(blobStore.get("b")).toBeUndefined()
blobStore.set("a", "invalidation-key-1", new Buffer("x"))
blobStore.set("b", "invalidation-key-2", new Buffer("y"))
blobStore.set("a", new Buffer("x"))
blobStore.set("b", new Buffer("y"))
blobStore.save()
blobStore = FileSystemBlobStore.load(storageDirectory)
expect(blobStore.get("a", "invalidation-key-1")).toEqual(new Buffer("x"))
expect(blobStore.get("b", "invalidation-key-2")).toEqual(new Buffer("y"))
expect(blobStore.get("a")).toEqual(new Buffer("x"))
expect(blobStore.get("b")).toEqual(new Buffer("y"))

View File

@@ -31,11 +31,6 @@ describe "GitRepository", ->
expect(-> new GitRepository(path.join(temp.dir, 'nogit.txt'))).toThrow()
describe ".getPath()", ->
it "returns the repository path for a .git directory path with a file", ->
return if process.platform is 'win32' #Win32TestFailures - libgit2 does not detect files in .git folders
repo = new GitRepository(path.join(__dirname, 'fixtures', 'git', 'master.git', 'HEAD'))
expect(repo.getPath()).toBe path.join(__dirname, 'fixtures', 'git', 'master.git')
it "returns the repository path for a .git directory path with a directory", ->
repo = new GitRepository(path.join(__dirname, 'fixtures', 'git', 'master.git', 'objects'))
expect(repo.getPath()).toBe path.join(__dirname, 'fixtures', 'git', 'master.git')

View File

@@ -4,27 +4,24 @@ import {it, fit, ffit, fffit, beforeEach, afterEach} from './async-spec-helpers'
import {Emitter, Disposable, CompositeDisposable} from 'event-kit'
import {HistoryManager, HistoryProject} from '../src/history-manager'
import StateStore from '../src/state-store'
describe("HistoryManager", () => {
let historyManager, commandRegistry, project, localStorage, stateStore
let historyManager, commandRegistry, project, stateStore
let commandDisposable, projectDisposable
beforeEach(() => {
beforeEach(async () => {
commandDisposable = jasmine.createSpyObj('Disposable', ['dispose'])
commandRegistry = jasmine.createSpyObj('CommandRegistry', ['add'])
commandRegistry.add.andReturn(commandDisposable)
localStorage = jasmine.createSpyObj('LocalStorage', ['getItem', 'setItem'])
localStorage.items = {
history: JSON.stringify({
projects: [
{ paths: ['/1', 'c:\\2'], lastOpened: new Date(2016, 9, 17, 17, 16, 23) },
{ paths: ['/test'], lastOpened: new Date(2016, 9, 17, 11, 12, 13) }
]
})
}
localStorage.getItem.andCallFake((key) => localStorage.items[key])
localStorage.setItem.andCallFake((key, value) => localStorage.items[key] = value)
stateStore = new StateStore('history-manager-test', 1)
await stateStore.save('history-manager', {
projects: [
{paths: ['/1', 'c:\\2'], lastOpened: new Date(2016, 9, 17, 17, 16, 23)},
{paths: ['/test'], lastOpened: new Date(2016, 9, 17, 11, 12, 13)}
]
})
projectDisposable = jasmine.createSpyObj('Disposable', ['dispose'])
project = jasmine.createSpyObj('Project', ['onDidChangePaths'])
@@ -33,14 +30,20 @@ describe("HistoryManager", () => {
return projectDisposable
})
historyManager = new HistoryManager({project, commands:commandRegistry, localStorage})
historyManager = new HistoryManager({stateStore, project, commands: commandRegistry})
historyManager.initialize(window.localStorage)
await historyManager.loadState()
})
afterEach(async () => {
await stateStore.clear()
})
describe("constructor", () => {
it("registers the 'clear-project-history' command function", () => {
expect(commandRegistry.add).toHaveBeenCalled()
const cmdCall = commandRegistry.add.calls[0]
expect(cmdCall.args.length).toBe(2)
expect(cmdCall.args.length).toBe(3)
expect(cmdCall.args[0]).toBe('atom-workspace')
expect(typeof cmdCall.args[1]['application:clear-project-history']).toBe('function')
})
@@ -65,33 +68,28 @@ describe("HistoryManager", () => {
})
describe("clearProjects", () => {
it("clears the list of projects", () => {
it("clears the list of projects", async () => {
expect(historyManager.getProjects().length).not.toBe(0)
historyManager.clearProjects()
await historyManager.clearProjects()
expect(historyManager.getProjects().length).toBe(0)
})
it("saves the state", () => {
expect(localStorage.setItem).not.toHaveBeenCalled()
historyManager.clearProjects()
expect(localStorage.setItem).toHaveBeenCalled()
expect(localStorage.setItem.calls[0].args[0]).toBe('history')
it("saves the state", async () => {
await historyManager.clearProjects()
const historyManager2 = new HistoryManager({stateStore, localStorage: window.localStorage, project, commands: commandRegistry})
await historyManager2.loadState()
expect(historyManager.getProjects().length).toBe(0)
})
it("fires the onDidChangeProjects event", () => {
expect(localStorage.setItem).not.toHaveBeenCalled()
historyManager.clearProjects()
expect(localStorage.setItem).toHaveBeenCalled()
expect(localStorage.setItem.calls[0].args[0]).toBe('history')
it("fires the onDidChangeProjects event", async () => {
const didChangeSpy = jasmine.createSpy()
historyManager.onDidChangeProjects(didChangeSpy)
await historyManager.clearProjects()
expect(historyManager.getProjects().length).toBe(0)
expect(didChangeSpy).toHaveBeenCalled()
})
})
it("loads state", () => {
expect(localStorage.getItem).toHaveBeenCalledWith('history')
})
it("listens to project.onDidChangePaths adding a new project", () => {
const start = new Date()
project.didChangePathsListener(['/a/new', '/path/or/two'])
@@ -112,61 +110,61 @@ describe("HistoryManager", () => {
})
describe("loadState", () => {
it("defaults to an empty array if no state", () => {
localStorage.items.history = null
historyManager.loadState()
it("defaults to an empty array if no state", async () => {
await stateStore.clear()
await historyManager.loadState()
expect(historyManager.getProjects()).toEqual([])
})
it("defaults to an empty array if no projects", () => {
localStorage.items.history = JSON.stringify('')
historyManager.loadState()
it("defaults to an empty array if no projects", async () => {
await stateStore.save('history-manager', {})
await historyManager.loadState()
expect(historyManager.getProjects()).toEqual([])
})
})
describe("addProject", () => {
it("adds a new project to the end", () => {
it("adds a new project to the end", async () => {
const date = new Date(2010, 10, 9, 8, 7, 6)
historyManager.addProject(['/a/b'], date)
await historyManager.addProject(['/a/b'], date)
const projects = historyManager.getProjects()
expect(projects.length).toBe(3)
expect(projects[2].paths).toEqual(['/a/b'])
expect(projects[2].lastOpened).toBe(date)
})
it("adds a new project to the start", () => {
it("adds a new project to the start", async () => {
const date = new Date()
historyManager.addProject(['/so/new'], date)
await historyManager.addProject(['/so/new'], date)
const projects = historyManager.getProjects()
expect(projects.length).toBe(3)
expect(projects[0].paths).toEqual(['/so/new'])
expect(projects[0].lastOpened).toBe(date)
})
it("updates an existing project and moves it to the start", () => {
it("updates an existing project and moves it to the start", async () => {
const date = new Date()
historyManager.addProject(['/test'], date)
await historyManager.addProject(['/test'], date)
const projects = historyManager.getProjects()
expect(projects.length).toBe(2)
expect(projects[0].paths).toEqual(['/test'])
expect(projects[0].lastOpened).toBe(date)
})
it("fires the onDidChangeProjects event when adding a project", () => {
it("fires the onDidChangeProjects event when adding a project", async () => {
const didChangeSpy = jasmine.createSpy()
const beforeCount = historyManager.getProjects().length
historyManager.onDidChangeProjects(didChangeSpy)
historyManager.addProject(['/test-new'], new Date())
await historyManager.addProject(['/test-new'], new Date())
expect(didChangeSpy).toHaveBeenCalled()
expect(historyManager.getProjects().length).toBe(beforeCount + 1)
})
it("fires the onDidChangeProjects event when updating a project", () => {
it("fires the onDidChangeProjects event when updating a project", async () => {
const didChangeSpy = jasmine.createSpy()
const beforeCount = historyManager.getProjects().length
historyManager.onDidChangeProjects(didChangeSpy)
historyManager.addProject(['/test'], new Date())
await historyManager.addProject(['/test'], new Date())
expect(didChangeSpy).toHaveBeenCalled()
expect(historyManager.getProjects().length).toBe(beforeCount)
})
@@ -186,14 +184,12 @@ describe("HistoryManager", () => {
})
describe("saveState" ,() => {
it("saves the state", () => {
historyManager.addProject(["/save/state"])
historyManager.saveState()
expect(localStorage.setItem).toHaveBeenCalled()
expect(localStorage.setItem.calls[0].args[0]).toBe('history')
expect(localStorage.items['history']).toContain('/save/state')
historyManager.loadState()
expect(historyManager.getProjects()[0].paths).toEqual(['/save/state'])
it("saves the state", async () => {
await historyManager.addProject(["/save/state"])
await historyManager.saveState()
const historyManager2 = new HistoryManager({stateStore, localStorage: window.localStorage, project, commands: commandRegistry})
await historyManager2.loadState()
expect(historyManager2.getProjects()[0].paths).toEqual(['/save/state'])
})
})
})

View File

@@ -112,7 +112,7 @@ describe("FileRecoveryService", () => {
const mockWindow = {}
const filePath = temp.path()
fs.writeFileSync(filePath, "content")
fs.chmodSync(filePath, 0o444)
fs.chmodSync(filePath, 0444)
let logs = []
this.stub(console, 'log', (message) => logs.push(message))

View File

@@ -5,11 +5,8 @@ describe "MenuManager", ->
menu = null
beforeEach ->
menu = new MenuManager(
resourcePath: atom.getLoadSettings().resourcePath
keymapManager: atom.keymaps
packageManager: atom.packages
)
menu = new MenuManager({keymapManager: atom.keymaps, packageManager: atom.packages})
menu.initialize({resourcePath: atom.getLoadSettings().resourcePath})
describe "::add(items)", ->
it "can add new menus that can be removed with the returned disposable", ->

View File

@@ -9,16 +9,18 @@ describe "NativeCompileCache", ->
beforeEach ->
cachedFiles = []
fakeCacheStore = jasmine.createSpyObj("cache store", ["set", "get", "has", "delete"])
fakeCacheStore.has.andCallFake (cacheKey, invalidationKey) ->
fakeCacheStore.get(cacheKey, invalidationKey)?
fakeCacheStore.get.andCallFake (cacheKey, invalidationKey) ->
fakeCacheStore.has.andCallFake (cacheKey) ->
fakeCacheStore.get(cacheKey)?
fakeCacheStore.get.andCallFake (cacheKey) ->
for entry in cachedFiles by -1
continue if entry.cacheKey isnt cacheKey
continue if entry.invalidationKey isnt invalidationKey
return entry.cacheBuffer
return
fakeCacheStore.set.andCallFake (cacheKey, invalidationKey, cacheBuffer) ->
cachedFiles.push({cacheKey, invalidationKey, cacheBuffer})
fakeCacheStore.set.andCallFake (cacheKey, cacheBuffer) ->
cachedFiles.push({cacheKey, cacheBuffer})
nativeCompileCache.setCacheStore(fakeCacheStore)
nativeCompileCache.setV8Version("a-v8-version")
@@ -29,13 +31,10 @@ describe "NativeCompileCache", ->
fn2 = require('./fixtures/native-cache/file-2')
expect(cachedFiles.length).toBe(2)
expect(cachedFiles[0].cacheKey).toBe(require.resolve('./fixtures/native-cache/file-1'))
expect(cachedFiles[0].cacheBuffer).toBeInstanceOf(Uint8Array)
expect(cachedFiles[0].cacheBuffer.length).toBeGreaterThan(0)
expect(fn1()).toBe(1)
expect(cachedFiles[1].cacheKey).toBe(require.resolve('./fixtures/native-cache/file-2'))
expect(cachedFiles[1].cacheBuffer).toBeInstanceOf(Uint8Array)
expect(cachedFiles[1].cacheBuffer.length).toBeGreaterThan(0)
expect(fn2()).toBe(2)
@@ -51,7 +50,6 @@ describe "NativeCompileCache", ->
fn4 = require('./fixtures/native-cache/file-4')
expect(cachedFiles.length).toBe(1)
expect(cachedFiles[0].cacheKey).toBe(require.resolve('./fixtures/native-cache/file-4'))
expect(cachedFiles[0].cacheBuffer).toBeInstanceOf(Uint8Array)
expect(cachedFiles[0].cacheBuffer.length).toBeGreaterThan(0)
expect(fn4()).toBe("file-4")
@@ -61,8 +59,6 @@ describe "NativeCompileCache", ->
fn4 = require('./fixtures/native-cache/file-4')
expect(cachedFiles.length).toBe(2)
expect(cachedFiles[1].cacheKey).toBe(require.resolve('./fixtures/native-cache/file-4'))
expect(cachedFiles[1].invalidationKey).not.toBe(cachedFiles[0].invalidationKey)
expect(cachedFiles[1].cacheBuffer).toBeInstanceOf(Uint8Array)
expect(cachedFiles[1].cacheBuffer.length).toBeGreaterThan(0)
@@ -79,7 +75,6 @@ describe "NativeCompileCache", ->
fn5 = require('./fixtures/native-cache/file-5')
expect(cachedFiles.length).toBe(1)
expect(cachedFiles[0].cacheKey).toBe(require.resolve('./fixtures/native-cache/file-5'))
expect(cachedFiles[0].cacheBuffer).toBeInstanceOf(Uint8Array)
expect(cachedFiles[0].cacheBuffer.length).toBeGreaterThan(0)
expect(fn5()).toBe("file-5")
@@ -89,8 +84,6 @@ describe "NativeCompileCache", ->
fn5 = require('./fixtures/native-cache/file-5')
expect(cachedFiles.length).toBe(2)
expect(cachedFiles[1].cacheKey).toBe(require.resolve('./fixtures/native-cache/file-5'))
expect(cachedFiles[1].invalidationKey).not.toBe(cachedFiles[0].invalidationKey)
expect(cachedFiles[1].cacheBuffer).toBeInstanceOf(Uint8Array)
expect(cachedFiles[1].cacheBuffer.length).toBeGreaterThan(0)
@@ -100,5 +93,5 @@ describe "NativeCompileCache", ->
fn3 = require('./fixtures/native-cache/file-3')
expect(fakeCacheStore.delete).toHaveBeenCalledWith(require.resolve('./fixtures/native-cache/file-3'))
expect(fakeCacheStore.delete).toHaveBeenCalled()
expect(fn3()).toBe(3)

View File

@@ -23,6 +23,7 @@ describe "PaneContainer", ->
serialize: -> deserializer: 'Item'
containerA = new PaneContainer(params)
containerA.initialize()
pane1A = containerA.getActivePane()
pane1A.addItem(new Item)
pane2A = pane1A.splitRight(items: [new Item])
@@ -33,6 +34,7 @@ describe "PaneContainer", ->
expect(pane3A.focused).toBe true
containerB = new PaneContainer(params)
containerB.initialize()
containerB.deserialize(containerA.serialize(), atom.deserializers)
[pane1B, pane2B, pane3B] = containerB.getPanes()
expect(pane3B.focused).toBe true
@@ -42,6 +44,7 @@ describe "PaneContainer", ->
expect(containerA.getActivePane()).toBe pane3A
containerB = new PaneContainer(params)
containerB.initialize()
containerB.deserialize(containerA.serialize(), atom.deserializers)
[pane1B, pane2B, pane3B] = containerB.getPanes()
expect(containerB.getActivePane()).toBe pane3B
@@ -51,6 +54,7 @@ describe "PaneContainer", ->
state = containerA.serialize()
state.activePaneId = -22
containerB = new PaneContainer(params)
containerB.initialize()
containerB.deserialize(state, atom.deserializers)
expect(containerB.getActivePane()).toBe containerB.getPanes()[0]
@@ -62,6 +66,7 @@ describe "PaneContainer", ->
it "leaves the empty panes intact", ->
state = containerA.serialize()
containerB = new PaneContainer(params)
containerB.initialize()
containerB.deserialize(state, atom.deserializers)
[leftPane, column] = containerB.getRoot().getChildren()
[topPane, bottomPane] = column.getChildren()
@@ -76,6 +81,7 @@ describe "PaneContainer", ->
state = containerA.serialize()
containerB = new PaneContainer(params)
containerB.initialize()
containerB.deserialize(state, atom.deserializers)
[leftPane, rightPane] = containerB.getRoot().getChildren()
@@ -84,6 +90,7 @@ describe "PaneContainer", ->
it "does not allow the root pane to be destroyed", ->
container = new PaneContainer(params)
container.initialize()
container.getRoot().destroy()
expect(container.getRoot()).toBeDefined()
expect(container.getRoot().isDestroyed()).toBe false
@@ -93,6 +100,7 @@ describe "PaneContainer", ->
beforeEach ->
container = new PaneContainer(params)
container.initialize()
pane1 = container.getRoot()
it "returns the first pane if no pane has been made active", ->
@@ -122,6 +130,7 @@ describe "PaneContainer", ->
beforeEach ->
container = new PaneContainer(params)
container.initialize()
container.getRoot().addItems([new Object, new Object])
container.getRoot().splitRight(items: [new Object, new Object])
[pane1, pane2] = container.getPanes()
@@ -144,6 +153,7 @@ describe "PaneContainer", ->
beforeEach ->
container = new PaneContainer(root: new Pane(items: [new Object, new Object]))
container.initialize()
container.getRoot().splitRight(items: [new Object, new Object])
[pane1, pane2] = container.getPanes()
@@ -165,6 +175,7 @@ describe "PaneContainer", ->
describe "::observePanes()", ->
it "invokes observers with all current and future panes", ->
container = new PaneContainer(params)
container.initialize()
container.getRoot().splitRight()
[pane1, pane2] = container.getPanes()
@@ -179,6 +190,7 @@ describe "PaneContainer", ->
describe "::observePaneItems()", ->
it "invokes observers with all current and future pane items", ->
container = new PaneContainer(params)
container.initialize()
container.getRoot().addItems([new Object, new Object])
container.getRoot().splitRight(items: [new Object])
[pane1, pane2] = container.getPanes()
@@ -199,6 +211,7 @@ describe "PaneContainer", ->
getURI: -> 'test'
container = new PaneContainer(params)
container.initialize()
container.getRoot().splitRight()
[pane1, pane2] = container.getPanes()
pane1.addItem(new TestItem)
@@ -219,6 +232,7 @@ describe "PaneContainer", ->
describe "::onDidAddPane(callback)", ->
it "invokes the given callback when panes are added", ->
container = new PaneContainer(params)
container.initialize()
events = []
container.onDidAddPane (event) ->
expect(event.pane in container.getPanes()).toBe true
@@ -238,6 +252,7 @@ describe "PaneContainer", ->
isDestroyed: -> @_isDestroyed
container = new PaneContainer(params)
container.initialize()
events = []
container.onWillDestroyPane (event) ->
itemsDestroyed = (item.isDestroyed() for item in event.pane.getItems())
@@ -254,6 +269,7 @@ describe "PaneContainer", ->
describe "::onDidDestroyPane(callback)", ->
it "invokes the given callback when panes are destroyed", ->
container = new PaneContainer(params)
container.initialize()
events = []
container.onDidDestroyPane (event) ->
expect(event.pane in container.getPanes()).toBe false
@@ -270,6 +286,7 @@ describe "PaneContainer", ->
it "invokes the given callback when the container is destroyed", ->
container = new PaneContainer(params)
container.initialize()
events = []
container.onDidDestroyPane (event) ->
expect(event.pane in container.getPanes()).toBe false
@@ -286,6 +303,7 @@ describe "PaneContainer", ->
describe "::onWillDestroyPaneItem() and ::onDidDestroyPaneItem", ->
it "invokes the given callbacks when an item will be destroyed on any pane", ->
container = new PaneContainer(params)
container.initialize()
pane1 = container.getRoot()
item1 = new Object
item2 = new Object
@@ -313,6 +331,7 @@ describe "PaneContainer", ->
describe "::saveAll()", ->
it "saves all modified pane items", ->
container = new PaneContainer(params)
container.initialize()
pane1 = container.getRoot()
pane2 = pane1.splitRight()
@@ -354,6 +373,7 @@ describe "PaneContainer", ->
copy: -> new TestItem(@id)
container = new PaneContainer(params)
container.initialize()
pane1 = container.getRoot()
item1 = new TestItem('1')
pane2 = pane1.splitRight(items: [item1])

View File

@@ -1,137 +0,0 @@
Panel = require '../src/panel'
PanelContainer = require '../src/panel-container'
describe "PanelContainerElement", ->
[jasmineContent, element, container] = []
class TestPanelContainerItem
constructior: ->
class TestPanelContainerItemElement extends HTMLElement
createdCallback: ->
@classList.add('test-root')
initialize: (@model) ->
this
TestPanelContainerItemElement = document.registerElement 'atom-test-container-item-element', prototype: TestPanelContainerItemElement.prototype
beforeEach ->
jasmineContent = document.body.querySelector('#jasmine-content')
atom.views.addViewProvider TestPanelContainerItem, (model) ->
new TestPanelContainerItemElement().initialize(model)
container = new PanelContainer({location: 'left'})
element = atom.views.getView(container)
jasmineContent.appendChild(element)
it 'has a location class with value from the model', ->
expect(element).toHaveClass 'left'
it 'removes the element when the container is destroyed', ->
expect(element.parentNode).toBe jasmineContent
container.destroy()
expect(element.parentNode).not.toBe jasmineContent
describe "adding and removing panels", ->
it "allows panels to be inserted at any position", ->
panel1 = new Panel({item: new TestPanelContainerItem(), priority: 10})
panel2 = new Panel({item: new TestPanelContainerItem(), priority: 5})
panel3 = new Panel({item: new TestPanelContainerItem(), priority: 8})
container.addPanel(panel1)
container.addPanel(panel2)
container.addPanel(panel3)
expect(element.childNodes[2].getModel()).toBe(panel1)
expect(element.childNodes[1].getModel()).toBe(panel3)
expect(element.childNodes[0].getModel()).toBe(panel2)
describe "when the container is at the left location", ->
it "adds atom-panel elements when a new panel is added to the container; removes them when the panels are destroyed", ->
expect(element.childNodes.length).toBe 0
panel1 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel1)
expect(element.childNodes.length).toBe 1
expect(element.childNodes[0]).toHaveClass 'left'
expect(element.childNodes[0]).toHaveClass 'tool-panel' # legacy selector support
expect(element.childNodes[0]).toHaveClass 'panel-left' # legacy selector support
expect(element.childNodes[0].tagName).toBe 'ATOM-PANEL'
panel2 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel2)
expect(element.childNodes.length).toBe 2
expect(atom.views.getView(panel1).style.display).not.toBe 'none'
expect(atom.views.getView(panel2).style.display).not.toBe 'none'
panel1.destroy()
expect(element.childNodes.length).toBe 1
panel2.destroy()
expect(element.childNodes.length).toBe 0
describe "when the container is at the bottom location", ->
beforeEach ->
container = new PanelContainer({location: 'bottom'})
element = atom.views.getView(container)
jasmineContent.appendChild(element)
it "adds atom-panel elements when a new panel is added to the container; removes them when the panels are destroyed", ->
expect(element.childNodes.length).toBe 0
panel1 = new Panel({item: new TestPanelContainerItem(), className: 'one'})
container.addPanel(panel1)
expect(element.childNodes.length).toBe 1
expect(element.childNodes[0]).toHaveClass 'bottom'
expect(element.childNodes[0]).toHaveClass 'tool-panel' # legacy selector support
expect(element.childNodes[0]).toHaveClass 'panel-bottom' # legacy selector support
expect(element.childNodes[0].tagName).toBe 'ATOM-PANEL'
expect(atom.views.getView(panel1)).toHaveClass 'one'
panel2 = new Panel({item: new TestPanelContainerItem(), className: 'two'})
container.addPanel(panel2)
expect(element.childNodes.length).toBe 2
expect(atom.views.getView(panel2)).toHaveClass 'two'
panel1.destroy()
expect(element.childNodes.length).toBe 1
panel2.destroy()
expect(element.childNodes.length).toBe 0
describe "when the container is modal", ->
beforeEach ->
container = new PanelContainer({location: 'modal'})
element = atom.views.getView(container)
jasmineContent.appendChild(element)
it "allows only one panel to be visible at a time", ->
panel1 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel1)
expect(atom.views.getView(panel1).style.display).not.toBe 'none'
panel2 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel2)
expect(atom.views.getView(panel1).style.display).toBe 'none'
expect(atom.views.getView(panel2).style.display).not.toBe 'none'
panel1.show()
expect(atom.views.getView(panel1).style.display).not.toBe 'none'
expect(atom.views.getView(panel2).style.display).toBe 'none'
it "adds the 'modal' class to panels", ->
panel1 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel1)
expect(atom.views.getView(panel1)).toHaveClass 'modal'
# legacy selector support
expect(atom.views.getView(panel1)).not.toHaveClass 'tool-panel'
expect(atom.views.getView(panel1)).toHaveClass 'overlay'
expect(atom.views.getView(panel1)).toHaveClass 'from-top'

View File

@@ -0,0 +1,165 @@
'use strict'
/* global HTMLElement */
const Panel = require('../src/panel')
const PanelContainer = require('../src/panel-container')
describe('PanelContainerElement', () => {
let jasmineContent, element, container
class TestPanelContainerItem {
}
class TestPanelContainerItemElement_ extends HTMLElement {
createdCallback () {
this.classList.add('test-root')
}
initialize (model) {
this.model = model
return this
}
}
const TestPanelContainerItemElement = document.registerElement(
'atom-test-container-item-element',
{prototype: TestPanelContainerItemElement_.prototype}
)
beforeEach(() => {
jasmineContent = document.body.querySelector('#jasmine-content')
atom.views.addViewProvider(
TestPanelContainerItem,
model => new TestPanelContainerItemElement().initialize(model)
)
container = new PanelContainer({location: 'left'})
element = atom.views.getView(container)
jasmineContent.appendChild(element)
})
it('has a location class with value from the model', () => {
expect(element).toHaveClass('left')
})
it('removes the element when the container is destroyed', () => {
expect(element.parentNode).toBe(jasmineContent)
container.destroy()
expect(element.parentNode).not.toBe(jasmineContent)
})
describe('adding and removing panels', () => {
it('allows panels to be inserted at any position', () => {
const panel1 = new Panel({item: new TestPanelContainerItem(), priority: 10})
const panel2 = new Panel({item: new TestPanelContainerItem(), priority: 5})
const panel3 = new Panel({item: new TestPanelContainerItem(), priority: 8})
container.addPanel(panel1)
container.addPanel(panel2)
container.addPanel(panel3)
expect(element.childNodes[2].getModel()).toBe(panel1)
expect(element.childNodes[1].getModel()).toBe(panel3)
expect(element.childNodes[0].getModel()).toBe(panel2)
})
describe('when the container is at the left location', () =>
it('adds atom-panel elements when a new panel is added to the container; removes them when the panels are destroyed', () => {
expect(element.childNodes.length).toBe(0)
const panel1 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel1)
expect(element.childNodes.length).toBe(1)
expect(element.childNodes[0]).toHaveClass('left')
expect(element.childNodes[0]).toHaveClass('tool-panel') // legacy selector support
expect(element.childNodes[0]).toHaveClass('panel-left') // legacy selector support
expect(element.childNodes[0].tagName).toBe('ATOM-PANEL')
const panel2 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel2)
expect(element.childNodes.length).toBe(2)
expect(atom.views.getView(panel1).style.display).not.toBe('none')
expect(atom.views.getView(panel2).style.display).not.toBe('none')
panel1.destroy()
expect(element.childNodes.length).toBe(1)
panel2.destroy()
expect(element.childNodes.length).toBe(0)
})
)
describe('when the container is at the bottom location', () => {
beforeEach(() => {
container = new PanelContainer({location: 'bottom'})
element = atom.views.getView(container)
jasmineContent.appendChild(element)
})
it('adds atom-panel elements when a new panel is added to the container; removes them when the panels are destroyed', () => {
expect(element.childNodes.length).toBe(0)
const panel1 = new Panel({item: new TestPanelContainerItem(), className: 'one'})
container.addPanel(panel1)
expect(element.childNodes.length).toBe(1)
expect(element.childNodes[0]).toHaveClass('bottom')
expect(element.childNodes[0]).toHaveClass('tool-panel') // legacy selector support
expect(element.childNodes[0]).toHaveClass('panel-bottom') // legacy selector support
expect(element.childNodes[0].tagName).toBe('ATOM-PANEL')
expect(atom.views.getView(panel1)).toHaveClass('one')
const panel2 = new Panel({item: new TestPanelContainerItem(), className: 'two'})
container.addPanel(panel2)
expect(element.childNodes.length).toBe(2)
expect(atom.views.getView(panel2)).toHaveClass('two')
panel1.destroy()
expect(element.childNodes.length).toBe(1)
panel2.destroy()
expect(element.childNodes.length).toBe(0)
})
})
})
describe('when the container is modal', () => {
beforeEach(() => {
container = new PanelContainer({location: 'modal'})
element = atom.views.getView(container)
jasmineContent.appendChild(element)
})
it('allows only one panel to be visible at a time', () => {
const panel1 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel1)
expect(atom.views.getView(panel1).style.display).not.toBe('none')
const panel2 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel2)
expect(atom.views.getView(panel1).style.display).toBe('none')
expect(atom.views.getView(panel2).style.display).not.toBe('none')
panel1.show()
expect(atom.views.getView(panel1).style.display).not.toBe('none')
expect(atom.views.getView(panel2).style.display).toBe('none')
})
it("adds the 'modal' class to panels", () => {
const panel1 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel1)
expect(atom.views.getView(panel1)).toHaveClass('modal')
// legacy selector support
expect(atom.views.getView(panel1)).not.toHaveClass('tool-panel')
expect(atom.views.getView(panel1)).toHaveClass('overlay')
expect(atom.views.getView(panel1)).toHaveClass('from-top')
})
})
})

View File

@@ -1,96 +0,0 @@
Panel = require '../src/panel'
PanelContainer = require '../src/panel-container'
describe "PanelContainer", ->
[container] = []
class TestPanelItem
constructior: ->
beforeEach ->
container = new PanelContainer
describe "::addPanel(panel)", ->
it 'emits an onDidAddPanel event with the index the panel was inserted at', ->
container.onDidAddPanel addPanelSpy = jasmine.createSpy()
panel1 = new Panel(item: new TestPanelItem())
container.addPanel(panel1)
expect(addPanelSpy).toHaveBeenCalledWith({panel: panel1, index: 0})
panel2 = new Panel(item: new TestPanelItem())
container.addPanel(panel2)
expect(addPanelSpy).toHaveBeenCalledWith({panel: panel2, index: 1})
describe "when a panel is destroyed", ->
it 'emits an onDidRemovePanel event with the index of the removed item', ->
container.onDidRemovePanel removePanelSpy = jasmine.createSpy()
panel1 = new Panel(item: new TestPanelItem())
container.addPanel(panel1)
panel2 = new Panel(item: new TestPanelItem())
container.addPanel(panel2)
expect(removePanelSpy).not.toHaveBeenCalled()
panel2.destroy()
expect(removePanelSpy).toHaveBeenCalledWith({panel: panel2, index: 1})
panel1.destroy()
expect(removePanelSpy).toHaveBeenCalledWith({panel: panel1, index: 0})
describe "panel priority", ->
describe 'left / top panel container', ->
[initialPanel] = []
beforeEach ->
# 'left' logic is the same as 'top'
container = new PanelContainer({location: 'left'})
initialPanel = new Panel(item: new TestPanelItem())
container.addPanel(initialPanel)
describe 'when a panel with low priority is added', ->
it 'is inserted at the beginning of the list', ->
container.onDidAddPanel addPanelSpy = jasmine.createSpy()
panel = new Panel(item: new TestPanelItem(), priority: 0)
container.addPanel(panel)
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
expect(container.getPanels()[0]).toBe panel
describe 'when a panel with priority between two other panels is added', ->
it 'is inserted at the between the two panels', ->
panel = new Panel(item: new TestPanelItem(), priority: 1000)
container.addPanel(panel)
container.onDidAddPanel addPanelSpy = jasmine.createSpy()
panel = new Panel(item: new TestPanelItem(), priority: 101)
container.addPanel(panel)
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 1})
expect(container.getPanels()[1]).toBe panel
describe 'right / bottom panel container', ->
[initialPanel] = []
beforeEach ->
# 'bottom' logic is the same as 'right'
container = new PanelContainer({location: 'right'})
initialPanel = new Panel(item: new TestPanelItem())
container.addPanel(initialPanel)
describe 'when a panel with high priority is added', ->
it 'is inserted at the beginning of the list', ->
container.onDidAddPanel addPanelSpy = jasmine.createSpy()
panel = new Panel(item: new TestPanelItem(), priority: 1000)
container.addPanel(panel)
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
expect(container.getPanels()[0]).toBe panel
describe 'when a panel with low priority is added', ->
it 'is inserted at the end of the list', ->
container.onDidAddPanel addPanelSpy = jasmine.createSpy()
panel = new Panel(item: new TestPanelItem(), priority: 0)
container.addPanel(panel)
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 1})
expect(container.getPanels()[1]).toBe panel

View File

@@ -0,0 +1,142 @@
'use strict'
const Panel = require('../src/panel')
const PanelContainer = require('../src/panel-container')
describe('PanelContainer', () => {
let container
class TestPanelItem {
}
beforeEach(() => {
container = new PanelContainer()
})
describe('::addPanel(panel)', () => {
it('emits an onDidAddPanel event with the index the panel was inserted at', () => {
const addPanelSpy = jasmine.createSpy()
container.onDidAddPanel(addPanelSpy)
const panel1 = new Panel({item: new TestPanelItem()})
container.addPanel(panel1)
expect(addPanelSpy).toHaveBeenCalledWith({panel: panel1, index: 0})
const panel2 = new Panel({item: new TestPanelItem()})
container.addPanel(panel2)
expect(addPanelSpy).toHaveBeenCalledWith({panel: panel2, index: 1})
})
})
describe('when a panel is destroyed', () => {
it('emits an onDidRemovePanel event with the index of the removed item', () => {
const removePanelSpy = jasmine.createSpy()
container.onDidRemovePanel(removePanelSpy)
const panel1 = new Panel({item: new TestPanelItem()})
container.addPanel(panel1)
const panel2 = new Panel({item: new TestPanelItem()})
container.addPanel(panel2)
expect(removePanelSpy).not.toHaveBeenCalled()
panel2.destroy()
expect(removePanelSpy).toHaveBeenCalledWith({panel: panel2, index: 1})
panel1.destroy()
expect(removePanelSpy).toHaveBeenCalledWith({panel: panel1, index: 0})
})
})
describe('::destroy()', () => {
it('destroys the container and all of its panels', () => {
const destroyedPanels = []
const panel1 = new Panel({item: new TestPanelItem()})
panel1.onDidDestroy(() => { destroyedPanels.push(panel1) })
container.addPanel(panel1)
const panel2 = new Panel({item: new TestPanelItem()})
panel2.onDidDestroy(() => { destroyedPanels.push(panel2) })
container.addPanel(panel2)
container.destroy()
expect(container.getPanels().length).toBe(0)
expect(destroyedPanels).toEqual([panel1, panel2])
})
})
describe('panel priority', () => {
describe('left / top panel container', () => {
let initialPanel
beforeEach(() => {
// 'left' logic is the same as 'top'
container = new PanelContainer({location: 'left'})
initialPanel = new Panel({item: new TestPanelItem()})
container.addPanel(initialPanel)
})
describe('when a panel with low priority is added', () => {
it('is inserted at the beginning of the list', () => {
const addPanelSpy = jasmine.createSpy()
container.onDidAddPanel(addPanelSpy)
const panel = new Panel({item: new TestPanelItem(), priority: 0})
container.addPanel(panel)
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
expect(container.getPanels()[0]).toBe(panel)
})
})
describe('when a panel with priority between two other panels is added', () => {
it('is inserted at the between the two panels', () => {
const addPanelSpy = jasmine.createSpy()
let panel = new Panel({item: new TestPanelItem(), priority: 1000})
container.addPanel(panel)
container.onDidAddPanel(addPanelSpy)
panel = new Panel({item: new TestPanelItem(), priority: 101})
container.addPanel(panel)
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 1})
expect(container.getPanels()[1]).toBe(panel)
})
})
})
describe('right / bottom panel container', () => {
let initialPanel
beforeEach(() => {
// 'bottom' logic is the same as 'right'
container = new PanelContainer({location: 'right'})
initialPanel = new Panel({item: new TestPanelItem()})
container.addPanel(initialPanel)
})
describe('when a panel with high priority is added', () => {
it('is inserted at the beginning of the list', () => {
const addPanelSpy = jasmine.createSpy()
container.onDidAddPanel(addPanelSpy)
const panel = new Panel({item: new TestPanelItem(), priority: 1000})
container.addPanel(panel)
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
expect(container.getPanels()[0]).toBe(panel)
})
})
describe('when a panel with low priority is added', () => {
it('is inserted at the end of the list', () => {
const addPanelSpy = jasmine.createSpy()
container.onDidAddPanel(addPanelSpy)
const panel = new Panel({item: new TestPanelItem(), priority: 0})
container.addPanel(panel)
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 1})
expect(container.getPanels()[1]).toBe(panel)
})
})
})
})
})

View File

@@ -28,7 +28,13 @@ describe "TextEditor", ->
editor.foldBufferRow(4)
expect(editor.isFoldedAtBufferRow(4)).toBeTruthy()
editor2 = TextEditor.deserialize(editor.serialize(), atom)
editor2 = TextEditor.deserialize(editor.serialize(), {
assert: atom.assert,
textEditors: atom.textEditors,
project: {
bufferForIdSync: (id) -> TextBuffer.deserialize(editor.buffer.serialize())
}
})
expect(editor2.id).toBe editor.id
expect(editor2.getBuffer().getPath()).toBe editor.getBuffer().getPath()
@@ -4862,8 +4868,8 @@ describe "TextEditor", ->
editor.replaceSelectedText {}, -> '123'
expect(buffer.lineForRow(0)).toBe '123var quicksort = function () {'
editor.replaceSelectedText {selectWordIfEmpty: true}, -> 'var'
editor.setCursorBufferPosition([0])
editor.replaceSelectedText {selectWordIfEmpty: true}, -> 'var'
expect(buffer.lineForRow(0)).toBe 'var quicksort = function () {'
editor.setCursorBufferPosition([10])
@@ -4876,6 +4882,12 @@ describe "TextEditor", ->
editor.replaceSelectedText {}, -> 'ia'
expect(buffer.lineForRow(0)).toBe 'via quicksort = function () {'
it "replaces the selected text and selects the replacement text", ->
editor.setSelectedBufferRange([[0, 4], [0, 9]])
editor.replaceSelectedText {}, -> 'whatnot'
expect(buffer.lineForRow(0)).toBe 'var whatnotsort = function () {'
expect(editor.getSelectedBufferRange()).toEqual [[0, 4], [0, 11]]
describe ".transpose()", ->
it "swaps two characters", ->
editor.buffer.setText("abc")
@@ -4896,7 +4908,7 @@ describe "TextEditor", ->
editor.setCursorScreenPosition([0, 1])
editor.upperCase()
expect(editor.lineTextForBufferRow(0)).toBe 'ABC'
expect(editor.getSelectedBufferRange()).toEqual [[0, 1], [0, 1]]
expect(editor.getSelectedBufferRange()).toEqual [[0, 0], [0, 3]]
describe "when there is a selection", ->
it "upper cases the current selection", ->
@@ -4913,7 +4925,7 @@ describe "TextEditor", ->
editor.setCursorScreenPosition([0, 1])
editor.lowerCase()
expect(editor.lineTextForBufferRow(0)).toBe 'abc'
expect(editor.getSelectedBufferRange()).toEqual [[0, 1], [0, 1]]
expect(editor.getSelectedBufferRange()).toEqual [[0, 0], [0, 3]]
describe "when there is a selection", ->
it "lower cases the current selection", ->

View File

@@ -194,10 +194,10 @@ describe "atom.themes", ->
expect(element.getAttribute('source-path')).toEqualPath lessPath
expect(element.textContent).toBe """
#header {
color: #4d926f;
color: #4D926F;
}
h2 {
color: #4d926f;
color: #4D926F;
}
"""

View File

@@ -5,6 +5,7 @@ describe "ViewRegistry", ->
beforeEach ->
registry = new ViewRegistry
registry.initialize()
afterEach ->
registry.clearDocumentRequests()

View File

@@ -15,7 +15,8 @@ describe "WindowEventHandler", ->
loadSettings.initialPath = initialPath
loadSettings
atom.project.destroy()
windowEventHandler = new WindowEventHandler({atomEnvironment: atom, applicationDelegate: atom.applicationDelegate, window, document})
windowEventHandler = new WindowEventHandler({atomEnvironment: atom, applicationDelegate: atom.applicationDelegate})
windowEventHandler.initialize(window, document)
afterEach ->
windowEventHandler.unsubscribe()

View File

@@ -1,210 +0,0 @@
{ipcRenderer} = require 'electron'
path = require 'path'
temp = require('temp').track()
{Disposable} = require 'event-kit'
describe "WorkspaceElement", ->
afterEach ->
temp.cleanupSync()
describe "when the workspace element is focused", ->
it "transfers focus to the active pane", ->
workspaceElement = atom.views.getView(atom.workspace)
jasmine.attachToDOM(workspaceElement)
activePaneElement = atom.views.getView(atom.workspace.getActivePane())
document.body.focus()
expect(document.activeElement).not.toBe(activePaneElement)
workspaceElement.focus()
expect(document.activeElement).toBe(activePaneElement)
describe "the scrollbar visibility class", ->
it "has a class based on the style of the scrollbar", ->
observeCallback = null
scrollbarStyle = require 'scrollbar-style'
spyOn(scrollbarStyle, 'observePreferredScrollbarStyle').andCallFake (cb) ->
observeCallback = cb
new Disposable(->)
workspaceElement = atom.views.getView(atom.workspace)
observeCallback('legacy')
expect(workspaceElement.className).toMatch 'scrollbars-visible-always'
observeCallback('overlay')
expect(workspaceElement).toHaveClass 'scrollbars-visible-when-scrolling'
describe "editor font styling", ->
[editor, editorElement, workspaceElement] = []
beforeEach ->
waitsForPromise -> atom.workspace.open('sample.js')
runs ->
workspaceElement = atom.views.getView(atom.workspace)
jasmine.attachToDOM(workspaceElement)
editor = atom.workspace.getActiveTextEditor()
editorElement = atom.views.getView(editor)
it "updates the font-size based on the 'editor.fontSize' config value", ->
initialCharWidth = editor.getDefaultCharWidth()
expect(getComputedStyle(editorElement).fontSize).toBe atom.config.get('editor.fontSize') + 'px'
atom.config.set('editor.fontSize', atom.config.get('editor.fontSize') + 5)
expect(getComputedStyle(editorElement).fontSize).toBe atom.config.get('editor.fontSize') + 'px'
expect(editor.getDefaultCharWidth()).toBeGreaterThan initialCharWidth
it "updates the font-family based on the 'editor.fontFamily' config value", ->
initialCharWidth = editor.getDefaultCharWidth()
fontFamily = atom.config.get('editor.fontFamily')
fontFamily += ', "Apple Color Emoji"' if process.platform is 'darwin'
expect(getComputedStyle(editorElement).fontFamily).toBe fontFamily
atom.config.set('editor.fontFamily', 'sans-serif')
fontFamily = atom.config.get('editor.fontFamily')
fontFamily += ', "Apple Color Emoji"' if process.platform is 'darwin'
expect(getComputedStyle(editorElement).fontFamily).toBe fontFamily
expect(editor.getDefaultCharWidth()).not.toBe initialCharWidth
it "updates the line-height based on the 'editor.lineHeight' config value", ->
initialLineHeight = editor.getLineHeightInPixels()
atom.config.set('editor.lineHeight', '30px')
expect(getComputedStyle(editorElement).lineHeight).toBe atom.config.get('editor.lineHeight')
expect(editor.getLineHeightInPixels()).not.toBe initialLineHeight
it "increases or decreases the font size when a ctrl-mousewheel event occurs", ->
atom.config.set('editor.zoomFontWhenCtrlScrolling', true)
atom.config.set('editor.fontSize', 12)
# Zoom out
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: -10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(11)
# Zoom in
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
# Not on an atom-text-editor
workspaceElement.dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
# No ctrl key
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10,
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
atom.config.set('editor.zoomFontWhenCtrlScrolling', false)
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
describe 'panel containers', ->
it 'inserts panel container elements in the correct places in the DOM', ->
workspaceElement = atom.views.getView(atom.workspace)
leftContainer = workspaceElement.querySelector('atom-panel-container.left')
rightContainer = workspaceElement.querySelector('atom-panel-container.right')
expect(leftContainer.nextSibling).toBe workspaceElement.verticalAxis
expect(rightContainer.previousSibling).toBe workspaceElement.verticalAxis
topContainer = workspaceElement.querySelector('atom-panel-container.top')
bottomContainer = workspaceElement.querySelector('atom-panel-container.bottom')
expect(topContainer.nextSibling).toBe workspaceElement.paneContainer
expect(bottomContainer.previousSibling).toBe workspaceElement.paneContainer
headerContainer = workspaceElement.querySelector('atom-panel-container.header')
footerContainer = workspaceElement.querySelector('atom-panel-container.footer')
expect(headerContainer.nextSibling).toBe workspaceElement.horizontalAxis
expect(footerContainer.previousSibling).toBe workspaceElement.horizontalAxis
modalContainer = workspaceElement.querySelector('atom-panel-container.modal')
expect(modalContainer.parentNode).toBe workspaceElement
it 'stretches header/footer panels to the workspace width', ->
workspaceElement = atom.views.getView(atom.workspace)
jasmine.attachToDOM(workspaceElement)
expect(workspaceElement.offsetWidth).toBeGreaterThan(0)
headerItem = document.createElement('div')
atom.workspace.addHeaderPanel({item: headerItem})
expect(headerItem.offsetWidth).toEqual(workspaceElement.offsetWidth)
footerItem = document.createElement('div')
atom.workspace.addFooterPanel({item: footerItem})
expect(footerItem.offsetWidth).toEqual(workspaceElement.offsetWidth)
it 'shrinks horizontal axis according to header/footer panels height', ->
workspaceElement = atom.views.getView(atom.workspace)
workspaceElement.style.height = '100px'
horizontalAxisElement = workspaceElement.querySelector('atom-workspace-axis.horizontal')
jasmine.attachToDOM(workspaceElement)
originalHorizontalAxisHeight = horizontalAxisElement.offsetHeight
expect(workspaceElement.offsetHeight).toBeGreaterThan(0)
expect(originalHorizontalAxisHeight).toBeGreaterThan(0)
headerItem = document.createElement('div')
headerItem.style.height = '10px'
atom.workspace.addHeaderPanel({item: headerItem})
expect(headerItem.offsetHeight).toBeGreaterThan(0)
footerItem = document.createElement('div')
footerItem.style.height = '15px'
atom.workspace.addFooterPanel({item: footerItem})
expect(footerItem.offsetHeight).toBeGreaterThan(0)
expect(horizontalAxisElement.offsetHeight).toEqual(originalHorizontalAxisHeight - headerItem.offsetHeight - footerItem.offsetHeight)
describe "the 'window:toggle-invisibles' command", ->
it "shows/hides invisibles in all open and future editors", ->
workspaceElement = atom.views.getView(atom.workspace)
expect(atom.config.get('editor.showInvisibles')).toBe false
atom.commands.dispatch(workspaceElement, 'window:toggle-invisibles')
expect(atom.config.get('editor.showInvisibles')).toBe true
atom.commands.dispatch(workspaceElement, 'window:toggle-invisibles')
expect(atom.config.get('editor.showInvisibles')).toBe false
describe "the 'window:run-package-specs' command", ->
it "runs the package specs for the active item's project path, or the first project path", ->
workspaceElement = atom.views.getView(atom.workspace)
spyOn(ipcRenderer, 'send')
# No project paths. Don't try to run specs.
atom.commands.dispatch(workspaceElement, "window:run-package-specs")
expect(ipcRenderer.send).not.toHaveBeenCalledWith("run-package-specs")
projectPaths = [temp.mkdirSync("dir1-"), temp.mkdirSync("dir2-")]
atom.project.setPaths(projectPaths)
# No active item. Use first project directory.
atom.commands.dispatch(workspaceElement, "window:run-package-specs")
expect(ipcRenderer.send).toHaveBeenCalledWith("run-package-specs", path.join(projectPaths[0], "spec"))
ipcRenderer.send.reset()
# Active item doesn't implement ::getPath(). Use first project directory.
item = document.createElement("div")
atom.workspace.getActivePane().activateItem(item)
atom.commands.dispatch(workspaceElement, "window:run-package-specs")
expect(ipcRenderer.send).toHaveBeenCalledWith("run-package-specs", path.join(projectPaths[0], "spec"))
ipcRenderer.send.reset()
# Active item has no path. Use first project directory.
item.getPath = -> null
atom.commands.dispatch(workspaceElement, "window:run-package-specs")
expect(ipcRenderer.send).toHaveBeenCalledWith("run-package-specs", path.join(projectPaths[0], "spec"))
ipcRenderer.send.reset()
# Active item has path. Use project path for item path.
item.getPath = -> path.join(projectPaths[1], "a-file.txt")
atom.commands.dispatch(workspaceElement, "window:run-package-specs")
expect(ipcRenderer.send).toHaveBeenCalledWith("run-package-specs", path.join(projectPaths[1], "spec"))
ipcRenderer.send.reset()

View File

@@ -0,0 +1,232 @@
'use strict'
/* global getComputedStyle, WheelEvent */
const {ipcRenderer} = require('electron')
const path = require('path')
const temp = require('temp').track()
const {Disposable} = require('event-kit')
describe('WorkspaceElement', () => {
afterEach(() => { temp.cleanupSync() })
describe('when the workspace element is focused', () => {
it('transfers focus to the active pane', () => {
const workspaceElement = atom.views.getView(atom.workspace)
jasmine.attachToDOM(workspaceElement)
const activePaneElement = atom.views.getView(atom.workspace.getActivePane())
document.body.focus()
expect(document.activeElement).not.toBe(activePaneElement)
workspaceElement.focus()
expect(document.activeElement).toBe(activePaneElement)
})
})
describe('the scrollbar visibility class', () => {
it('has a class based on the style of the scrollbar', () => {
let observeCallback
const scrollbarStyle = require('scrollbar-style')
spyOn(scrollbarStyle, 'observePreferredScrollbarStyle').andCallFake(cb => {
observeCallback = cb
return new Disposable(() => {})
})
const workspaceElement = atom.views.getView(atom.workspace)
observeCallback('legacy')
expect(workspaceElement.className).toMatch('scrollbars-visible-always')
observeCallback('overlay')
expect(workspaceElement).toHaveClass('scrollbars-visible-when-scrolling')
})
})
describe('editor font styling', () => {
let editor, editorElement, workspaceElement
beforeEach(() => {
waitsForPromise(() => atom.workspace.open('sample.js'))
runs(() => {
workspaceElement = atom.views.getView(atom.workspace)
jasmine.attachToDOM(workspaceElement)
editor = atom.workspace.getActiveTextEditor()
editorElement = atom.views.getView(editor)
})
})
it("updates the font-size based on the 'editor.fontSize' config value", () => {
const initialCharWidth = editor.getDefaultCharWidth()
expect(getComputedStyle(editorElement).fontSize).toBe(atom.config.get('editor.fontSize') + 'px')
atom.config.set('editor.fontSize', atom.config.get('editor.fontSize') + 5)
expect(getComputedStyle(editorElement).fontSize).toBe(atom.config.get('editor.fontSize') + 'px')
expect(editor.getDefaultCharWidth()).toBeGreaterThan(initialCharWidth)
})
it("updates the font-family based on the 'editor.fontFamily' config value", () => {
const initialCharWidth = editor.getDefaultCharWidth()
let fontFamily = atom.config.get('editor.fontFamily')
expect(getComputedStyle(editorElement).fontFamily).toBe(fontFamily)
atom.config.set('editor.fontFamily', 'sans-serif')
fontFamily = atom.config.get('editor.fontFamily')
expect(getComputedStyle(editorElement).fontFamily).toBe(fontFamily)
expect(editor.getDefaultCharWidth()).not.toBe(initialCharWidth)
})
it("updates the line-height based on the 'editor.lineHeight' config value", () => {
const initialLineHeight = editor.getLineHeightInPixels()
atom.config.set('editor.lineHeight', '30px')
expect(getComputedStyle(editorElement).lineHeight).toBe(atom.config.get('editor.lineHeight'))
expect(editor.getLineHeightInPixels()).not.toBe(initialLineHeight)
})
it('increases or decreases the font size when a ctrl-mousewheel event occurs', () => {
atom.config.set('editor.zoomFontWhenCtrlScrolling', true)
atom.config.set('editor.fontSize', 12)
// Zoom out
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: -10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(11)
// Zoom in
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
// Not on an atom-text-editor
workspaceElement.dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
// No ctrl key
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
atom.config.set('editor.zoomFontWhenCtrlScrolling', false)
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
})
})
describe('panel containers', () => {
it('inserts panel container elements in the correct places in the DOM', () => {
const workspaceElement = atom.views.getView(atom.workspace)
const leftContainer = workspaceElement.querySelector('atom-panel-container.left')
const rightContainer = workspaceElement.querySelector('atom-panel-container.right')
expect(leftContainer.nextSibling).toBe(workspaceElement.verticalAxis)
expect(rightContainer.previousSibling).toBe(workspaceElement.verticalAxis)
const topContainer = workspaceElement.querySelector('atom-panel-container.top')
const bottomContainer = workspaceElement.querySelector('atom-panel-container.bottom')
expect(topContainer.nextSibling).toBe(workspaceElement.paneContainer)
expect(bottomContainer.previousSibling).toBe(workspaceElement.paneContainer)
const headerContainer = workspaceElement.querySelector('atom-panel-container.header')
const footerContainer = workspaceElement.querySelector('atom-panel-container.footer')
expect(headerContainer.nextSibling).toBe(workspaceElement.horizontalAxis)
expect(footerContainer.previousSibling).toBe(workspaceElement.horizontalAxis)
const modalContainer = workspaceElement.querySelector('atom-panel-container.modal')
expect(modalContainer.parentNode).toBe(workspaceElement)
})
it('stretches header/footer panels to the workspace width', () => {
const workspaceElement = atom.views.getView(atom.workspace)
jasmine.attachToDOM(workspaceElement)
expect(workspaceElement.offsetWidth).toBeGreaterThan(0)
const headerItem = document.createElement('div')
atom.workspace.addHeaderPanel({item: headerItem})
expect(headerItem.offsetWidth).toEqual(workspaceElement.offsetWidth)
const footerItem = document.createElement('div')
atom.workspace.addFooterPanel({item: footerItem})
expect(footerItem.offsetWidth).toEqual(workspaceElement.offsetWidth)
})
it('shrinks horizontal axis according to header/footer panels height', () => {
const workspaceElement = atom.views.getView(atom.workspace)
workspaceElement.style.height = '100px'
const horizontalAxisElement = workspaceElement.querySelector('atom-workspace-axis.horizontal')
jasmine.attachToDOM(workspaceElement)
const originalHorizontalAxisHeight = horizontalAxisElement.offsetHeight
expect(workspaceElement.offsetHeight).toBeGreaterThan(0)
expect(originalHorizontalAxisHeight).toBeGreaterThan(0)
const headerItem = document.createElement('div')
headerItem.style.height = '10px'
atom.workspace.addHeaderPanel({item: headerItem})
expect(headerItem.offsetHeight).toBeGreaterThan(0)
const footerItem = document.createElement('div')
footerItem.style.height = '15px'
atom.workspace.addFooterPanel({item: footerItem})
expect(footerItem.offsetHeight).toBeGreaterThan(0)
expect(horizontalAxisElement.offsetHeight).toEqual(originalHorizontalAxisHeight - headerItem.offsetHeight - footerItem.offsetHeight)
})
})
describe("the 'window:toggle-invisibles' command", () => {
it('shows/hides invisibles in all open and future editors', () => {
const workspaceElement = atom.views.getView(atom.workspace)
expect(atom.config.get('editor.showInvisibles')).toBe(false)
atom.commands.dispatch(workspaceElement, 'window:toggle-invisibles')
expect(atom.config.get('editor.showInvisibles')).toBe(true)
atom.commands.dispatch(workspaceElement, 'window:toggle-invisibles')
expect(atom.config.get('editor.showInvisibles')).toBe(false)
})
})
describe("the 'window:run-package-specs' command", () => {
it("runs the package specs for the active item's project path, or the first project path", () => {
const workspaceElement = atom.views.getView(atom.workspace)
spyOn(ipcRenderer, 'send')
// No project paths. Don't try to run specs.
atom.commands.dispatch(workspaceElement, 'window:run-package-specs')
expect(ipcRenderer.send).not.toHaveBeenCalledWith('run-package-specs')
const projectPaths = [temp.mkdirSync('dir1-'), temp.mkdirSync('dir2-')]
atom.project.setPaths(projectPaths)
// No active item. Use first project directory.
atom.commands.dispatch(workspaceElement, 'window:run-package-specs')
expect(ipcRenderer.send).toHaveBeenCalledWith('run-package-specs', path.join(projectPaths[0], 'spec'))
ipcRenderer.send.reset()
// Active item doesn't implement ::getPath(). Use first project directory.
const item = document.createElement('div')
atom.workspace.getActivePane().activateItem(item)
atom.commands.dispatch(workspaceElement, 'window:run-package-specs')
expect(ipcRenderer.send).toHaveBeenCalledWith('run-package-specs', path.join(projectPaths[0], 'spec'))
ipcRenderer.send.reset()
// Active item has no path. Use first project directory.
item.getPath = () => null
atom.commands.dispatch(workspaceElement, 'window:run-package-specs')
expect(ipcRenderer.send).toHaveBeenCalledWith('run-package-specs', path.join(projectPaths[0], 'spec'))
ipcRenderer.send.reset()
// Active item has path. Use project path for item path.
item.getPath = () => path.join(projectPaths[1], 'a-file.txt')
atom.commands.dispatch(workspaceElement, 'window:run-package-specs')
expect(ipcRenderer.send).toHaveBeenCalledWith('run-package-specs', path.join(projectPaths[1], 'spec'))
ipcRenderer.send.reset()
})
})
})

File diff suppressed because it is too large Load Diff

2091
spec/workspace-spec.js Normal file

File diff suppressed because it is too large Load Diff