forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modelfactory.spec.ts
118 lines (100 loc) · 3.96 KB
/
modelfactory.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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { expect } from 'chai';
import { CodeCellModel } from '@jupyterlab/cells';
import { NotebookModel } from '@jupyterlab/notebook';
import { NotebookModelFactory } from '@jupyterlab/notebook';
describe('@jupyterlab/notebook', () => {
describe('NotebookModelFactory', () => {
describe('#constructor', () => {
it('should create a new notebook model factory', () => {
const factory = new NotebookModelFactory({});
expect(factory).to.be.an.instanceof(NotebookModelFactory);
});
it('should accept a code cell content factory', () => {
const codeCellContentFactory = new CodeCellModel.ContentFactory();
const factory = new NotebookModelFactory({ codeCellContentFactory });
expect(factory.contentFactory.codeCellContentFactory).to.equal(
codeCellContentFactory
);
});
it('should accept a notebook model content factory', () => {
const contentFactory = new NotebookModel.ContentFactory({});
const factory = new NotebookModelFactory({ contentFactory });
expect(factory.contentFactory).to.equal(contentFactory);
});
});
describe('#contentFactory', () => {
it('should be the content factory used by the model factory', () => {
const factory = new NotebookModelFactory({});
expect(factory.contentFactory).to.be.an.instanceof(
NotebookModel.ContentFactory
);
});
});
describe('#name', () => {
it('should get the name of the model factory', () => {
const factory = new NotebookModelFactory({});
expect(factory.name).to.equal('notebook');
});
});
describe('#contentType', () => {
it('should get the file type', () => {
const factory = new NotebookModelFactory({});
expect(factory.contentType).to.equal('notebook');
});
});
describe('#fileFormat', () => {
it('should get the file format', () => {
const factory = new NotebookModelFactory({});
expect(factory.fileFormat).to.equal('json');
});
});
describe('#isDisposed', () => {
it('should get whether the factory is disposed', () => {
const factory = new NotebookModelFactory({});
expect(factory.isDisposed).to.equal(false);
factory.dispose();
expect(factory.isDisposed).to.equal(true);
});
});
describe('#dispose()', () => {
it('should dispose of the model factory', () => {
const factory = new NotebookModelFactory({});
factory.dispose();
expect(factory.isDisposed).to.equal(true);
});
it('should be safe to call multiple times', () => {
const factory = new NotebookModelFactory({});
factory.dispose();
factory.dispose();
expect(factory.isDisposed).to.equal(true);
});
});
describe('#createNew()', () => {
it('should create a new model for a given path', () => {
const factory = new NotebookModelFactory({});
const model = factory.createNew();
expect(model).to.be.an.instanceof(NotebookModel);
});
it('should add an empty code cell by default', () => {
const factory = new NotebookModelFactory({});
const model = factory.createNew();
expect(model.cells.length).to.equal(1);
expect(model.cells.get(0).type).to.equal('code');
});
it('should accept a language preference', () => {
const factory = new NotebookModelFactory({});
const model = factory.createNew('foo');
expect(model.defaultKernelLanguage).to.equal('foo');
});
});
describe('#preferredLanguage()', () => {
it('should always return an empty string', () => {
const factory = new NotebookModelFactory({});
expect(factory.preferredLanguage('')).to.equal('');
expect(factory.preferredLanguage('.ipynb')).to.equal('');
});
});
});
});