forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputarea.spec.ts
208 lines (141 loc) · 5.04 KB
/
inputarea.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import expect = require('expect.js');
import {
Widget
} from '@phosphor/widgets';
import {
CodeEditorWrapper
} from '@jupyterlab/codeeditor';
import {
InputArea, InputPrompt, CodeCellModel
} from '@jupyterlab/cells';
const PROMPT_CLASS = 'jp-InputArea-prompt';
describe('@jupyterlab/cells', () => {
const model = new CodeCellModel({});
describe('InputArea', () => {
describe('#constructor()', () => {
it('should create an input area widget', () => {
let widget = new InputArea({ model });
expect(widget).to.be.an(InputArea);
});
});
describe('#model', () => {
it('should be the model used by the input area', () => {
let widget = new InputArea({ model });
expect(widget.model).to.be(model);
});
});
describe('#contentFactory', () => {
it('should be the content factory used by the input area', () => {
let widget = new InputArea({ model });
expect(widget.contentFactory).to.be(InputArea.defaultContentFactory);
});
});
describe('#editorWidget', () => {
it('should be the editor widget used by the input area', () => {
let widget = new InputArea({ model });
expect(widget.editorWidget).to.be.a(CodeEditorWrapper);
});
});
describe('#editor', () => {
it('should be the code editor used by the cell', () => {
let widget = new InputArea({ model });
expect(widget.editor.host).to.be(widget.editorWidget.node);
});
});
describe('#promptNode', () => {
it('should be the prompt node used by the cell', () => {
let widget = new InputArea({ model });
expect(widget.promptNode.className).to.contain('jp-InputPrompt');
});
});
describe('#renderInput()', () => {
it('should render the widget', () => {
let widget = new InputArea({ model });
let rendered = new Widget();
Widget.attach(widget, document.body);
widget.renderInput(rendered);
expect(rendered.isAttached).to.be(true);
widget.dispose();
});
});
describe('#showEditor()', () => {
it('should be called to show the editor', () => {
let widget = new InputArea({ model });
let rendered = new Widget();
Widget.attach(widget, document.body);
widget.renderInput(rendered);
widget.showEditor();
expect(rendered.isAttached).to.be(false);
widget.dispose();
});
});
describe('#setPrompt()', () => {
it('should change the value of the input prompt', () => {
let widget = new InputArea({ model });
let prompt = widget.node.querySelector(`.${PROMPT_CLASS}`);
expect(prompt.textContent).to.be.empty();
widget.setPrompt('foo');
expect(prompt.textContent).to.contain('foo');
});
});
describe('#dispose()', () => {
it('should dispose of the resources used by the widget', () => {
let widget = new InputArea({ model });
widget.dispose();
expect(widget.isDisposed).to.be(true);
widget.dispose();
expect(widget.isDisposed).to.be(true);
});
});
describe('.ContentFactory', () => {
describe('#constructor()', () => {
it('should create a new content factory', () => {
let factory = new InputArea.ContentFactory();
expect(factory).to.be.an(InputArea.ContentFactory);
});
});
describe('#editorFactory', () => {
it('should be the code editor factory being used', () => {
let factory = new InputArea.ContentFactory();
expect(factory.editorFactory).to.be(InputArea.defaultEditorFactory);
});
});
describe('#createInputPrompt()', () => {
it('should create an input prompt', () => {
let factory = new InputArea.ContentFactory();
expect(factory.createInputPrompt()).to.be.an(InputPrompt);
});
});
});
describe('.defaultContentFactory', () => {
it('should be an instance of the content factory', () => {
expect(InputArea.defaultContentFactory).to.be.an(InputArea.ContentFactory);
});
});
describe('.defaultEditorFactory', () => {
it('should be an editor factory', () => {
let factory = InputArea.defaultEditorFactory;
let host = document.createElement('div');
expect(factory({ host, model }).host).to.be(host);
});
});
});
describe('InputPrompt', () => {
describe('#constructor()', () => {
it('should create an input prompt', () => {
let widget = new InputPrompt();
expect(widget).to.be.an(InputPrompt);
});
});
describe('#executionCount', () => {
it('should be the execution count for the prompt', () => {
let widget = new InputPrompt();
expect(widget.executionCount).to.be(null);
widget.executionCount = '1';
expect(widget.executionCount).to.be('1');
});
});
});
});