mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 21:57:55 +08:00
115 lines
4.6 KiB
CoffeeScript
115 lines
4.6 KiB
CoffeeScript
path = require 'path'
|
|
Package = require '../src/package'
|
|
ThemePackage = require '../src/theme-package'
|
|
|
|
resolveFixturePath = (packagename) ->
|
|
path.join(__dirname, 'fixtures', 'packages', packagename)
|
|
|
|
describe "Package", ->
|
|
describe "when the package contains incompatible native modules", ->
|
|
beforeEach ->
|
|
spyOn(NylasEnv, 'inDevMode').andReturn(false)
|
|
|
|
it "does not activate it", ->
|
|
packagePath = resolveFixturePath('package-with-incompatible-native-module')
|
|
pack = new Package(packagePath)
|
|
expect(pack.isCompatible()).toBe false
|
|
expect(pack.incompatibleModules[0].name).toBe 'native-module'
|
|
expect(pack.incompatibleModules[0].path).toBe path.join(packagePath, 'node_modules', 'native-module')
|
|
|
|
it "caches the incompatible native modules in local storage", ->
|
|
packagePath = resolveFixturePath('package-with-incompatible-native-module')
|
|
cacheKey = null
|
|
cacheItem = null
|
|
|
|
spyOn(global.localStorage, 'setItem').andCallFake (key, item) ->
|
|
cacheKey = key
|
|
cacheItem = item
|
|
spyOn(global.localStorage, 'getItem').andCallFake (key) ->
|
|
return cacheItem if cacheKey is key
|
|
|
|
expect(new Package(packagePath).isCompatible()).toBe false
|
|
expect(global.localStorage.getItem.callCount).toBe 1
|
|
expect(global.localStorage.setItem.callCount).toBe 1
|
|
|
|
expect(new Package(packagePath).isCompatible()).toBe false
|
|
expect(global.localStorage.getItem.callCount).toBe 2
|
|
expect(global.localStorage.setItem.callCount).toBe 1
|
|
|
|
describe "theme", ->
|
|
theme = null
|
|
|
|
beforeEach ->
|
|
@wrap = document.createElement('nylas-theme-wrap')
|
|
document.getElementById("jasmine-content").appendChild(@wrap)
|
|
|
|
afterEach ->
|
|
theme.deactivate() if theme?
|
|
|
|
describe "when the theme contains a single style file", ->
|
|
it "loads and applies css", ->
|
|
|
|
expect(window.getComputedStyle(@wrap)['padding-bottom']).not.toBe "1234px"
|
|
themePath = resolveFixturePath('theme-with-index-css')
|
|
theme = new ThemePackage(themePath)
|
|
theme.activate()
|
|
expect(window.getComputedStyle(@wrap)['padding-top']).toBe "1234px"
|
|
|
|
it "parses, loads and applies less", ->
|
|
expect(window.getComputedStyle(@wrap)['padding-bottom']).not.toBe "1234px"
|
|
themePath = resolveFixturePath('theme-with-index-less')
|
|
theme = new ThemePackage(themePath)
|
|
theme.activate()
|
|
expect(window.getComputedStyle(@wrap)['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", ->
|
|
styles = window.getComputedStyle(@wrap)
|
|
expect(styles["padding-top"]).not.toBe("101px")
|
|
expect(styles["padding-right"]).not.toBe("102px")
|
|
expect(styles["padding-bottom"]).not.toBe("103px")
|
|
|
|
themePath = resolveFixturePath('theme-with-package-file')
|
|
theme = new ThemePackage(themePath)
|
|
theme.activate()
|
|
styles = window.getComputedStyle(@wrap)
|
|
expect(styles["padding-top"]).toBe("101px")
|
|
expect(styles["padding-right"]).toBe("102px")
|
|
expect(styles["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", ->
|
|
styles = window.getComputedStyle(@wrap)
|
|
expect(styles["padding-top"]).not.toBe("10px")
|
|
expect(styles["padding-right"]).not.toBe("20px")
|
|
expect(styles["padding-bottom"]).not.toBe("30px")
|
|
|
|
themePath = resolveFixturePath('theme-without-package-file')
|
|
theme = new ThemePackage(themePath)
|
|
theme.activate()
|
|
styles = window.getComputedStyle(@wrap)
|
|
expect(styles["padding-top"]).toBe("10px")
|
|
expect(styles["padding-right"]).toBe("20px")
|
|
expect(styles["padding-bottom"]).toBe("30px")
|
|
|
|
describe "reloading a theme", ->
|
|
beforeEach ->
|
|
themePath = resolveFixturePath('theme-with-package-file')
|
|
theme = new ThemePackage(themePath)
|
|
theme.activate()
|
|
|
|
it "reloads without readding to the stylesheets list", ->
|
|
expect(theme.getStylesheetPaths().length).toBe 3
|
|
theme.reloadStylesheets()
|
|
expect(theme.getStylesheetPaths().length).toBe 3
|
|
|
|
describe "events", ->
|
|
beforeEach ->
|
|
themePath = resolveFixturePath('theme-with-package-file')
|
|
theme = new ThemePackage(themePath)
|
|
theme.activate()
|
|
|
|
it "deactivated event fires on .deactivate()", ->
|
|
theme.onDidDeactivate spy = jasmine.createSpy()
|
|
theme.deactivate()
|
|
expect(spy).toHaveBeenCalled()
|