Repository navigation
Expand file tree
/
Copy pathmarker-layer.test.js
More file actions
111 lines (91 loc) · 3.66 KB
/
Copy pathmarker-layer.test.js
File metadata and controls
111 lines (91 loc) · 3.66 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
import React from 'react';
import {mount} from 'enzyme';
import {TextBuffer} from 'atom';
import MarkerLayer from '../../lib/atom/marker-layer';
import RefHolder from '../../lib/models/ref-holder';
import AtomTextEditor from '../../lib/atom/atom-text-editor';
describe('MarkerLayer', function() {
let atomEnv, workspace, editor, layer, layerID;
beforeEach(async function() {
atomEnv = global.buildAtomEnvironment();
workspace = atomEnv.workspace;
editor = await atomEnv.workspace.open(__filename);
});
afterEach(function() {
atomEnv.destroy();
});
function setLayer(object) {
layer = object;
}
function setLayerID(id) {
layerID = id;
}
it('adds its layer on mount', function() {
mount(
<MarkerLayer
editor={editor}
maintainHistory={true}
persistent={true}
handleID={setLayerID}
handleLayer={setLayer}
/>,
);
const theLayer = editor.getMarkerLayer(layerID);
assert.strictEqual(theLayer, layer);
assert.isTrue(theLayer.bufferMarkerLayer.maintainHistory);
assert.isTrue(theLayer.bufferMarkerLayer.persistent);
});
it('removes its layer on unmount', function() {
const wrapper = mount(<MarkerLayer editor={editor} handleID={setLayerID} handleLayer={setLayer} />);
assert.isDefined(editor.getMarkerLayer(layerID));
assert.isDefined(layer);
wrapper.unmount();
assert.isUndefined(editor.getMarkerLayer(layerID));
assert.isUndefined(layer);
});
it('inherits an editor from a parent node', function() {
const refEditor = new RefHolder();
mount(
<AtomTextEditor workspace={workspace} refModel={refEditor}>
<MarkerLayer handleID={setLayerID} />
</AtomTextEditor>,
);
const theEditor = refEditor.get();
assert.isDefined(theEditor.getMarkerLayer(layerID));
});
describe('with an externally managed layer', function() {
it('locates a display marker layer', function() {
const external = editor.addMarkerLayer();
const wrapper = mount(<MarkerLayer editor={editor} external={external} />);
assert.strictEqual(wrapper.find('BareMarkerLayer').instance().layerHolder.get(), external);
});
it('locates a marker layer on the buffer', function() {
const external = editor.getBuffer().addMarkerLayer();
const wrapper = mount(<MarkerLayer editor={editor} external={external} />);
assert.strictEqual(wrapper.find('BareMarkerLayer').instance().layerHolder.get().bufferMarkerLayer, external);
});
it('does nothing if the marker layer is not found', function() {
const otherBuffer = new TextBuffer();
const external = otherBuffer.addMarkerLayer();
const wrapper = mount(<MarkerLayer editor={editor} external={external} />);
assert.isTrue(wrapper.find('BareMarkerLayer').instance().layerHolder.isEmpty());
});
it('does nothing if the marker layer is on a different editor', function() {
const otherBuffer = new TextBuffer();
let external = otherBuffer.addMarkerLayer();
while (parseInt(external.id, 10) < editor.getBuffer().nextMarkerLayerId) {
external = otherBuffer.addMarkerLayer();
}
const oops = editor.addMarkerLayer();
assert.strictEqual(oops.id, external.id);
const wrapper = mount(<MarkerLayer editor={editor} external={external} />);
assert.isTrue(wrapper.find('BareMarkerLayer').instance().layerHolder.isEmpty());
});
it('does not destroy its layer on unmount', function() {
const external = editor.addMarkerLayer();
const wrapper = mount(<MarkerLayer editor={editor} external={external} />);
wrapper.unmount();
assert.isFalse(external.isDestroyed());
});
});
});