-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
editor.spec.ts
123 lines (109 loc) · 3.96 KB
/
editor.spec.ts
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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { CodeEditor } from '@jupyterlab/codeeditor';
import { ISharedText, SourceChange, YFile } from '@jupyter/ydoc';
describe('CodeEditor.Model', () => {
let model: CodeEditor.Model;
beforeEach(() => {
const sharedModel = new YFile();
model = new CodeEditor.Model({ sharedModel });
});
afterEach(() => {
model.dispose();
});
describe('#constructor()', () => {
it('should create a CodeEditor Model', () => {
expect(model).toBeInstanceOf(CodeEditor.Model);
expect(model.sharedModel.getSource()).toBe('');
});
it('should create a CodeEditor Model with an initial value', () => {
const sharedEditorModel = new YFile();
sharedEditorModel.setSource('Initial text here');
const other = new CodeEditor.Model({ sharedModel: sharedEditorModel });
expect(other).toBeInstanceOf(CodeEditor.Model);
expect(other.sharedModel.getSource()).toBe('Initial text here');
other.dispose();
});
it('should create a CodeEditor Model with an initial mimetype', () => {
const sharedEditorModel = new YFile();
sharedEditorModel.setSource('import this');
const other = new CodeEditor.Model({
sharedModel: sharedEditorModel,
mimeType: 'text/x-python'
});
expect(other).toBeInstanceOf(CodeEditor.Model);
expect(other.mimeType).toBe('text/x-python');
expect(other.sharedModel.getSource()).toBe('import this');
other.dispose();
});
});
describe('#mimeTypeChanged', () => {
it('should be emitted when the mime type changes', () => {
let called = false;
model.mimeTypeChanged.connect((sender, args) => {
expect(sender).toBe(model);
expect(args.oldValue).toBe('text/plain');
expect(args.newValue).toBe('text/foo');
called = true;
});
model.mimeType = 'text/foo';
expect(called).toBe(true);
});
});
describe('#value', () => {
it('should be the observable value of the model', () => {
let called = false;
const handler = (sender: ISharedText, args: SourceChange) => {
expect(sender).toBe(model.sharedModel);
expect(args.sourceChange).toEqual([{ insert: 'foo' }]);
called = true;
};
model.sharedModel.changed.connect(handler);
model.sharedModel.setSource('foo');
expect(called).toBe(true);
model.sharedModel.changed.disconnect(handler);
});
it('should handle an insert', () => {
let called = false;
const handler = (sender: ISharedText, args: SourceChange) => {
expect(args.sourceChange).toEqual([{ insert: 'foo' }]);
called = true;
};
model.sharedModel.changed.connect(handler);
model.sharedModel.updateSource(0, 0, 'foo');
expect(called).toBe(true);
model.sharedModel.changed.disconnect(handler);
});
it('should handle a remove', () => {
let called = false;
model.sharedModel.setSource('foo');
const handler = (sender: ISharedText, args: SourceChange) => {
expect(args.sourceChange).toEqual([{ delete: 1 }]);
called = true;
};
model.sharedModel.changed.connect(handler);
model.sharedModel.updateSource(0, 1);
expect(called).toBe(true);
model.sharedModel.changed.disconnect(handler);
});
});
describe('#selections', () => {
it('should be the selections associated with the model', () => {
expect(model.selections.keys().length).toBe(0);
});
});
describe('#mimeType', () => {
it('should be the mime type of the model', () => {
expect(model.mimeType).toBe('text/plain');
model.mimeType = 'text/foo';
expect(model.mimeType).toBe('text/foo');
});
});
describe('#isDisposed', () => {
it('should test whether the model is disposed', () => {
expect(model.isDisposed).toBe(false);
model.dispose();
expect(model.isDisposed).toBe(true);
});
});
});