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 be settable', () => {
let model = new CodeCellModel({});
expect(model.executionCount).to.be(null);
model.executionCount = 1;
expect(model.executionCount).to.be(1);
});
it('should accept a code cell argument', () => {
const cell: nbformat.ICodeCell = {
cell_type: 'code',
execution_count: 1,
outputs: [
{
output_type: 'display_data',
data: { 'text/plain': 'foo' },
metadata: {}
} as nbformat.IDisplayData
],
source: 'foo',
metadata: { trusted: false }
};
const model = new CodeCellModel({ cell });
expect(model).to.be.an.instanceof(CodeCellModel);
expect(model.value.text).to.equal(cell.source);
});
it('should signal when model state has changed', () => {
const model = new CodeCellModel({});
let called = false;
const listener = (sender: any, args: IChangedArgs) => {
expect(args.newValue).to.equal(1);
called = true;
};
model.stateChanged.connect(listener);
model.executionCount = 1;
expect(called).to.equal(true);
});
it('should be an output area model', () => {
const model = new CodeCellModel({});
expect(model.outputs).to.be.an.instanceof(OutputAreaModel);
});
});
it('should show the execution count of the cell', () => {
const cell: nbformat.ICodeCell = {
cell_type: 'code',
execution_count: 1,
outputs: [],
source: 'foo',
metadata: { trusted: false }
};
const model = new CodeCellModel({ cell });
expect(model.executionCount).to.equal(1);
});
it('should be an output area model', () => {
const model = new CodeCellModel({});
expect(model.outputs).to.be.an.instanceof(OutputAreaModel);
});
});
it('should update the trusted state of the output models', () => {
let model = new CodeCellModel({});
model.outputs.add(DEFAULT_OUTPUTS[0]);
expect(model.outputs.get(0).trusted).to.be(false);
model.trusted = true;
expect(model.outputs.get(0).trusted).to.be(true);
});
cell_type: 'code',
execution_count: 1,
outputs: [
{
output_type: 'display_data',
data: {
'text/plain': 'foo',
'application/json': { bar: 1 }
},
metadata: {}
} as nbformat.IDisplayData
],
source: 'foo',
metadata: { trusted: false }
};
const model = new CodeCellModel({ cell });
const serialized = model.toJSON();
expect(serialized).to.not.equal(cell);
expect(serialized).to.deep.equal(cell);
const output = serialized.outputs[0] as any;
expect(output.data['application/json']['bar']).to.equal(1);
});
});
createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel {
if (!options.contentFactory) {
options.contentFactory = this.codeCellContentFactory;
}
return new CodeCellModel(options);
}
createCodeCell(options: CodeCellModel.IOptions): ICodeCellModel {
if (options.contentFactory) {
options.contentFactory = this.codeCellContentFactory;
}
if (this.modelDB) {
if (!options.id) {
options.id = UUID.uuid4();
}
options.modelDB = this.modelDB.view(options.id);
}
return new CodeCellModel(options);
}