-
-
Notifications
You must be signed in to change notification settings - Fork 141
/
decoration-manager-spec.js
159 lines (142 loc) · 5.71 KB
/
decoration-manager-spec.js
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const DecorationManager = require('../src/decoration-manager');
const TextEditor = require('../src/text-editor');
describe('DecorationManager', function() {
let [decorationManager, buffer, editor, markerLayer1, markerLayer2] = [];
beforeEach(function() {
buffer = atom.project.bufferForPathSync('sample.js');
editor = new TextEditor({ buffer });
markerLayer1 = editor.addMarkerLayer();
markerLayer2 = editor.addMarkerLayer();
decorationManager = new DecorationManager(editor);
waitsForPromise(() => atom.packages.activatePackage('language-javascript'));
});
afterEach(() => buffer.destroy());
describe('decorations', function() {
let [
layer1Marker,
layer2Marker,
layer1MarkerDecoration,
layer2MarkerDecoration,
decorationProperties
] = [];
beforeEach(function() {
layer1Marker = markerLayer1.markBufferRange([[2, 13], [3, 15]]);
decorationProperties = { type: 'line-number', class: 'one' };
layer1MarkerDecoration = decorationManager.decorateMarker(
layer1Marker,
decorationProperties
);
layer2Marker = markerLayer2.markBufferRange([[2, 13], [3, 15]]);
layer2MarkerDecoration = decorationManager.decorateMarker(
layer2Marker,
decorationProperties
);
});
it('can add decorations associated with markers and remove them', function() {
expect(layer1MarkerDecoration).toBeDefined();
expect(layer1MarkerDecoration.getProperties()).toBe(decorationProperties);
expect(decorationManager.decorationsForScreenRowRange(2, 3)).toEqual({
[layer1Marker.id]: [layer1MarkerDecoration],
[layer2Marker.id]: [layer2MarkerDecoration]
});
layer1MarkerDecoration.destroy();
expect(
decorationManager.decorationsForScreenRowRange(2, 3)[layer1Marker.id]
).not.toBeDefined();
layer2MarkerDecoration.destroy();
expect(
decorationManager.decorationsForScreenRowRange(2, 3)[layer2Marker.id]
).not.toBeDefined();
});
it('will not fail if the decoration is removed twice', function() {
layer1MarkerDecoration.destroy();
layer1MarkerDecoration.destroy();
});
it('does not allow destroyed markers to be decorated', function() {
layer1Marker.destroy();
expect(() =>
decorationManager.decorateMarker(layer1Marker, {
type: 'overlay',
item: document.createElement('div')
})
).toThrow('Cannot decorate a destroyed marker');
expect(decorationManager.getOverlayDecorations()).toEqual([]);
});
it('does not allow destroyed marker layers to be decorated', function() {
const layer = editor.addMarkerLayer();
layer.destroy();
expect(() =>
decorationManager.decorateMarkerLayer(layer, { type: 'highlight' })
).toThrow('Cannot decorate a destroyed marker layer');
});
describe('when a decoration is updated via Decoration::update()', () =>
it("emits an 'updated' event containing the new and old params", function() {
let updatedSpy;
layer1MarkerDecoration.onDidChangeProperties(
(updatedSpy = jasmine.createSpy())
);
layer1MarkerDecoration.setProperties({
type: 'line-number',
class: 'two'
});
const {
oldProperties,
newProperties
} = updatedSpy.mostRecentCall.args[0];
expect(oldProperties).toEqual(decorationProperties);
expect(newProperties.type).toBe('line-number');
expect(newProperties.gutterName).toBe('line-number');
expect(newProperties.class).toBe('two');
}));
describe('::getDecorations(properties)', () =>
it('returns decorations matching the given optional properties', function() {
expect(decorationManager.getDecorations()).toEqual([
layer1MarkerDecoration,
layer2MarkerDecoration
]);
expect(
decorationManager.getDecorations({ class: 'two' }).length
).toEqual(0);
expect(
decorationManager.getDecorations({ class: 'one' }).length
).toEqual(2);
}));
});
describe('::decorateMarker', () =>
describe('when decorating gutters', function() {
let [layer1Marker] = [];
beforeEach(
() => (layer1Marker = markerLayer1.markBufferRange([[1, 0], [1, 0]]))
);
it("creates a decoration that is both of 'line-number' and 'gutter' type when called with the 'line-number' type", function() {
const decorationProperties = { type: 'line-number', class: 'one' };
const layer1MarkerDecoration = decorationManager.decorateMarker(
layer1Marker,
decorationProperties
);
expect(layer1MarkerDecoration.isType('line-number')).toBe(true);
expect(layer1MarkerDecoration.isType('gutter')).toBe(true);
expect(layer1MarkerDecoration.getProperties().gutterName).toBe(
'line-number'
);
expect(layer1MarkerDecoration.getProperties().class).toBe('one');
});
it("creates a decoration that is only of 'gutter' type if called with the 'gutter' type and a 'gutterName'", function() {
const decorationProperties = {
type: 'gutter',
gutterName: 'test-gutter',
class: 'one'
};
const layer1MarkerDecoration = decorationManager.decorateMarker(
layer1Marker,
decorationProperties
);
expect(layer1MarkerDecoration.isType('gutter')).toBe(true);
expect(layer1MarkerDecoration.isType('line-number')).toBe(false);
expect(layer1MarkerDecoration.getProperties().gutterName).toBe(
'test-gutter'
);
expect(layer1MarkerDecoration.getProperties().class).toBe('one');
});
}));
});