2013-09-25 19:39:16 +04:00
|
|
|
path = require 'path'
|
2014-01-17 23:08:43 +04:00
|
|
|
|
2013-11-26 22:11:31 +04:00
|
|
|
{$, $$, fs, WorkspaceView} = require 'atom'
|
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'
|
|
|
|
AtomPackage = require '../src/atom-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 ->
|
2013-10-29 22:05:03 +04:00
|
|
|
atom.packages.loadPackages(sync: true)
|
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', ->
|
|
|
|
themeManager.activateThemes()
|
|
|
|
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
|
|
|
|
2013-09-03 23:22:32 +04:00
|
|
|
describe "getImportPaths()", ->
|
|
|
|
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", ->
|
2013-08-14 21:44:55 +04:00
|
|
|
themeManager.on 'reloaded', reloadHandler = jasmine.createSpy()
|
2013-08-07 21:40:46 +04:00
|
|
|
spyOn(themeManager, 'getUserStylesheetPath').andCallFake -> null
|
2013-10-19 02:24:39 +04:00
|
|
|
themeManager.activateThemes()
|
2013-08-14 04:01:45 +04:00
|
|
|
|
2013-11-11 21:16:44 +04:00
|
|
|
atom.config.set('core.themes', [])
|
2013-09-20 03:57:48 +04:00
|
|
|
expect($('style.theme').length).toBe 0
|
2013-08-14 04:01:45 +04:00
|
|
|
expect(reloadHandler).toHaveBeenCalled()
|
2013-08-07 21:40:46 +04:00
|
|
|
|
2013-11-11 21:16:44 +04:00
|
|
|
atom.config.set('core.themes', ['atom-dark-syntax'])
|
2013-09-14 03:21:07 +04:00
|
|
|
expect($('style.theme').length).toBe 1
|
|
|
|
expect($('style.theme:eq(0)').attr('id')).toMatch /atom-dark-syntax/
|
2013-08-07 21:40:46 +04:00
|
|
|
|
2013-11-11 21:16:44 +04:00
|
|
|
atom.config.set('core.themes', ['atom-light-syntax', 'atom-dark-syntax'])
|
2013-09-14 03:21:07 +04:00
|
|
|
expect($('style.theme').length).toBe 2
|
2013-09-13 02:20:40 +04:00
|
|
|
expect($('style.theme:eq(0)').attr('id')).toMatch /atom-dark-syntax/
|
|
|
|
expect($('style.theme:eq(1)').attr('id')).toMatch /atom-light-syntax/
|
2013-08-07 21:40:46 +04:00
|
|
|
|
2013-11-11 21:16:44 +04:00
|
|
|
atom.config.set('core.themes', [])
|
2013-09-14 03:21:07 +04:00
|
|
|
expect($('style.theme').length).toBe 0
|
2013-08-09 22:24:21 +04:00
|
|
|
|
2013-12-07 01:24:34 +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-14 03:51:21 +04:00
|
|
|
importPaths = themeManager.getImportPaths()
|
|
|
|
expect(importPaths.length).toBe 1
|
|
|
|
expect(importPaths[0]).toContain 'atom-dark-ui'
|
|
|
|
|
2013-08-09 22:24:21 +04:00
|
|
|
describe "when a theme fails to load", ->
|
|
|
|
it "logs a warning", ->
|
|
|
|
spyOn(console, 'warn')
|
2013-10-19 04:41:32 +04:00
|
|
|
expect(-> atom.packages.activatePackage('a-theme-that-will-not-be-found')).toThrow()
|
2013-09-25 19:39:16 +04:00
|
|
|
|
|
|
|
describe "requireStylesheet(path)", ->
|
|
|
|
it "synchronously loads css at the given path and installs a style tag for it in the head", ->
|
2013-11-21 03:35:49 +04:00
|
|
|
cssPath = atom.project.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
|
|
|
|
|
|
|
|
element = $('head style[id*="css.css"]')
|
2013-11-07 05:12:47 +04:00
|
|
|
expect(element.attr('id')).toBe themeManager.stringToId(cssPath)
|
2013-11-01 01:58:01 +04:00
|
|
|
expect(element.text()).toBe fs.readFileSync(cssPath, 'utf8')
|
2013-09-25 19:39:16 +04:00
|
|
|
|
|
|
|
# doesn't append twice
|
|
|
|
themeManager.requireStylesheet(cssPath)
|
|
|
|
expect($('head style').length).toBe lengthBefore + 1
|
|
|
|
|
|
|
|
$('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", ->
|
2013-11-21 03:35:49 +04:00
|
|
|
lessPath = atom.project.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
|
|
|
|
|
|
|
|
element = $('head style[id*="sample.less"]')
|
2013-11-07 05:12:47 +04:00
|
|
|
expect(element.attr('id')).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')
|
2013-11-21 04:59:37 +04:00
|
|
|
expect($('head style[id*="css.css"]').attr('id')).toBe themeManager.stringToId(atom.project.resolve('css.css'))
|
2013-09-25 19:39:16 +04:00
|
|
|
themeManager.requireStylesheet path.join(__dirname, 'fixtures', 'sample')
|
2013-11-21 04:59:37 +04:00
|
|
|
expect($('head style[id*="sample.less"]').attr('id')).toBe themeManager.stringToId(atom.project.resolve('sample.less'))
|
2013-09-25 19:39:16 +04:00
|
|
|
|
|
|
|
$('head style[id*="css.css"]').remove()
|
|
|
|
$('head style[id*="sample.less"]').remove()
|
|
|
|
|
|
|
|
describe ".removeStylesheet(path)", ->
|
|
|
|
it "removes styling applied by given stylesheet path", ->
|
|
|
|
cssPath = require.resolve('./fixtures/css.css')
|
|
|
|
|
|
|
|
expect($(document.body).css('font-weight')).not.toBe("bold")
|
|
|
|
themeManager.requireStylesheet(cssPath)
|
|
|
|
expect($(document.body).css('font-weight')).toBe("bold")
|
|
|
|
themeManager.removeStylesheet(cssPath)
|
|
|
|
expect($(document.body).css('font-weight')).not.toBe("bold")
|
|
|
|
|
|
|
|
describe "base stylesheet loading", ->
|
|
|
|
beforeEach ->
|
2013-11-26 22:11:31 +04:00
|
|
|
atom.workspaceView = new WorkspaceView
|
|
|
|
atom.workspaceView.append $$ -> @div class: 'editor'
|
|
|
|
atom.workspaceView.attachToDom()
|
2013-10-19 02:24:39 +04:00
|
|
|
themeManager.activateThemes()
|
2013-09-25 19:39:16 +04:00
|
|
|
|
|
|
|
it "loads the correct values from the theme's ui-variables file", ->
|
2013-11-11 21:16:44 +04:00
|
|
|
atom.config.set('core.themes', ['theme-with-ui-variables'])
|
2013-09-25 19:39:16 +04:00
|
|
|
|
|
|
|
# an override loaded in the base css
|
2013-11-26 22:11:31 +04:00
|
|
|
expect(atom.workspaceView.css("background-color")).toBe "rgb(0, 0, 255)"
|
2013-09-25 19:39:16 +04:00
|
|
|
|
|
|
|
# from within the theme itself
|
|
|
|
expect($(".editor").css("padding-top")).toBe "150px"
|
|
|
|
expect($(".editor").css("padding-right")).toBe "150px"
|
|
|
|
expect($(".editor").css("padding-bottom")).toBe "150px"
|
2014-01-17 23:08:43 +04:00
|
|
|
|
|
|
|
describe "when the user stylesheet changes", ->
|
|
|
|
it "reloads it", ->
|
2014-01-31 04:58:35 +04:00
|
|
|
userStylesheetPath = path.join(temp.mkdirSync("atom"), 'styles.css')
|
2014-01-17 23:08:43 +04:00
|
|
|
fs.writeFileSync(userStylesheetPath, 'body {border-style: dotted !important;}')
|
|
|
|
|
|
|
|
spyOn(themeManager, 'getUserStylesheetPath').andReturn userStylesheetPath
|
|
|
|
themeManager.activateThemes()
|
|
|
|
|
|
|
|
expect($(document.body).css('border-style')).toBe 'dotted'
|
|
|
|
spyOn(themeManager, 'loadUserStylesheet').andCallThrough()
|
|
|
|
|
|
|
|
fs.writeFileSync(userStylesheetPath, 'body {border-style: dashed}')
|
|
|
|
|
|
|
|
waitsFor ->
|
|
|
|
themeManager.loadUserStylesheet.callCount is 1
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect($(document.body).css('border-style')).toBe 'dashed'
|
|
|
|
fs.removeSync(userStylesheetPath)
|
|
|
|
|
|
|
|
waitsFor ->
|
|
|
|
themeManager.loadUserStylesheet.callCount is 2
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect($(document.body).css('border-style')).toBe 'none'
|