Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should initialize the model when the file is saved for the first time', async () => {
const context = await createNotebookContext();
context.model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
expect(context.model.cells.canUndo).to.equal(true);
await context.initialize(true);
await context.ready;
expect(context.model.cells.canUndo).to.equal(false);
});
it('should initialize the model when the file is reverted for the first time', async () => {
const context = await initNotebookContext();
await manager.contents.save(context.path, {
type: 'notebook',
format: 'json',
content: NBTestUtils.DEFAULT_CONTENT
});
context.model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
expect(context.model.cells.canUndo).to.equal(true);
await context.initialize(false);
await context.ready;
expect(context.model.cells.canUndo).to.equal(false);
});
});
it('should update the active cell if necessary', () => {
const widget = createActiveWidget();
widget.model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
widget.activeCellIndex = 1;
expect(widget.activeCell).to.equal(widget.widgets[1]);
});
});
it('should be reset when loading from disk', () => {
const model = new NotebookModel();
const cell = model.contentFactory.createCodeCell({});
model.cells.push(cell);
model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
expect(ArrayExt.firstIndexOf(toArray(model.cells), cell)).to.equal(-1);
expect(model.cells.length).to.equal(6);
});
it('should initialize the model when the file is reverted for the first time', async () => {
const context = await createNotebookContext();
await manager.contents.save(context.path, {
type: 'notebook',
format: 'json',
content: NBTestUtils.DEFAULT_CONTENT
});
context.model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
expect(context.model.cells.canUndo).to.equal(true);
await context.initialize(false);
await context.ready;
expect(context.model.cells.canUndo).to.equal(false);
});
});
it('should emit a signal when the active cell changes', async () => {
const tracker = new NotebookTracker({ namespace });
const panel = NBTestUtils.createNotebookPanel(context);
let count = 0;
tracker.activeCellChanged.connect(() => {
count++;
});
panel.content.model!.fromJSON(NBTestUtils.DEFAULT_CONTENT);
await tracker.add(panel);
expect(count).to.equal(1);
panel.content.activeCellIndex = 1;
expect(count).to.equal(2);
panel.dispose();
});
});
it('should serialize the model from JSON', () => {
const model = new NotebookModel();
model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
expect(model.cells.length).to.equal(6);
expect(model.nbformat).to.equal(NBTestUtils.DEFAULT_CONTENT.nbformat);
expect(model.nbformatMinor).to.equal(nbformat.MINOR_VERSION);
});
it('should add the model cells to the layout', () => {
const widget = new LogStaticNotebook(options);
const model = new NotebookModel();
model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
widget.model = model;
expect(widget.widgets.length).to.equal(6);
});
beforeEach(async () => {
context = await initNotebookContext({ startKernel: true });
panel = NBTestUtils.createNotebookPanel(context);
context.model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
});
beforeEach(async () => {
context = await initNotebookContext();
panel = NBTestUtils.createNotebookPanel(context);
context.model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
});