forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel.spec.ts
108 lines (90 loc) · 3.36 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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { expect } from 'chai';
import { Context } from '@jupyterlab/docregistry';
import { INotebookModel, NotebookPanel, Notebook } from '@jupyterlab/notebook';
import { Toolbar } from '@jupyterlab/apputils';
import { initNotebookContext, NBTestUtils } from '@jupyterlab/testutils';
/**
* Default data.
*/
const contentFactory = NBTestUtils.createNotebookPanelFactory();
describe('@jupyterlab/notebook', () => {
describe('NotebookPanel', () => {
let context: Context<INotebookModel>;
beforeEach(async () => {
context = await initNotebookContext();
});
afterEach(() => {
context.dispose();
});
describe('#constructor()', () => {
it('should create a notebook panel', () => {
const content = NBTestUtils.createNotebook();
const panel = new NotebookPanel({ context, content });
expect(panel).to.be.an.instanceof(NotebookPanel);
});
it('should change notebook to edit mode if we have a single empty code cell', async () => {
const panel = NBTestUtils.createNotebookPanel(context);
const model = panel.content.model;
expect(model).to.equal(context.model);
await context.initialize(true);
await context.ready;
expect(panel.content.mode).to.equal('edit');
});
});
describe('#toolbar', () => {
it('should be the toolbar used by the widget', () => {
const panel = NBTestUtils.createNotebookPanel(context);
expect(panel.toolbar).to.be.an.instanceof(Toolbar);
});
});
describe('#content', () => {
it('should be the notebook content widget', () => {
const panel = NBTestUtils.createNotebookPanel(context);
expect(panel.content).to.be.an.instanceof(Notebook);
});
});
describe('#context', () => {
it('should get the document context for the widget', () => {
const panel = NBTestUtils.createNotebookPanel(context);
expect(panel.context).to.equal(context);
});
});
describe('#dispose()', () => {
it('should dispose of the resources used by the widget', () => {
const panel = NBTestUtils.createNotebookPanel(context);
panel.dispose();
expect(panel.isDisposed).to.equal(true);
});
it('should be safe to call more than once', () => {
const panel = NBTestUtils.createNotebookPanel(context);
panel.dispose();
panel.dispose();
expect(panel.isDisposed).to.equal(true);
});
});
describe('.ContentFactory', () => {
describe('#constructor', () => {
it('should create a new ContentFactory', () => {
const factory = new NotebookPanel.ContentFactory({
editorFactory: NBTestUtils.editorFactory
});
expect(factory).to.be.an.instanceof(NotebookPanel.ContentFactory);
});
});
describe('#NBTestUtils.createNotebook()', () => {
it('should create a notebook widget', () => {
const options = {
contentFactory: contentFactory,
rendermime: NBTestUtils.defaultRenderMime(),
mimeTypeService: NBTestUtils.mimeTypeService
};
expect(contentFactory.createNotebook(options)).to.be.an.instanceof(
Notebook
);
});
});
});
});
});