/
panel.spec.ts
142 lines (118 loc) · 3.98 KB
/
panel.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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { expect } from 'chai';
import { ServiceManager } from '@jupyterlab/services';
import { Message, MessageLoop } from '@lumino/messaging';
import { Widget } from '@lumino/widgets';
import { CodeConsole, ConsolePanel } from '@jupyterlab/console';
import { dismissDialog } from '@jupyterlab/testutils';
import {
createConsolePanelFactory,
rendermime,
mimeTypeService,
editorFactory
} from './utils';
class TestPanel extends ConsolePanel {
methods: string[] = [];
protected onActivateRequest(msg: Message): void {
super.onActivateRequest(msg);
this.methods.push('onActivateRequest');
}
protected onCloseRequest(msg: Message): void {
super.onCloseRequest(msg);
this.methods.push('onCloseRequest');
}
}
const contentFactory = createConsolePanelFactory();
describe('console/panel', () => {
let panel: TestPanel;
const manager = new ServiceManager({ standby: 'never' });
before(() => {
return manager.ready;
});
beforeEach(() => {
panel = new TestPanel({
manager,
contentFactory,
rendermime,
mimeTypeService
});
});
afterEach(() => {
panel.dispose();
});
describe('ConsolePanel', () => {
describe('#constructor()', () => {
it('should create a new console panel', () => {
expect(panel).to.be.an.instanceof(ConsolePanel);
expect(Array.from(panel.node.classList)).to.contain('jp-ConsolePanel');
});
});
describe('#console', () => {
it('should be a code console widget created at instantiation', () => {
expect(panel.console).to.be.an.instanceof(CodeConsole);
});
});
describe('#session', () => {
it('should be a client session object', () => {
expect(panel.session.path).to.be.ok;
});
});
describe('#dispose()', () => {
it('should dispose of the resources held by the panel', () => {
panel.dispose();
expect(panel.isDisposed).to.equal(true);
panel.dispose();
expect(panel.isDisposed).to.equal(true);
});
});
describe('#onAfterAttach()', () => {
it('should start the session', async () => {
Widget.attach(panel, document.body);
await dismissDialog();
return panel.session.ready;
});
});
describe('#onActivateRequest()', () => {
it('should give the focus to the console prompt', () => {
expect(panel.methods).to.not.contain('onActivateRequest');
Widget.attach(panel, document.body);
MessageLoop.sendMessage(panel, Widget.Msg.ActivateRequest);
expect(panel.methods).to.contain('onActivateRequest');
expect(panel.console.promptCell.editor.hasFocus()).to.equal(true);
return dismissDialog();
});
});
describe('#onCloseRequest()', () => {
it('should dispose of the panel resources after closing', () => {
expect(panel.methods).to.not.contain('onCloseRequest');
Widget.attach(panel, document.body);
expect(panel.isDisposed).to.equal(false);
MessageLoop.sendMessage(panel, Widget.Msg.CloseRequest);
expect(panel.methods).to.contain('onCloseRequest');
expect(panel.isDisposed).to.equal(true);
});
});
describe('.ContentFactory', () => {
describe('#constructor', () => {
it('should create a new code console factory', () => {
const factory = new ConsolePanel.ContentFactory({ editorFactory });
expect(factory).to.be.an.instanceof(ConsolePanel.ContentFactory);
});
});
describe('#createConsole()', () => {
it('should create a console widget', () => {
const options = {
contentFactory: contentFactory,
rendermime,
mimeTypeService,
session: panel.session
};
expect(contentFactory.createConsole(options)).to.be.an.instanceof(
CodeConsole
);
});
});
});
});
});