forked from nylas/nylas-mail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage-spec.coffee
110 lines (90 loc) · 4.6 KB
/
package-spec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
{$} = require '../src/space-pen-extensions'
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 ->
$("#jasmine-content").append $("<nylas-theme-wrap></nylas-theme-wrap>")
afterEach ->
theme.deactivate() if theme?
describe "when the theme contains a single style file", ->
it "loads and applies css", ->
expect($("nylas-theme-wrap").css("padding-bottom")).not.toBe "1234px"
themePath = resolveFixturePath('theme-with-index-css')
theme = new ThemePackage(themePath)
theme.activate()
expect($("nylas-theme-wrap").css("padding-top")).toBe "1234px"
it "parses, loads and applies less", ->
expect($("nylas-theme-wrap").css("padding-bottom")).not.toBe "1234px"
themePath = resolveFixturePath('theme-with-index-less')
theme = new ThemePackage(themePath)
theme.activate()
expect($("nylas-theme-wrap").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($("nylas-theme-wrap").css("padding-top")).not.toBe("101px")
expect($("nylas-theme-wrap").css("padding-right")).not.toBe("102px")
expect($("nylas-theme-wrap").css("padding-bottom")).not.toBe("103px")
themePath = resolveFixturePath('theme-with-package-file')
theme = new ThemePackage(themePath)
theme.activate()
expect($("nylas-theme-wrap").css("padding-top")).toBe("101px")
expect($("nylas-theme-wrap").css("padding-right")).toBe("102px")
expect($("nylas-theme-wrap").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($("nylas-theme-wrap").css("padding-top")).not.toBe "10px"
expect($("nylas-theme-wrap").css("padding-right")).not.toBe "20px"
expect($("nylas-theme-wrap").css("padding-bottom")).not.toBe "30px"
themePath = resolveFixturePath('theme-without-package-file')
theme = new ThemePackage(themePath)
theme.activate()
expect($("nylas-theme-wrap").css("padding-top")).toBe "10px"
expect($("nylas-theme-wrap").css("padding-right")).toBe "20px"
expect($("nylas-theme-wrap").css("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()