-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle-manager-spec.coffee
66 lines (49 loc) · 2.58 KB
/
style-manager-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
StyleManager = require '../src/style-manager'
describe "StyleManager", ->
[manager, addEvents, removeEvents, updateEvents] = []
beforeEach ->
manager = new StyleManager
addEvents = []
removeEvents = []
updateEvents = []
manager.onDidAddStyleElement (event) -> addEvents.push(event)
manager.onDidRemoveStyleElement (event) -> removeEvents.push(event)
manager.onDidUpdateStyleElement (event) -> updateEvents.push(event)
describe "::addStyleSheet(source, params)", ->
it "adds a stylesheet based on the given source and returns a disposable allowing it to be removed", ->
disposable = manager.addStyleSheet("a {color: red;}")
expect(addEvents.length).toBe 1
expect(addEvents[0].textContent).toBe "a {color: red;}"
styleElements = manager.getStyleElements()
expect(styleElements.length).toBe 1
expect(styleElements[0].textContent).toBe "a {color: red;}"
disposable.dispose()
expect(removeEvents.length).toBe 1
expect(removeEvents[0].textContent).toBe "a {color: red;}"
expect(manager.getStyleElements().length).toBe 0
describe "when a sourcePath parameter is specified", ->
it "ensures a maximum of one style element for the given source path, updating a previous if it exists", ->
disposable1 = manager.addStyleSheet("a {color: red;}", sourcePath: '/foo/bar')
expect(addEvents.length).toBe 1
expect(addEvents[0].getAttribute('source-path')).toBe '/foo/bar'
disposable2 = manager.addStyleSheet("a {color: blue;}", sourcePath: '/foo/bar')
expect(addEvents.length).toBe 1
expect(updateEvents.length).toBe 1
expect(updateEvents[0].getAttribute('source-path')).toBe '/foo/bar'
expect(updateEvents[0].textContent).toBe "a {color: blue;}"
disposable2.dispose()
addEvents = []
manager.addStyleSheet("a {color: yellow;}", sourcePath: '/foo/bar')
expect(addEvents.length).toBe 1
expect(addEvents[0].getAttribute('source-path')).toBe '/foo/bar'
expect(addEvents[0].textContent).toBe "a {color: yellow;}"
describe "when a group parameter is specified", ->
it "inserts the stylesheet at the end of any existing stylesheets for the same group", ->
manager.addStyleSheet("a {color: red}", group: 'a')
manager.addStyleSheet("a {color: blue}", group: 'b')
manager.addStyleSheet("a {color: green}", group: 'a')
expect(manager.getStyleElements().map (elt) -> elt.textContent).toEqual [
"a {color: red}"
"a {color: green}"
"a {color: blue}"
]