Only serialize attachments in JSON if exists (#14516)

This commit is contained in:
Chris LaFreniere
2021-03-03 09:06:16 -08:00
committed by GitHub
parent 3f0ca8b714
commit 56dcd4ba50
2 changed files with 11 additions and 9 deletions

View File

@@ -1048,15 +1048,18 @@ suite('Cell Model', function (): void {
mimetype: ''
});
let contents: nb.ICellContents = {
cell_type: CellTypes.Code,
cell_type: CellTypes.Markdown,
source: '',
attachments: cellAttachment
};
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
assert.deepEqual(model.attachments, contents.attachments);
assert.deepEqual(model.attachments, contents.attachments, 'Attachments do not match in cellModel');
let serializedCell = model.toJSON();
assert.deepEqual(serializedCell.attachments, cellAttachment, 'Cell attachment from JSON is incorrect');
});
test('Should read attachments name from notebook attachments', async function () {
test('Should not include attachments in notebook json if no attachments exist', async function () {
let notebookModel = new NotebookModelStub({
name: '',
version: '',
@@ -1067,10 +1070,9 @@ suite('Cell Model', function (): void {
source: ''
};
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
assert.deepEqual(model.attachments, {});
assert.deepEqual(model.attachments, undefined, 'Cell model attachments should return undefined if they do not exist');
contents.attachments = undefined;
model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
assert.deepEqual(model.attachments, {});
let serializedCell = model.toJSON();
assert.deepEqual(serializedCell.attachments, undefined, 'JSON should not include attachments if attachments do not exist');
});
});