2013-03-26 04:57:30 +04:00
|
|
|
|
$ = require 'jquery'
|
2012-12-19 06:47:20 +04:00
|
|
|
|
RootView = require 'root-view'
|
2013-01-04 02:10:11 +04:00
|
|
|
|
{$$} = require 'space-pen'
|
2013-03-13 01:42:24 +04:00
|
|
|
|
fs = require 'fs-utils'
|
2012-12-19 06:47:20 +04:00
|
|
|
|
|
2013-02-08 02:37:48 +04:00
|
|
|
|
describe "the `atom` global", ->
|
2013-02-08 00:17:34 +04:00
|
|
|
|
beforeEach ->
|
2013-02-20 04:18:25 +04:00
|
|
|
|
window.rootView = new RootView
|
2013-02-08 23:51:51 +04:00
|
|
|
|
|
2013-03-25 20:57:58 +04:00
|
|
|
|
describe "package lifecycle methods", ->
|
|
|
|
|
describe ".activatePackage(id)", ->
|
2013-03-26 03:55:21 +04:00
|
|
|
|
describe "atom packages", ->
|
2013-03-26 04:57:30 +04:00
|
|
|
|
describe "when the package has a main module", ->
|
|
|
|
|
describe "when the metadata specifies a main module path˜", ->
|
|
|
|
|
it "requires the module at the specified path", ->
|
|
|
|
|
mainModule = require('package-with-main/main-module')
|
|
|
|
|
spyOn(mainModule, 'activate')
|
|
|
|
|
pack = atom.activatePackage('package-with-main')
|
|
|
|
|
expect(mainModule.activate).toHaveBeenCalled()
|
|
|
|
|
expect(pack.mainModule).toBe mainModule
|
|
|
|
|
|
|
|
|
|
describe "when the metadata does not specify a main module", ->
|
|
|
|
|
it "requires index.coffee", ->
|
|
|
|
|
indexModule = require('package-with-index/index')
|
|
|
|
|
spyOn(indexModule, 'activate')
|
|
|
|
|
pack = atom.activatePackage('package-with-index')
|
|
|
|
|
expect(indexModule.activate).toHaveBeenCalled()
|
|
|
|
|
expect(pack.mainModule).toBe indexModule
|
|
|
|
|
|
|
|
|
|
describe "when the package has no main module", ->
|
|
|
|
|
it "does not throw an exception", ->
|
|
|
|
|
spyOn(console, "error")
|
|
|
|
|
spyOn(console, "warn").andCallThrough()
|
|
|
|
|
expect(-> atom.activatePackage('package-without-module')).not.toThrow()
|
|
|
|
|
expect(console.error).not.toHaveBeenCalled()
|
|
|
|
|
expect(console.warn).not.toHaveBeenCalled()
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
2013-03-26 20:50:40 +04:00
|
|
|
|
it "passes the activate method the package's previously serialized state if it exists", ->
|
2013-03-26 04:57:30 +04:00
|
|
|
|
pack = atom.activatePackage("package-with-serialization")
|
2013-03-26 03:55:21 +04:00
|
|
|
|
expect(pack.mainModule.someNumber).not.toBe 77
|
|
|
|
|
pack.mainModule.someNumber = 77
|
2013-03-26 04:57:30 +04:00
|
|
|
|
atom.deactivatePackage("package-with-serialization")
|
2013-03-26 03:55:21 +04:00
|
|
|
|
spyOn(pack.mainModule, 'activate').andCallThrough()
|
2013-03-26 04:57:30 +04:00
|
|
|
|
atom.activatePackage("package-with-serialization")
|
2013-03-26 03:55:21 +04:00
|
|
|
|
expect(pack.mainModule.activate).toHaveBeenCalledWith({someNumber: 77})
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
2013-03-26 20:50:40 +04:00
|
|
|
|
it "logs warning instead of throwing an exception if the package fails to load", ->
|
2013-03-26 03:55:21 +04:00
|
|
|
|
config.set("core.disabledPackages", [])
|
|
|
|
|
spyOn(console, "warn")
|
|
|
|
|
expect(-> atom.activatePackage("package-that-throws-an-exception")).not.toThrow()
|
|
|
|
|
expect(console.warn).toHaveBeenCalled()
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
2013-03-26 03:55:21 +04:00
|
|
|
|
describe "keymap loading", ->
|
2013-03-26 04:57:30 +04:00
|
|
|
|
describe "when the metadata does not contain a 'keymaps' manifest", ->
|
2013-03-26 03:55:21 +04:00
|
|
|
|
it "loads all the .cson/.json files in the keymaps directory", ->
|
|
|
|
|
element1 = $$ -> @div class: 'test-1'
|
|
|
|
|
element2 = $$ -> @div class: 'test-2'
|
|
|
|
|
element3 = $$ -> @div class: 'test-3'
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
2013-03-26 03:55:21 +04:00
|
|
|
|
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBeUndefined()
|
|
|
|
|
expect(keymap.bindingsForElement(element2)['ctrl-z']).toBeUndefined()
|
|
|
|
|
expect(keymap.bindingsForElement(element3)['ctrl-z']).toBeUndefined()
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
2013-03-26 04:57:30 +04:00
|
|
|
|
atom.activatePackage("package-with-keymaps")
|
2013-01-28 10:38:11 +04:00
|
|
|
|
|
2013-03-26 03:55:21 +04:00
|
|
|
|
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBe "test-1"
|
|
|
|
|
expect(keymap.bindingsForElement(element2)['ctrl-z']).toBe "test-2"
|
|
|
|
|
expect(keymap.bindingsForElement(element3)['ctrl-z']).toBeUndefined()
|
2013-02-09 05:19:45 +04:00
|
|
|
|
|
2013-03-26 04:57:30 +04:00
|
|
|
|
describe "when the metadata contains a 'keymaps' manifest", ->
|
2013-03-26 03:55:21 +04:00
|
|
|
|
it "loads only the keymaps specified by the manifest, in the specified order", ->
|
|
|
|
|
element1 = $$ -> @div class: 'test-1'
|
|
|
|
|
element3 = $$ -> @div class: 'test-3'
|
2013-03-23 06:46:32 +04:00
|
|
|
|
|
2013-03-26 03:55:21 +04:00
|
|
|
|
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBeUndefined()
|
2013-03-23 06:46:32 +04:00
|
|
|
|
|
2013-03-26 03:55:21 +04:00
|
|
|
|
atom.activatePackage("package-with-keymaps-manifest")
|
2013-02-09 05:19:45 +04:00
|
|
|
|
|
2013-03-26 03:55:21 +04:00
|
|
|
|
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBe 'keymap-1'
|
|
|
|
|
expect(keymap.bindingsForElement(element1)['ctrl-n']).toBe 'keymap-2'
|
|
|
|
|
expect(keymap.bindingsForElement(element3)['ctrl-y']).toBeUndefined()
|
2013-02-09 05:19:45 +04:00
|
|
|
|
|
2013-03-26 04:57:30 +04:00
|
|
|
|
describe "stylesheet loading", ->
|
|
|
|
|
describe "when the metadata contains a 'stylesheets' manifest", ->
|
2013-03-26 20:50:40 +04:00
|
|
|
|
it "loads stylesheets from the stylesheets directory as specified by the manifest", ->
|
|
|
|
|
one = fs.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/1.css")
|
|
|
|
|
two = fs.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/2.less")
|
|
|
|
|
three = fs.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/3.css")
|
|
|
|
|
expect(stylesheetElementForId(one)).not.toExist()
|
|
|
|
|
expect(stylesheetElementForId(two)).not.toExist()
|
|
|
|
|
expect(stylesheetElementForId(three)).not.toExist()
|
|
|
|
|
|
|
|
|
|
atom.activatePackage("package-with-stylesheets-manifest")
|
|
|
|
|
|
|
|
|
|
expect(stylesheetElementForId(one)).toExist()
|
|
|
|
|
expect(stylesheetElementForId(two)).toExist()
|
|
|
|
|
expect(stylesheetElementForId(three)).not.toExist()
|
|
|
|
|
expect($('#jasmine-content').css('font-size')).toBe '1px'
|
2013-03-26 04:57:30 +04:00
|
|
|
|
|
|
|
|
|
describe "when the metadata does not contains a 'stylesheets' manifest", ->
|
|
|
|
|
it "loads all stylesheets from the stylesheets directory", ->
|
|
|
|
|
one = fs.resolveOnLoadPath("package-with-stylesheets/stylesheets/1.css")
|
|
|
|
|
two = fs.resolveOnLoadPath("package-with-stylesheets/stylesheets/2.less")
|
|
|
|
|
three = fs.resolveOnLoadPath("package-with-stylesheets/stylesheets/3.css")
|
|
|
|
|
expect(stylesheetElementForId(one)).not.toExist()
|
|
|
|
|
expect(stylesheetElementForId(two)).not.toExist()
|
|
|
|
|
expect(stylesheetElementForId(three)).not.toExist()
|
|
|
|
|
|
|
|
|
|
atom.activatePackage("package-with-stylesheets")
|
|
|
|
|
expect(stylesheetElementForId(one)).toExist()
|
|
|
|
|
expect(stylesheetElementForId(two)).toExist()
|
|
|
|
|
expect(stylesheetElementForId(three)).toExist()
|
|
|
|
|
expect($('#jasmine-content').css('font-size')).toBe '3px'
|
2013-03-26 03:55:21 +04:00
|
|
|
|
|
2013-03-26 21:21:44 +04:00
|
|
|
|
describe "grammar loading", ->
|
|
|
|
|
it "loads the package's grammars", ->
|
|
|
|
|
atom.activatePackage('package-with-grammars')
|
|
|
|
|
expect(syntax.selectGrammar('a.alot').name).toBe 'Alot'
|
|
|
|
|
expect(syntax.selectGrammar('a.alittle').name).toBe 'Alittle'
|
|
|
|
|
|
2013-03-26 03:55:21 +04:00
|
|
|
|
describe "textmate packages", ->
|
|
|
|
|
it "loads the package's grammars", ->
|
|
|
|
|
expect(syntax.selectGrammar("file.rb").name).toBe "Null Grammar"
|
|
|
|
|
atom.activatePackage('ruby.tmbundle', sync: true)
|
|
|
|
|
expect(syntax.selectGrammar("file.rb").name).toBe "Ruby"
|
2013-03-25 20:57:58 +04:00
|
|
|
|
|
|
|
|
|
describe ".deactivatePackage(id)", ->
|
2013-03-26 03:55:21 +04:00
|
|
|
|
describe "atom packages", ->
|
2013-03-26 21:00:29 +04:00
|
|
|
|
it "calls `deactivate` on the package's main module", ->
|
|
|
|
|
pack = atom.activatePackage("package-with-deactivate")
|
|
|
|
|
expect(atom.isPackageActive("package-with-deactivate")).toBeTruthy()
|
2013-03-26 03:55:21 +04:00
|
|
|
|
spyOn(pack.mainModule, 'deactivate').andCallThrough()
|
|
|
|
|
|
2013-03-26 21:00:29 +04:00
|
|
|
|
atom.deactivatePackage("package-with-deactivate")
|
2013-03-26 03:55:21 +04:00
|
|
|
|
expect(pack.mainModule.deactivate).toHaveBeenCalled()
|
2013-03-26 21:00:29 +04:00
|
|
|
|
expect(atom.isPackageActive("package-with-module")).toBeFalsy()
|
2013-03-26 03:55:21 +04:00
|
|
|
|
|
|
|
|
|
it "absorbs exceptions that are thrown by the package module's serialize methods", ->
|
|
|
|
|
spyOn(console, 'error')
|
|
|
|
|
atom.activatePackage('package-with-serialize-error', immediate: true)
|
2013-03-26 21:00:29 +04:00
|
|
|
|
atom.activatePackage('package-with-serialization', immediate: true)
|
2013-03-26 03:55:21 +04:00
|
|
|
|
atom.deactivatePackages()
|
|
|
|
|
expect(atom.packageStates['package-with-serialize-error']).toBeUndefined()
|
2013-03-26 21:00:29 +04:00
|
|
|
|
expect(atom.packageStates['package-with-serialization']).toEqual someNumber: 1
|
2013-03-26 03:55:21 +04:00
|
|
|
|
expect(console.error).toHaveBeenCalled()
|
|
|
|
|
|
2013-03-26 21:25:09 +04:00
|
|
|
|
it "removes the package's grammars", ->
|
|
|
|
|
atom.activatePackage('package-with-grammars')
|
|
|
|
|
atom.deactivatePackage('package-with-grammars')
|
|
|
|
|
expect(syntax.selectGrammar('a.alot').name).toBe 'Null Grammar'
|
|
|
|
|
expect(syntax.selectGrammar('a.alittle').name).toBe 'Null Grammar'
|
|
|
|
|
|
2013-03-26 22:03:48 +04:00
|
|
|
|
it "removes the package's keymaps", ->
|
|
|
|
|
atom.activatePackage('package-with-keymaps')
|
|
|
|
|
atom.deactivatePackage('package-with-keymaps')
|
|
|
|
|
expect(keymap.bindingsForElement($$ -> @div class: 'test-1')['ctrl-z']).toBeUndefined()
|
|
|
|
|
expect(keymap.bindingsForElement($$ -> @div class: 'test-2')['ctrl-z']).toBeUndefined()
|
|
|
|
|
|
2013-03-26 03:55:21 +04:00
|
|
|
|
describe "texmate packages", ->
|
|
|
|
|
it "removes the package's grammars", ->
|
|
|
|
|
expect(syntax.selectGrammar("file.rb").name).toBe "Null Grammar"
|
|
|
|
|
atom.activatePackage('ruby.tmbundle', sync: true)
|
|
|
|
|
expect(syntax.selectGrammar("file.rb").name).toBe "Ruby"
|
|
|
|
|
atom.deactivatePackage('ruby.tmbundle')
|
|
|
|
|
expect(syntax.selectGrammar("file.rb").name).toBe "Null Grammar"
|
2013-02-25 23:25:11 +04:00
|
|
|
|
|
|
|
|
|
describe ".getVersion(callback)", ->
|
|
|
|
|
it "calls the callback with the current version number", ->
|
|
|
|
|
versionHandler = jasmine.createSpy("versionHandler")
|
|
|
|
|
atom.getVersion(versionHandler)
|
|
|
|
|
waitsFor ->
|
|
|
|
|
versionHandler.callCount > 0
|
|
|
|
|
|
|
|
|
|
runs ->
|
2013-02-28 22:15:24 +04:00
|
|
|
|
expect(versionHandler.argsForCall[0][0]).toMatch /^\d+\.\d+(\.\d+)?$/
|
2013-03-02 02:52:21 +04:00
|
|
|
|
|
|
|
|
|
describe "modal native dialogs", ->
|
|
|
|
|
beforeEach ->
|
|
|
|
|
spyOn(atom, 'sendMessageToBrowserProcess')
|
|
|
|
|
atom.sendMessageToBrowserProcess.simulateConfirmation = (buttonText) ->
|
|
|
|
|
labels = @argsForCall[0][1][2...]
|
|
|
|
|
callbacks = @argsForCall[0][2]
|
|
|
|
|
@reset()
|
|
|
|
|
callbacks[labels.indexOf(buttonText)]()
|
2013-03-02 03:27:13 +04:00
|
|
|
|
advanceClock 50
|
2013-03-02 02:52:21 +04:00
|
|
|
|
|
|
|
|
|
atom.sendMessageToBrowserProcess.simulatePathSelection = (path) ->
|
|
|
|
|
callback = @argsForCall[0][2]
|
|
|
|
|
@reset()
|
|
|
|
|
callback(path)
|
2013-03-02 03:27:13 +04:00
|
|
|
|
advanceClock 50
|
2013-03-02 02:52:21 +04:00
|
|
|
|
|
|
|
|
|
it "only presents one native dialog at a time", ->
|
|
|
|
|
confirmHandler = jasmine.createSpy("confirmHandler")
|
|
|
|
|
selectPathHandler = jasmine.createSpy("selectPathHandler")
|
|
|
|
|
|
|
|
|
|
atom.confirm "Are you happy?", "really, truly happy?", "Yes", confirmHandler, "No"
|
|
|
|
|
atom.confirm "Are you happy?", "really, truly happy?", "Yes", confirmHandler, "No"
|
|
|
|
|
atom.showSaveDialog(selectPathHandler)
|
|
|
|
|
atom.showSaveDialog(selectPathHandler)
|
|
|
|
|
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.callCount).toBe 1
|
|
|
|
|
atom.sendMessageToBrowserProcess.simulateConfirmation("Yes")
|
|
|
|
|
expect(confirmHandler).toHaveBeenCalled()
|
|
|
|
|
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.callCount).toBe 1
|
|
|
|
|
atom.sendMessageToBrowserProcess.simulateConfirmation("No")
|
|
|
|
|
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.callCount).toBe 1
|
|
|
|
|
atom.sendMessageToBrowserProcess.simulatePathSelection('/selected/path')
|
|
|
|
|
expect(selectPathHandler).toHaveBeenCalledWith('/selected/path')
|
|
|
|
|
selectPathHandler.reset()
|
|
|
|
|
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.callCount).toBe 1
|
|
|
|
|
|
|
|
|
|
it "prioritizes dialogs presented as the result of dismissing other dialogs before any previously deferred dialogs", ->
|
|
|
|
|
atom.confirm "A1", "", "Next", ->
|
|
|
|
|
atom.confirm "B1", "", "Next", ->
|
|
|
|
|
atom.confirm "C1", "", "Next", ->
|
|
|
|
|
atom.confirm "C2", "", "Next", ->
|
|
|
|
|
atom.confirm "B2", "", "Next", ->
|
|
|
|
|
atom.confirm "A2", "", "Next", ->
|
|
|
|
|
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.callCount).toBe 1
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.argsForCall[0][1][0]).toBe "A1"
|
|
|
|
|
atom.sendMessageToBrowserProcess.simulateConfirmation('Next')
|
|
|
|
|
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.callCount).toBe 1
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.argsForCall[0][1][0]).toBe "B1"
|
|
|
|
|
atom.sendMessageToBrowserProcess.simulateConfirmation('Next')
|
|
|
|
|
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.callCount).toBe 1
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.argsForCall[0][1][0]).toBe "C1"
|
|
|
|
|
atom.sendMessageToBrowserProcess.simulateConfirmation('Next')
|
|
|
|
|
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.callCount).toBe 1
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.argsForCall[0][1][0]).toBe "C2"
|
|
|
|
|
atom.sendMessageToBrowserProcess.simulateConfirmation('Next')
|
|
|
|
|
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.callCount).toBe 1
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.argsForCall[0][1][0]).toBe "B2"
|
|
|
|
|
atom.sendMessageToBrowserProcess.simulateConfirmation('Next')
|
|
|
|
|
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.callCount).toBe 1
|
|
|
|
|
expect(atom.sendMessageToBrowserProcess.argsForCall[0][1][0]).toBe "A2"
|
|
|
|
|
atom.sendMessageToBrowserProcess.simulateConfirmation('Next')
|