2013-09-25 19:39:16 +04:00
|
|
|
path = require 'path'
|
2014-01-17 23:08:43 +04:00
|
|
|
|
2014-11-25 23:55:50 +03:00
|
|
|
{$, $$} = require '../src/space-pen-extensions'
|
2014-02-24 05:19:00 +04:00
|
|
|
fs = require 'fs-plus'
|
2014-01-17 23:08:43 +04:00
|
|
|
temp = require 'temp'
|
2013-08-07 21:40:46 +04:00
|
|
|
|
2013-09-18 05:58:41 +04:00
|
|
|
ThemeManager = require '../src/theme-manager'
|
2014-02-18 00:59:03 +04:00
|
|
|
Package = require '../src/package'
|
2013-08-07 21:40:46 +04:00
|
|
|
|
2013-10-19 04:42:09 +04:00
|
|
|
describe "ThemeManager", ->
|
2013-08-20 06:45:13 +04:00
|
|
|
themeManager = null
|
2013-10-15 04:58:53 +04:00
|
|
|
resourcePath = atom.getLoadSettings().resourcePath
|
2013-11-11 23:47:24 +04:00
|
|
|
configDirPath = atom.getConfigDirPath()
|
2013-08-20 06:45:13 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2013-11-11 23:47:24 +04:00
|
|
|
themeManager = new ThemeManager({packageManager: atom.packages, resourcePath, configDirPath})
|
2013-08-20 06:45:13 +04:00
|
|
|
|
|
|
|
afterEach ->
|
2013-10-19 02:24:39 +04:00
|
|
|
themeManager.deactivateThemes()
|
|
|
|
|
|
|
|
describe "theme getters and setters", ->
|
|
|
|
beforeEach ->
|
2014-11-26 02:24:46 +03:00
|
|
|
jasmine.snapshotDeprecations()
|
2014-05-21 19:55:40 +04:00
|
|
|
atom.packages.loadPackages()
|
2013-10-19 02:24:39 +04:00
|
|
|
|
2014-11-26 02:24:46 +03:00
|
|
|
afterEach ->
|
|
|
|
jasmine.restoreDeprecationsSnapshot()
|
|
|
|
|
2013-10-19 02:24:39 +04:00
|
|
|
it 'getLoadedThemes get all the loaded themes', ->
|
|
|
|
themes = themeManager.getLoadedThemes()
|
2013-10-21 22:37:01 +04:00
|
|
|
expect(themes.length).toBeGreaterThan(2)
|
2013-10-19 02:24:39 +04:00
|
|
|
|
|
|
|
it 'getActiveThemes get all the active themes', ->
|
2014-02-07 23:21:52 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
themeManager.activateThemes()
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
names = atom.config.get('core.themes')
|
|
|
|
expect(names.length).toBeGreaterThan(0)
|
|
|
|
themes = themeManager.getActiveThemes()
|
|
|
|
expect(themes).toHaveLength(names.length)
|
2013-08-20 06:45:13 +04:00
|
|
|
|
2014-04-18 00:31:43 +04:00
|
|
|
describe "when the core.themes config value contains invalid entry", ->
|
2014-04-22 20:51:00 +04:00
|
|
|
it "ignores theme", ->
|
2014-04-18 00:31:43 +04:00
|
|
|
atom.config.set 'core.themes', [
|
|
|
|
'atom-light-ui'
|
|
|
|
null
|
|
|
|
undefined
|
|
|
|
''
|
|
|
|
false
|
|
|
|
4
|
|
|
|
{}
|
|
|
|
[]
|
|
|
|
'atom-dark-ui'
|
|
|
|
]
|
|
|
|
|
|
|
|
expect(themeManager.getEnabledThemeNames()).toEqual ['atom-dark-ui', 'atom-light-ui']
|
|
|
|
|
2014-10-01 00:01:41 +04:00
|
|
|
describe "::getImportPaths()", ->
|
2013-09-03 23:22:32 +04:00
|
|
|
it "returns the theme directories before the themes are loaded", ->
|
2013-12-07 01:24:34 +04:00
|
|
|
atom.config.set('core.themes', ['theme-with-index-less', 'atom-dark-ui', 'atom-light-ui'])
|
2013-09-03 23:22:32 +04:00
|
|
|
|
|
|
|
paths = themeManager.getImportPaths()
|
|
|
|
|
|
|
|
# syntax theme is not a dir at this time, so only two.
|
|
|
|
expect(paths.length).toBe 2
|
2014-01-16 05:42:17 +04:00
|
|
|
expect(paths[0]).toContain 'atom-light-ui'
|
|
|
|
expect(paths[1]).toContain 'atom-dark-ui'
|
2013-09-03 23:22:32 +04:00
|
|
|
|
2013-10-02 22:24:24 +04:00
|
|
|
it "ignores themes that cannot be resolved to a directory", ->
|
2013-11-11 21:16:44 +04:00
|
|
|
atom.config.set('core.themes', ['definitely-not-a-theme'])
|
2013-10-02 22:24:24 +04:00
|
|
|
expect(-> themeManager.getImportPaths()).not.toThrow()
|
|
|
|
|
2013-08-07 21:40:46 +04:00
|
|
|
describe "when the core.themes config value changes", ->
|
|
|
|
it "add/removes stylesheets to reflect the new config value", ->
|
2015-01-09 04:51:09 +03:00
|
|
|
themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy()
|
2014-11-19 20:31:03 +03:00
|
|
|
spyOn(atom.styles, 'getUserStyleSheetPath').andCallFake -> null
|
2013-08-14 04:01:45 +04:00
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
themeManager.activateThemes()
|
|
|
|
|
|
|
|
runs ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.reset()
|
2014-02-07 23:21:52 +04:00
|
|
|
atom.config.set('core.themes', [])
|
|
|
|
|
|
|
|
waitsFor ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.callCount == 1
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
runs ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.reset()
|
2014-02-07 23:21:52 +04:00
|
|
|
expect($('style.theme')).toHaveLength 0
|
2014-10-16 23:17:32 +04:00
|
|
|
atom.config.set('core.themes', ['atom-dark-ui'])
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
waitsFor ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.callCount == 1
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
runs ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.reset()
|
2015-01-07 06:08:45 +03:00
|
|
|
expect($('style[priority=1]')).toHaveLength 2
|
|
|
|
expect($('style[priority=1]:eq(0)').attr('source-path')).toMatch /atom-dark-ui/
|
2014-10-16 23:17:32 +04:00
|
|
|
atom.config.set('core.themes', ['atom-light-ui', 'atom-dark-ui'])
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
waitsFor ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.callCount == 1
|
2013-08-07 21:40:46 +04:00
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
runs ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.reset()
|
2015-01-07 06:08:45 +03:00
|
|
|
expect($('style[priority=1]')).toHaveLength 2
|
|
|
|
expect($('style[priority=1]:eq(0)').attr('source-path')).toMatch /atom-dark-ui/
|
|
|
|
expect($('style[priority=1]:eq(1)').attr('source-path')).toMatch /atom-light-ui/
|
2014-02-07 23:21:52 +04:00
|
|
|
atom.config.set('core.themes', [])
|
2013-08-07 21:40:46 +04:00
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
waitsFor ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.callCount == 1
|
2013-08-07 21:40:46 +04:00
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
runs ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.reset()
|
2015-01-07 06:08:45 +03:00
|
|
|
expect($('style[priority=1]')).toHaveLength 2
|
2014-02-07 23:21:52 +04:00
|
|
|
# atom-dark-ui has an directory path, the syntax one doesn't
|
|
|
|
atom.config.set('core.themes', ['theme-with-index-less', 'atom-dark-ui'])
|
2013-08-09 22:24:21 +04:00
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
waitsFor ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.callCount == 1
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
runs ->
|
2015-01-07 06:08:45 +03:00
|
|
|
expect($('style[priority=1]')).toHaveLength 2
|
2014-02-07 23:21:52 +04:00
|
|
|
importPaths = themeManager.getImportPaths()
|
|
|
|
expect(importPaths.length).toBe 1
|
|
|
|
expect(importPaths[0]).toContain 'atom-dark-ui'
|
2013-08-14 03:51:21 +04:00
|
|
|
|
2014-12-30 22:53:38 +03:00
|
|
|
it 'adds theme-* classes to the workspace for each active theme', ->
|
2015-03-17 01:11:12 +03:00
|
|
|
atom.config.set('core.themes', ['atom-dark-ui', 'atom-dark-syntax'])
|
2014-12-30 22:53:38 +03:00
|
|
|
workspaceElement = atom.views.getView(atom.workspace)
|
2015-01-09 04:51:09 +03:00
|
|
|
themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy()
|
2014-12-30 22:53:38 +03:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
themeManager.activateThemes()
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(workspaceElement).toHaveClass 'theme-atom-dark-ui'
|
|
|
|
|
2015-01-09 04:51:09 +03:00
|
|
|
themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy()
|
2014-12-30 22:53:38 +03:00
|
|
|
atom.config.set('core.themes', ['theme-with-ui-variables', 'theme-with-syntax-variables'])
|
|
|
|
|
|
|
|
waitsFor ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.callCount > 0
|
2014-12-30 22:53:38 +03:00
|
|
|
|
|
|
|
runs ->
|
|
|
|
# `theme-` twice as it prefixes the name with `theme-`
|
|
|
|
expect(workspaceElement).toHaveClass 'theme-theme-with-ui-variables'
|
|
|
|
expect(workspaceElement).toHaveClass 'theme-theme-with-syntax-variables'
|
|
|
|
expect(workspaceElement).not.toHaveClass 'theme-atom-dark-ui'
|
|
|
|
expect(workspaceElement).not.toHaveClass 'theme-atom-dark-syntax'
|
|
|
|
|
2013-08-09 22:24:21 +04:00
|
|
|
describe "when a theme fails to load", ->
|
|
|
|
it "logs a warning", ->
|
|
|
|
spyOn(console, 'warn')
|
2014-12-24 03:47:09 +03:00
|
|
|
atom.packages.activatePackage('a-theme-that-will-not-be-found')
|
|
|
|
expect(console.warn.callCount).toBe 1
|
|
|
|
expect(console.warn.argsForCall[0][0]).toContain "Could not resolve 'a-theme-that-will-not-be-found'"
|
2013-09-25 19:39:16 +04:00
|
|
|
|
2014-10-01 00:01:41 +04:00
|
|
|
describe "::requireStylesheet(path)", ->
|
2014-11-27 19:03:40 +03:00
|
|
|
beforeEach ->
|
|
|
|
jasmine.snapshotDeprecations()
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
jasmine.restoreDeprecationsSnapshot()
|
|
|
|
|
2013-09-25 19:39:16 +04:00
|
|
|
it "synchronously loads css at the given path and installs a style tag for it in the head", ->
|
2014-11-27 19:03:40 +03:00
|
|
|
atom.styles.onDidAddStyleElement styleElementAddedHandler = jasmine.createSpy("styleElementAddedHandler")
|
2014-09-10 02:35:00 +04:00
|
|
|
themeManager.onDidChangeStylesheets stylesheetsChangedHandler = jasmine.createSpy("stylesheetsChangedHandler")
|
|
|
|
themeManager.onDidAddStylesheet stylesheetAddedHandler = jasmine.createSpy("stylesheetAddedHandler")
|
2014-11-27 19:03:40 +03:00
|
|
|
|
2015-01-10 01:54:54 +03:00
|
|
|
cssPath = atom.project.getDirectories()[0]?.resolve('css.css')
|
2013-09-25 19:39:16 +04:00
|
|
|
lengthBefore = $('head style').length
|
|
|
|
|
|
|
|
themeManager.requireStylesheet(cssPath)
|
|
|
|
expect($('head style').length).toBe lengthBefore + 1
|
|
|
|
|
2014-11-27 19:03:40 +03:00
|
|
|
expect(styleElementAddedHandler).toHaveBeenCalled()
|
2014-05-06 04:54:22 +04:00
|
|
|
expect(stylesheetAddedHandler).toHaveBeenCalled()
|
|
|
|
expect(stylesheetsChangedHandler).toHaveBeenCalled()
|
|
|
|
|
2014-10-14 23:21:19 +04:00
|
|
|
element = $('head style[source-path*="css.css"]')
|
|
|
|
expect(element.attr('source-path')).toBe themeManager.stringToId(cssPath)
|
2013-11-01 01:58:01 +04:00
|
|
|
expect(element.text()).toBe fs.readFileSync(cssPath, 'utf8')
|
2014-05-06 04:54:22 +04:00
|
|
|
expect(element[0].sheet).toBe stylesheetAddedHandler.argsForCall[0][0]
|
2013-09-25 19:39:16 +04:00
|
|
|
|
|
|
|
# doesn't append twice
|
2014-11-27 19:03:40 +03:00
|
|
|
styleElementAddedHandler.reset()
|
2013-09-25 19:39:16 +04:00
|
|
|
themeManager.requireStylesheet(cssPath)
|
|
|
|
expect($('head style').length).toBe lengthBefore + 1
|
2014-11-27 19:03:40 +03:00
|
|
|
expect(styleElementAddedHandler).not.toHaveBeenCalled()
|
2013-09-25 19:39:16 +04:00
|
|
|
|
|
|
|
$('head style[id*="css.css"]').remove()
|
|
|
|
|
|
|
|
it "synchronously loads and parses less files at the given path and installs a style tag for it in the head", ->
|
2015-01-10 01:54:54 +03:00
|
|
|
lessPath = atom.project.getDirectories()[0]?.resolve('sample.less')
|
2013-09-25 19:39:16 +04:00
|
|
|
lengthBefore = $('head style').length
|
|
|
|
themeManager.requireStylesheet(lessPath)
|
|
|
|
expect($('head style').length).toBe lengthBefore + 1
|
|
|
|
|
2014-10-14 23:21:19 +04:00
|
|
|
element = $('head style[source-path*="sample.less"]')
|
|
|
|
expect(element.attr('source-path')).toBe themeManager.stringToId(lessPath)
|
2013-09-25 19:39:16 +04:00
|
|
|
expect(element.text()).toBe """
|
|
|
|
#header {
|
|
|
|
color: #4d926f;
|
|
|
|
}
|
|
|
|
h2 {
|
|
|
|
color: #4d926f;
|
|
|
|
}
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# doesn't append twice
|
|
|
|
themeManager.requireStylesheet(lessPath)
|
|
|
|
expect($('head style').length).toBe lengthBefore + 1
|
|
|
|
$('head style[id*="sample.less"]').remove()
|
|
|
|
|
|
|
|
it "supports requiring css and less stylesheets without an explicit extension", ->
|
|
|
|
themeManager.requireStylesheet path.join(__dirname, 'fixtures', 'css')
|
2015-01-10 01:54:54 +03:00
|
|
|
expect($('head style[source-path*="css.css"]').attr('source-path')).toBe themeManager.stringToId(atom.project.getDirectories()[0]?.resolve('css.css'))
|
2013-09-25 19:39:16 +04:00
|
|
|
themeManager.requireStylesheet path.join(__dirname, 'fixtures', 'sample')
|
2015-01-10 01:54:54 +03:00
|
|
|
expect($('head style[source-path*="sample.less"]').attr('source-path')).toBe themeManager.stringToId(atom.project.getDirectories()[0]?.resolve('sample.less'))
|
2013-09-25 19:39:16 +04:00
|
|
|
|
|
|
|
$('head style[id*="css.css"]').remove()
|
|
|
|
$('head style[id*="sample.less"]').remove()
|
|
|
|
|
2014-10-01 00:02:04 +04:00
|
|
|
it "returns a disposable allowing styles applied by the given path to be removed", ->
|
2013-09-25 19:39:16 +04:00
|
|
|
cssPath = require.resolve('./fixtures/css.css')
|
|
|
|
|
|
|
|
expect($(document.body).css('font-weight')).not.toBe("bold")
|
2014-10-01 00:02:04 +04:00
|
|
|
disposable = themeManager.requireStylesheet(cssPath)
|
2013-09-25 19:39:16 +04:00
|
|
|
expect($(document.body).css('font-weight')).toBe("bold")
|
2014-03-20 00:43:31 +04:00
|
|
|
|
2014-11-27 19:03:40 +03:00
|
|
|
atom.styles.onDidRemoveStyleElement styleElementRemovedHandler = jasmine.createSpy("styleElementRemovedHandler")
|
2014-09-10 02:35:00 +04:00
|
|
|
themeManager.onDidRemoveStylesheet stylesheetRemovedHandler = jasmine.createSpy("stylesheetRemovedHandler")
|
|
|
|
themeManager.onDidChangeStylesheets stylesheetsChangedHandler = jasmine.createSpy("stylesheetsChangedHandler")
|
2014-05-06 04:54:22 +04:00
|
|
|
|
2014-10-01 00:02:04 +04:00
|
|
|
disposable.dispose()
|
2014-05-06 04:54:22 +04:00
|
|
|
|
2013-09-25 19:39:16 +04:00
|
|
|
expect($(document.body).css('font-weight')).not.toBe("bold")
|
2014-05-06 04:54:22 +04:00
|
|
|
|
2014-11-27 19:03:40 +03:00
|
|
|
expect(styleElementRemovedHandler).toHaveBeenCalled()
|
2014-05-06 04:54:22 +04:00
|
|
|
expect(stylesheetRemovedHandler).toHaveBeenCalled()
|
|
|
|
stylesheet = stylesheetRemovedHandler.argsForCall[0][0]
|
|
|
|
expect(stylesheet instanceof CSSStyleSheet).toBe true
|
|
|
|
expect(stylesheet.cssRules[0].selectorText).toBe 'body'
|
|
|
|
|
2014-03-20 00:43:31 +04:00
|
|
|
expect(stylesheetsChangedHandler).toHaveBeenCalled()
|
2013-09-25 19:39:16 +04:00
|
|
|
|
2014-12-30 22:53:46 +03:00
|
|
|
describe "base style sheet loading", ->
|
2014-11-20 03:51:18 +03:00
|
|
|
workspaceElement = null
|
2013-09-25 19:39:16 +04:00
|
|
|
beforeEach ->
|
2014-11-20 03:51:18 +03:00
|
|
|
workspaceElement = atom.views.getView(atom.workspace)
|
|
|
|
jasmine.attachToDOM(workspaceElement)
|
|
|
|
workspaceElement.appendChild document.createElement('atom-text-editor')
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
themeManager.activateThemes()
|
2013-09-25 19:39:16 +04:00
|
|
|
|
|
|
|
it "loads the correct values from the theme's ui-variables file", ->
|
2015-01-09 04:51:09 +03:00
|
|
|
themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy()
|
2014-10-30 20:03:44 +03:00
|
|
|
atom.config.set('core.themes', ['theme-with-ui-variables', 'theme-with-syntax-variables'])
|
2013-09-25 19:39:16 +04:00
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
waitsFor ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.callCount > 0
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
runs ->
|
|
|
|
# an override loaded in the base css
|
2014-11-20 03:51:18 +03:00
|
|
|
expect(getComputedStyle(workspaceElement)["background-color"]).toBe "rgb(0, 0, 255)"
|
2013-09-25 19:39:16 +04:00
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
# from within the theme itself
|
2014-10-09 01:11:57 +04:00
|
|
|
expect($("atom-text-editor").css("padding-top")).toBe "150px"
|
|
|
|
expect($("atom-text-editor").css("padding-right")).toBe "150px"
|
|
|
|
expect($("atom-text-editor").css("padding-bottom")).toBe "150px"
|
2014-01-17 23:08:43 +04:00
|
|
|
|
2014-07-12 01:04:54 +04:00
|
|
|
describe "when there is a theme with incomplete variables", ->
|
|
|
|
it "loads the correct values from the fallback ui-variables", ->
|
2015-01-09 04:51:09 +03:00
|
|
|
themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy()
|
2014-10-30 20:03:44 +03:00
|
|
|
atom.config.set('core.themes', ['theme-with-incomplete-ui-variables', 'theme-with-syntax-variables'])
|
2014-07-12 01:04:54 +04:00
|
|
|
|
|
|
|
waitsFor ->
|
2015-01-09 04:51:09 +03:00
|
|
|
didChangeActiveThemesHandler.callCount > 0
|
2014-07-12 01:04:54 +04:00
|
|
|
|
|
|
|
runs ->
|
|
|
|
# an override loaded in the base css
|
2014-11-20 03:51:18 +03:00
|
|
|
expect(getComputedStyle(workspaceElement)["background-color"]).toBe "rgb(0, 0, 255)"
|
2014-07-12 01:04:54 +04:00
|
|
|
|
|
|
|
# from within the theme itself
|
2014-10-09 01:11:57 +04:00
|
|
|
expect($("atom-text-editor").css("background-color")).toBe "rgb(0, 152, 255)"
|
2014-07-12 01:04:54 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
describe "user stylesheet", ->
|
2015-01-14 03:00:00 +03:00
|
|
|
userStylesheetPath = null
|
|
|
|
beforeEach ->
|
|
|
|
userStylesheetPath = path.join(temp.mkdirSync("atom"), 'styles.less')
|
|
|
|
fs.writeFileSync(userStylesheetPath, 'body {border-style: dotted !important;}')
|
|
|
|
spyOn(atom.styles, 'getUserStyleSheetPath').andReturn userStylesheetPath
|
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
describe "when the user stylesheet changes", ->
|
|
|
|
beforeEach ->
|
|
|
|
jasmine.snapshotDeprecations()
|
2014-08-21 22:53:10 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
afterEach ->
|
|
|
|
jasmine.restoreDeprecationsSnapshot()
|
2014-11-27 19:03:40 +03:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
it "reloads it", ->
|
|
|
|
[styleElementAddedHandler, styleElementRemovedHandler] = []
|
|
|
|
[stylesheetRemovedHandler, stylesheetAddedHandler, stylesheetsChangedHandler] = []
|
2014-11-27 19:03:40 +03:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
waitsForPromise ->
|
|
|
|
themeManager.activateThemes()
|
2014-01-17 23:08:43 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
runs ->
|
|
|
|
atom.styles.onDidRemoveStyleElement styleElementRemovedHandler = jasmine.createSpy("styleElementRemovedHandler")
|
|
|
|
atom.styles.onDidAddStyleElement styleElementAddedHandler = jasmine.createSpy("styleElementAddedHandler")
|
2014-11-27 19:03:40 +03:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
themeManager.onDidChangeStylesheets stylesheetsChangedHandler = jasmine.createSpy("stylesheetsChangedHandler")
|
|
|
|
themeManager.onDidRemoveStylesheet stylesheetRemovedHandler = jasmine.createSpy("stylesheetRemovedHandler")
|
|
|
|
themeManager.onDidAddStylesheet stylesheetAddedHandler = jasmine.createSpy("stylesheetAddedHandler")
|
|
|
|
spyOn(themeManager, 'loadUserStylesheet').andCallThrough()
|
2014-05-06 04:54:22 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
expect($(document.body).css('border-style')).toBe 'dotted'
|
|
|
|
fs.writeFileSync(userStylesheetPath, 'body {border-style: dashed}')
|
2014-01-17 23:08:43 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
waitsFor ->
|
|
|
|
themeManager.loadUserStylesheet.callCount is 1
|
2014-01-17 23:08:43 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
runs ->
|
|
|
|
expect($(document.body).css('border-style')).toBe 'dashed'
|
2014-05-06 04:54:22 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
expect(styleElementRemovedHandler).toHaveBeenCalled()
|
|
|
|
expect(styleElementRemovedHandler.argsForCall[0][0].textContent).toContain 'dotted'
|
|
|
|
expect(stylesheetRemovedHandler).toHaveBeenCalled()
|
|
|
|
expect(stylesheetRemovedHandler.argsForCall[0][0].cssRules[0].style.border).toBe 'dotted'
|
2014-05-06 04:54:22 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
expect(styleElementAddedHandler).toHaveBeenCalled()
|
|
|
|
expect(styleElementAddedHandler.argsForCall[0][0].textContent).toContain 'dashed'
|
|
|
|
expect(stylesheetAddedHandler).toHaveBeenCalled()
|
|
|
|
expect(stylesheetAddedHandler.argsForCall[0][0].cssRules[0].style.border).toBe 'dashed'
|
2014-05-06 04:54:22 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
expect(stylesheetsChangedHandler).toHaveBeenCalled()
|
2014-05-06 04:54:22 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
styleElementRemovedHandler.reset()
|
|
|
|
stylesheetRemovedHandler.reset()
|
|
|
|
stylesheetsChangedHandler.reset()
|
|
|
|
fs.removeSync(userStylesheetPath)
|
2014-01-17 23:08:43 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
waitsFor ->
|
|
|
|
themeManager.loadUserStylesheet.callCount is 2
|
2014-01-17 23:08:43 +04:00
|
|
|
|
2015-01-14 02:12:02 +03:00
|
|
|
runs ->
|
|
|
|
expect(styleElementRemovedHandler).toHaveBeenCalled()
|
|
|
|
expect(styleElementRemovedHandler.argsForCall[0][0].textContent).toContain 'dashed'
|
|
|
|
expect(stylesheetRemovedHandler).toHaveBeenCalled()
|
|
|
|
expect(stylesheetRemovedHandler.argsForCall[0][0].cssRules[0].style.border).toBe 'dashed'
|
|
|
|
expect($(document.body).css('border-style')).toBe 'none'
|
|
|
|
expect(stylesheetsChangedHandler).toHaveBeenCalled()
|
|
|
|
|
|
|
|
describe "when there is an error reading the stylesheet", ->
|
|
|
|
addErrorHandler = null
|
|
|
|
beforeEach ->
|
2015-01-14 02:47:43 +03:00
|
|
|
themeManager.loadUserStylesheet()
|
|
|
|
spyOn(themeManager.lessCache, 'cssForFile').andCallFake ->
|
|
|
|
throw new Error('EACCES permission denied "styles.less"')
|
2015-01-14 02:12:02 +03:00
|
|
|
atom.notifications.onDidAddNotification addErrorHandler = jasmine.createSpy()
|
|
|
|
|
2015-02-03 04:50:02 +03:00
|
|
|
it "creates an error notification and does not add the stylesheet", ->
|
2015-01-14 02:12:02 +03:00
|
|
|
themeManager.loadUserStylesheet()
|
|
|
|
expect(addErrorHandler).toHaveBeenCalled()
|
|
|
|
note = addErrorHandler.mostRecentCall.args[0]
|
|
|
|
expect(note.getType()).toBe 'error'
|
|
|
|
expect(note.getMessage()).toContain 'Error loading'
|
2015-02-03 04:50:02 +03:00
|
|
|
expect(atom.styles.styleElementsBySourcePath[atom.styles.getUserStyleSheetPath()]).toBeUndefined()
|
2015-01-14 02:12:02 +03:00
|
|
|
|
|
|
|
describe "when there is an error watching the user stylesheet", ->
|
|
|
|
addErrorHandler = null
|
|
|
|
beforeEach ->
|
2015-01-14 02:47:43 +03:00
|
|
|
{File} = require 'pathwatcher'
|
|
|
|
spyOn(File::, 'on').andCallFake (event) ->
|
|
|
|
if event.indexOf('contents-changed') > -1
|
|
|
|
throw new Error('Unable to watch path')
|
2015-01-14 02:12:02 +03:00
|
|
|
spyOn(themeManager, 'loadStylesheet').andReturn ''
|
|
|
|
atom.notifications.onDidAddNotification addErrorHandler = jasmine.createSpy()
|
|
|
|
|
|
|
|
it "creates an error notification", ->
|
|
|
|
themeManager.loadUserStylesheet()
|
|
|
|
expect(addErrorHandler).toHaveBeenCalled()
|
|
|
|
note = addErrorHandler.mostRecentCall.args[0]
|
|
|
|
expect(note.getType()).toBe 'error'
|
|
|
|
expect(note.getMessage()).toContain 'Unable to watch path'
|
2014-02-20 23:41:23 +04:00
|
|
|
|
|
|
|
describe "when a non-existent theme is present in the config", ->
|
2014-10-26 05:01:59 +03:00
|
|
|
beforeEach ->
|
2014-10-30 20:03:44 +03:00
|
|
|
spyOn(console, 'warn')
|
2014-10-26 05:01:59 +03:00
|
|
|
atom.config.set('core.themes', ['non-existent-dark-ui', 'non-existent-dark-syntax'])
|
2014-05-20 21:11:35 +04:00
|
|
|
|
2014-02-20 23:41:23 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
themeManager.activateThemes()
|
|
|
|
|
2014-10-30 20:03:44 +03:00
|
|
|
it 'uses the default dark UI and syntax themes and logs a warning', ->
|
2015-01-09 19:24:48 +03:00
|
|
|
activeThemeNames = themeManager.getActiveThemeNames()
|
2014-10-30 20:03:44 +03:00
|
|
|
expect(console.warn.callCount).toBe 2
|
2014-10-26 05:01:59 +03:00
|
|
|
expect(activeThemeNames.length).toBe(2)
|
|
|
|
expect(activeThemeNames).toContain('atom-dark-ui')
|
|
|
|
expect(activeThemeNames).toContain('atom-dark-syntax')
|
2014-08-05 15:32:16 +04:00
|
|
|
|
2014-08-12 02:24:49 +04:00
|
|
|
describe "when in safe mode", ->
|
2014-08-05 15:32:16 +04:00
|
|
|
beforeEach ->
|
2014-08-08 21:59:45 +04:00
|
|
|
themeManager = new ThemeManager({packageManager: atom.packages, resourcePath, configDirPath, safeMode: true})
|
2014-08-05 15:32:16 +04:00
|
|
|
|
2014-08-12 02:24:49 +04:00
|
|
|
describe 'when the enabled UI and syntax themes are bundled with Atom', ->
|
|
|
|
beforeEach ->
|
|
|
|
atom.config.set('core.themes', ['atom-light-ui', 'atom-dark-syntax'])
|
2014-08-05 15:32:16 +04:00
|
|
|
|
2014-08-12 02:24:49 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
themeManager.activateThemes()
|
|
|
|
|
|
|
|
it 'uses the enabled themes', ->
|
2015-01-09 19:24:48 +03:00
|
|
|
activeThemeNames = themeManager.getActiveThemeNames()
|
2014-08-12 02:24:49 +04:00
|
|
|
expect(activeThemeNames.length).toBe(2)
|
|
|
|
expect(activeThemeNames).toContain('atom-light-ui')
|
|
|
|
expect(activeThemeNames).toContain('atom-dark-syntax')
|
|
|
|
|
|
|
|
describe 'when the enabled UI and syntax themes are not bundled with Atom', ->
|
|
|
|
beforeEach ->
|
|
|
|
atom.config.set('core.themes', ['installed-dark-ui', 'installed-dark-syntax'])
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
themeManager.activateThemes()
|
|
|
|
|
|
|
|
it 'uses the default dark UI and syntax themes', ->
|
2015-01-09 19:24:48 +03:00
|
|
|
activeThemeNames = themeManager.getActiveThemeNames()
|
2014-08-12 02:24:49 +04:00
|
|
|
expect(activeThemeNames.length).toBe(2)
|
|
|
|
expect(activeThemeNames).toContain('atom-dark-ui')
|
|
|
|
expect(activeThemeNames).toContain('atom-dark-syntax')
|
|
|
|
|
|
|
|
describe 'when the enabled UI theme is not bundled with Atom', ->
|
|
|
|
beforeEach ->
|
|
|
|
atom.config.set('core.themes', ['installed-dark-ui', 'atom-light-syntax'])
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
themeManager.activateThemes()
|
|
|
|
|
|
|
|
it 'uses the default dark UI theme', ->
|
2015-01-09 19:24:48 +03:00
|
|
|
activeThemeNames = themeManager.getActiveThemeNames()
|
2014-08-05 15:32:16 +04:00
|
|
|
expect(activeThemeNames.length).toBe(2)
|
|
|
|
expect(activeThemeNames).toContain('atom-dark-ui')
|
2014-08-12 02:24:49 +04:00
|
|
|
expect(activeThemeNames).toContain('atom-light-syntax')
|
|
|
|
|
|
|
|
describe 'when the enabled syntax theme is not bundled with Atom', ->
|
|
|
|
beforeEach ->
|
|
|
|
atom.config.set('core.themes', ['atom-light-ui', 'installed-dark-syntax'])
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
themeManager.activateThemes()
|
|
|
|
|
|
|
|
it 'uses the default dark syntax theme', ->
|
2015-01-09 19:24:48 +03:00
|
|
|
activeThemeNames = themeManager.getActiveThemeNames()
|
2014-08-12 02:24:49 +04:00
|
|
|
expect(activeThemeNames.length).toBe(2)
|
|
|
|
expect(activeThemeNames).toContain('atom-light-ui')
|
2014-08-05 15:32:16 +04:00
|
|
|
expect(activeThemeNames).toContain('atom-dark-syntax')
|