diff --git a/spec/atom-package-spec.coffee b/spec/atom-package-spec.coffee new file mode 100644 index 000000000..e592fbc99 --- /dev/null +++ b/spec/atom-package-spec.coffee @@ -0,0 +1,77 @@ +$ = require 'jquery' +fsUtils = require 'fs-utils' +path = require 'path' +Package = require 'package' + +describe "AtomPackage", -> + describe "theme", -> + theme = null + + beforeEach -> + $("#jasmine-content").append $("
") + + afterEach -> + theme.deactivate() if theme? + + describe "when the theme contains a single style file", -> + it "loads and applies css", -> + expect($(".editor").css("padding-bottom")).not.toBe "1234px" + themePath = project.resolve('packages/theme-with-index-css') + theme = Package.load(themePath) + theme.activate() + expect($(".editor").css("padding-top")).toBe "1234px" + + it "parses, loads and applies less", -> + expect($(".editor").css("padding-bottom")).not.toBe "1234px" + themePath = project.resolve('packages/theme-with-index-less') + theme = Package.load(themePath) + theme.activate() + expect($(".editor").css("padding-top")).toBe "4321px" + + describe "when the theme contains a package.json file", -> + it "loads and applies stylesheets from package.json in the correct order", -> + expect($(".editor").css("padding-top")).not.toBe("101px") + expect($(".editor").css("padding-right")).not.toBe("102px") + expect($(".editor").css("padding-bottom")).not.toBe("103px") + + themePath = project.resolve('packages/theme-with-package-file') + theme = Package.load(themePath) + theme.activate() + expect($(".editor").css("padding-top")).toBe("101px") + expect($(".editor").css("padding-right")).toBe("102px") + expect($(".editor").css("padding-bottom")).toBe("103px") + + describe "when the theme does not contain a package.json file and is a directory", -> + it "loads all stylesheet files in the directory", -> + expect($(".editor").css("padding-top")).not.toBe "10px" + expect($(".editor").css("padding-right")).not.toBe "20px" + expect($(".editor").css("padding-bottom")).not.toBe "30px" + + themePath = project.resolve('packages/theme-without-package-file') + theme = Package.load(themePath) + theme.activate() + expect($(".editor").css("padding-top")).toBe "10px" + expect($(".editor").css("padding-right")).toBe "20px" + expect($(".editor").css("padding-bottom")).toBe "30px" + + describe "reloading a theme", -> + beforeEach -> + themePath = project.resolve('packages/theme-with-package-file') + theme = Package.load(themePath) + theme.activate() + + it "reloads without readding to the stylesheets list", -> + expect(theme.getStylesheetPaths().length).toBe 3 + theme.reloadStylesheet(theme.getStylesheetPaths()[0]) + expect(theme.getStylesheetPaths().length).toBe 3 + + describe "events", -> + beforeEach -> + themePath = project.resolve('packages/theme-with-package-file') + theme = Package.load(themePath) + theme.activate() + + it "deactivated event fires on .deactivate()", -> + theme.on 'deactivated', spy = jasmine.createSpy() + theme.deactivate() + expect(spy).toHaveBeenCalled() diff --git a/spec/fixtures/packages/theme-with-index-css/package.json b/spec/fixtures/packages/theme-with-index-css/package.json new file mode 100644 index 000000000..a4dc0188d --- /dev/null +++ b/spec/fixtures/packages/theme-with-index-css/package.json @@ -0,0 +1,3 @@ +{ + "theme": true +} diff --git a/spec/fixtures/packages/theme-with-index-less/package.json b/spec/fixtures/packages/theme-with-index-less/package.json new file mode 100644 index 000000000..a4dc0188d --- /dev/null +++ b/spec/fixtures/packages/theme-with-index-less/package.json @@ -0,0 +1,3 @@ +{ + "theme": true +} diff --git a/spec/theme-spec.coffee b/spec/theme-spec.coffee deleted file mode 100644 index 973b20925..000000000 --- a/spec/theme-spec.coffee +++ /dev/null @@ -1,72 +0,0 @@ -$ = require 'jquery' -fsUtils = require 'fs-utils' -path = require 'path' - -xdescribe "Theme", -> - theme = null - - beforeEach -> - $("#jasmine-content").append $("
") - - afterEach -> - theme.deactivate() if theme? - - describe "when the theme is a file", -> - it "loads and applies css", -> - expect($(".editor").css("padding-bottom")).not.toBe "1234px" - themePath = project.resolve('themes/theme-stylesheet.css') - theme = new Theme(themePath) - expect($(".editor").css("padding-top")).toBe "1234px" - expect(theme.directoryPath).not.toBeDefined() - - it "parses, loads and applies less", -> - expect($(".editor").css("padding-bottom")).not.toBe "1234px" - themePath = project.resolve('themes/theme-stylesheet.less') - theme = new Theme(themePath) - expect($(".editor").css("padding-top")).toBe "4321px" - - describe "when the theme contains a package.json file", -> - it "loads and applies stylesheets from package.json in the correct order", -> - expect($(".editor").css("padding-top")).not.toBe("101px") - expect($(".editor").css("padding-right")).not.toBe("102px") - expect($(".editor").css("padding-bottom")).not.toBe("103px") - - themePath = project.resolve('themes/theme-with-package-file') - theme = new Theme(themePath) - expect(theme.directoryPath).toBe themePath - expect($(".editor").css("padding-top")).toBe("101px") - expect($(".editor").css("padding-right")).toBe("102px") - expect($(".editor").css("padding-bottom")).toBe("103px") - - describe "when the theme does not contain a package.json file and is a directory", -> - it "loads all stylesheet files in the directory", -> - expect($(".editor").css("padding-top")).not.toBe "10px" - expect($(".editor").css("padding-right")).not.toBe "20px" - expect($(".editor").css("padding-bottom")).not.toBe "30px" - - themePath = project.resolve('themes/theme-without-package-file') - theme = new Theme(themePath) - expect(theme.directoryPath).toBe themePath - expect($(".editor").css("padding-top")).toBe "10px" - expect($(".editor").css("padding-right")).toBe "20px" - expect($(".editor").css("padding-bottom")).toBe "30px" - - describe "reloading a theme", -> - beforeEach -> - themePath = project.resolve('themes/theme-with-package-file') - theme = new Theme(themePath) - - it "reloads without readding to the stylesheets list", -> - expect(theme.getStylesheetPaths().length).toBe 3 - theme.loadStylesheet(theme.getStylesheetPaths()[0]) - expect(theme.getStylesheetPaths().length).toBe 3 - - describe "events", -> - beforeEach -> - themePath = project.resolve('themes/theme-with-package-file') - theme = new Theme(themePath) - - it "deactivated event fires on .deactivate()", -> - theme.on 'deactivated', spy = jasmine.createSpy() - theme.deactivate() - expect(spy).toHaveBeenCalled() diff --git a/src/atom-package.coffee b/src/atom-package.coffee index 26846a2e6..26502dc6f 100644 --- a/src/atom-package.coffee +++ b/src/atom-package.coffee @@ -141,8 +141,11 @@ class AtomPackage extends Package oldSheets = _.clone(@stylesheets) @loadStylesheets() removeStylesheet(stylesheetPath) for [stylesheetPath] in oldSheets + @reloadStylesheet(stylesheetPath, content) for [stylesheetPath, content] in @stylesheets + + reloadStylesheet: (stylesheetPath, content) -> type = if @metadata.theme then 'theme' else 'bundled' - applyStylesheet(stylesheetPath, content, type) for [stylesheetPath, content] in @stylesheets + window.applyStylesheet(stylesheetPath, content, type) requireMainModule: -> return @mainModule if @mainModule?