Repository navigation
Expand file tree
/
Copy pathmarker.test.js
More file actions
149 lines (126 loc) · 4.72 KB
/
Copy pathmarker.test.js
File metadata and controls
149 lines (126 loc) · 4.72 KB
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
import React from 'react';
import {mount} from 'enzyme';
import {Range} from 'atom';
import Marker from '../../lib/atom/marker';
import AtomTextEditor from '../../lib/atom/atom-text-editor';
import RefHolder from '../../lib/models/ref-holder';
import MarkerLayer from '../../lib/atom/marker-layer';
describe('Marker', function() {
let atomEnv, workspace, editor, marker, markerID;
beforeEach(async function() {
atomEnv = global.buildAtomEnvironment();
workspace = atomEnv.workspace;
editor = await atomEnv.workspace.open(__filename);
});
afterEach(function() {
atomEnv.destroy();
});
function setMarker(m) {
marker = m;
}
function setMarkerID(id) {
markerID = id;
}
it('adds its marker on mount with default properties', function() {
mount(
<Marker
editor={editor}
bufferRange={Range.fromObject([[0, 0], [10, 0]])}
handleID={setMarkerID}
handleMarker={setMarker}
/>,
);
const theMarker = editor.getMarker(markerID);
assert.strictEqual(theMarker, marker);
assert.isTrue(theMarker.getBufferRange().isEqual([[0, 0], [10, 0]]));
assert.strictEqual(theMarker.bufferMarker.invalidate, 'overlap');
assert.isFalse(theMarker.isReversed());
});
it('configures its marker', function() {
mount(
<Marker
editor={editor}
handleID={setMarkerID}
bufferRange={Range.fromObject([[1, 2], [4, 5]])}
reversed={true}
invalidate={'never'}
exclusive={true}
/>,
);
const theMarker = editor.getMarker(markerID);
assert.isTrue(theMarker.getBufferRange().isEqual([[1, 2], [4, 5]]));
assert.isTrue(theMarker.isReversed());
assert.strictEqual(theMarker.bufferMarker.invalidate, 'never');
});
it('prefers marking a MarkerLayer to a TextEditor', function() {
const layer = editor.addMarkerLayer();
mount(
<Marker
editor={editor}
layer={layer}
handleID={setMarkerID}
bufferRange={Range.fromObject([[0, 0], [1, 0]])}
/>,
);
const theMarker = layer.getMarker(markerID);
assert.strictEqual(theMarker.layer, layer);
});
it('destroys its marker on unmount', function() {
const wrapper = mount(
<Marker editor={editor} handleID={setMarkerID} bufferRange={Range.fromObject([[0, 0], [0, 0]])} />,
);
assert.isDefined(editor.getMarker(markerID));
wrapper.unmount();
assert.isUndefined(editor.getMarker(markerID));
});
it('marks an editor from a parent node', function() {
const editorHolder = new RefHolder();
mount(
<AtomTextEditor workspace={workspace} refModel={editorHolder}>
<Marker handleID={setMarkerID} bufferRange={Range.fromObject([[0, 0], [0, 0]])} />
</AtomTextEditor>,
);
const theEditor = editorHolder.get();
const theMarker = theEditor.getMarker(markerID);
assert.isTrue(theMarker.getBufferRange().isEqual([[0, 0], [0, 0]]));
});
it('marks a marker layer from a parent node', function() {
let layerID;
const editorHolder = new RefHolder();
mount(
<AtomTextEditor workspace={workspace} refModel={editorHolder}>
<MarkerLayer handleID={id => { layerID = id; }}>
<Marker handleID={setMarkerID} bufferRange={Range.fromObject([[0, 0], [0, 0]])} />
</MarkerLayer>
</AtomTextEditor>,
);
const theEditor = editorHolder.get();
const layer = theEditor.getMarkerLayer(layerID);
const theMarker = layer.getMarker(markerID);
assert.isTrue(theMarker.getBufferRange().isEqual([[0, 0], [0, 0]]));
});
describe('with an externally managed marker', function() {
it('locates its marker by ID', function() {
const external = editor.markBufferRange([[0, 0], [0, 5]]);
const wrapper = mount(<Marker editor={editor} id={external.id} />);
const instance = wrapper.find('BareMarker').instance();
assert.strictEqual(instance.markerHolder.get(), external);
});
it('locates its marker on a parent MarkerLayer', function() {
const layer = editor.addMarkerLayer();
const external = layer.markBufferRange([[0, 0], [0, 5]]);
const wrapper = mount(<Marker layer={layer} id={external.id} />);
const instance = wrapper.find('BareMarker').instance();
assert.strictEqual(instance.markerHolder.get(), external);
});
it('fails on construction if its ID is invalid', function() {
assert.throws(() => mount(<Marker editor={editor} id={67} />), /Invalid marker ID: 67/);
});
it('does not destroy its marker on unmount', function() {
const external = editor.markBufferRange([[0, 0], [0, 5]]);
const wrapper = mount(<Marker editor={editor} id={external.id} />);
wrapper.unmount();
assert.isFalse(external.isDestroyed());
});
});
});