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 set the cell prompt properly while executing', async () => {
const widget = new CodeCell({ model, rendermime, contentFactory });
widget.initializeState();
widget.model.value.text = 'foo';
const future1 = CodeCell.execute(widget, session);
expect(widget.promptNode.textContent).toEqual('[*]:');
const future2 = CodeCell.execute(widget, session);
expect(widget.promptNode.textContent).toEqual('[*]:');
await expect(future1).rejects.toThrow('Canceled');
expect(widget.promptNode.textContent).toEqual('[*]:');
let msg = await future2;
expect(msg).not.toBeUndefined;
// The `if` is a Typescript type guard so that msg.content works below.
if (msg) {
expect(widget.promptNode.textContent).toEqual(
`[${msg.content.execution_count}]:`
);
it('should save the collapse state to the model `collapsed` metadata', () => {
const model = new CodeCellModel({});
let widget = new CodeCell({ model, rendermime });
widget.initializeState();
expect(widget.outputHidden).toEqual(false);
widget.outputHidden = true;
widget.saveCollapseState();
expect(model.metadata.get('collapsed')).toEqual(true);
// Default values are not saved explicitly
widget.outputHidden = false;
widget.saveCollapseState();
expect(model.metadata.get('collapsed')).toEqual(undefined);
// Default values are explicitly deleted
model.metadata.set('collapsed', false);
widget.outputHidden = false;
widget.saveCollapseState();
it('should save the collapse state to the model', () => {
const model = new CodeCellModel({});
let widget = new CodeCell({ model, rendermime });
widget.initializeState();
expect(widget.outputsScrolled).toEqual(false);
widget.outputsScrolled = true;
widget.saveScrolledState();
expect(model.metadata.get('scrolled')).toEqual(true);
widget.outputsScrolled = false;
widget.saveScrolledState();
// Default values are not saved explicitly
expect(model.metadata.get('scrolled')).toEqual(undefined);
});
});
it('should accept a custom contentFactory', () => {
const contentFactory = NBTestUtils.createCodeCellFactory();
const widget = new CodeCell({ model, contentFactory, rendermime });
widget.initializeState();
expect(widget).toBeInstanceOf(CodeCell);
});
});
it('should add a code cell to the content widget', () => {
const contentFactory = NBTestUtils.createCodeCellFactory();
const model = new CodeCellModel({});
const cell = new CodeCell({
model,
contentFactory,
rendermime
}).initializeState();
Widget.attach(widget, document.body);
expect(widget.cells.length).to.equal(0);
widget.addCell(cell);
expect(widget.cells.length).to.equal(1);
});
});
it('should load the output collapse state from the model', () => {
const model = new CodeCellModel({});
let widget = new CodeCell({ model, rendermime });
widget.initializeState();
widget.loadCollapseState();
expect(widget.outputHidden).toEqual(false);
model.metadata.set('collapsed', true);
widget.loadCollapseState();
expect(widget.outputHidden).toEqual(true);
model.metadata.set('collapsed', false);
widget.loadCollapseState();
expect(widget.outputHidden).toEqual(false);
});
});
it('should fulfill a promise if there is code to execute', async () => {
const widget = new CodeCell({ model, rendermime, contentFactory });
widget.initializeState();
let originalCount: number;
widget.model.value.text = 'foo';
originalCount = widget.model.executionCount;
await CodeCell.execute(widget, session);
const executionCount = widget.model.executionCount;
expect(executionCount).not.toEqual(originalCount);
});
it('should be the view state of the output being collapsed', () => {
const widget = new CodeCell({ model, rendermime });
widget.initializeState();
expect(widget.outputHidden).toEqual(false);
widget.outputHidden = true;
expect(widget.outputHidden).toEqual(true);
});
});
createCodeCell(options: CodeCell.IOptions): CodeCell {
if (!options.contentFactory) {
options.contentFactory = this;
}
return new CodeCell(options).initializeState();
}
createCodeCell(options: CodeCell.IOptions, parent: StaticNotebook): CodeCell {
if (!options.contentFactory) {
options.contentFactory = this;
}
return new CodeCell(options);
}