This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
inputarea.spec.ts
162 lines (139 loc) · 5.16 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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { expect } from 'chai';
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', () => {
const widget = new InputArea({ model });
expect(widget).to.be.an.instanceof(InputArea);
});
});
describe('#model', () => {
it('should be the model used by the input area', () => {
const widget = new InputArea({ model });
expect(widget.model).to.equal(model);
});
});
describe('#contentFactory', () => {
it('should be the content factory used by the input area', () => {
const widget = new InputArea({ model });
expect(widget.contentFactory).to.equal(InputArea.defaultContentFactory);
});
});
describe('#editorWidget', () => {
it('should be the editor widget used by the input area', () => {
const widget = new InputArea({ model });
expect(widget.editorWidget).to.be.an.instanceof(CodeEditorWrapper);
});
});
describe('#editor', () => {
it('should be the code editor used by the cell', () => {
const widget = new InputArea({ model });
expect(widget.editor.host).to.equal(widget.editorWidget.node);
});
});
describe('#promptNode', () => {
it('should be the prompt node used by the cell', () => {
const widget = new InputArea({ model });
expect(widget.promptNode.className).to.contain('jp-InputPrompt');
});
});
describe('#renderInput()', () => {
it('should render the widget', () => {
const widget = new InputArea({ model });
const rendered = new Widget();
Widget.attach(widget, document.body);
widget.renderInput(rendered);
expect(rendered.isAttached).to.equal(true);
widget.dispose();
});
});
describe('#showEditor()', () => {
it('should be called to show the editor', () => {
const widget = new InputArea({ model });
const rendered = new Widget();
Widget.attach(widget, document.body);
widget.renderInput(rendered);
widget.showEditor();
expect(rendered.isAttached).to.equal(false);
widget.dispose();
});
});
describe('#setPrompt()', () => {
it('should change the value of the input prompt', () => {
const widget = new InputArea({ model });
const 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', () => {
const widget = new InputArea({ model });
widget.dispose();
expect(widget.isDisposed).to.equal(true);
widget.dispose();
expect(widget.isDisposed).to.equal(true);
});
});
describe('.ContentFactory', () => {
describe('#constructor()', () => {
it('should create a new content factory', () => {
const factory = new InputArea.ContentFactory();
expect(factory).to.be.an.instanceof(InputArea.ContentFactory);
});
});
describe('#editorFactory', () => {
it('should be the code editor factory being used', () => {
const factory = new InputArea.ContentFactory();
expect(factory.editorFactory).to.equal(
InputArea.defaultEditorFactory
);
});
});
describe('#createInputPrompt()', () => {
it('should create an input prompt', () => {
const factory = new InputArea.ContentFactory();
expect(factory.createInputPrompt()).to.be.an.instanceof(InputPrompt);
});
});
});
describe('.defaultContentFactory', () => {
it('should be an instance of the content factory', () => {
expect(InputArea.defaultContentFactory).to.be.an.instanceof(
InputArea.ContentFactory
);
});
});
describe('.defaultEditorFactory', () => {
it('should be an editor factory', () => {
const factory = InputArea.defaultEditorFactory;
const host = document.createElement('div');
expect(factory({ host, model }).host).to.equal(host);
});
});
});
describe('InputPrompt', () => {
describe('#constructor()', () => {
it('should create an input prompt', () => {
const widget = new InputPrompt();
expect(widget).to.be.an.instanceof(InputPrompt);
});
});
describe('#executionCount', () => {
it('should be the execution count for the prompt', () => {
const widget = new InputPrompt();
expect(widget.executionCount).to.be.null;
widget.executionCount = '1';
expect(widget.executionCount).to.equal('1');
});
});
});
});