Fix split cell not working with attachments (#19587)

This commit is contained in:
Barbara Valdez
2022-06-01 16:23:46 -07:00
committed by GitHub
parent 071f631c34
commit f06fd7f6f7
4 changed files with 108 additions and 8 deletions

View File

@@ -1079,6 +1079,96 @@ suite('Cell Model', function (): void {
assert.deepStrictEqual(serializedCell.attachments, undefined, 'JSON should not include attachments if attachments do not exist');
});
test('Should remove unused attachments name when updating cell source', async function () {
const cellAttachment = JSON.parse('{"ads.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}');
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let contents: nb.ICellContents = {
cell_type: CellTypes.Markdown,
source: '',
attachments: cellAttachment
};
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
assert.deepStrictEqual(model.attachments, contents.attachments, 'Attachments do not match in cellModel');
model.source = 'Test';
assert.notDeepStrictEqual(model.attachments, contents.attachments, 'Unused attachments are not removed after updating cell source');
});
test('Should not remove attachments that are still referenced in cell after updating the cell source', async function () {
const cellAttachment = JSON.parse('{"ads.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}');
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let contents: nb.ICellContents = {
cell_type: CellTypes.Markdown,
source: '![ads.png](attachment:ads.png)',
attachments: cellAttachment
};
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
model.source = '![ads.png](attachment:ads.png) \n Test';
assert.deepStrictEqual(model.attachments, contents.attachments, 'Attachments referenced in cell were removed');
});
test('Should update cell attachments', async function () {
const cellAttachment = JSON.parse('{"ads.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}');
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let contents: nb.ICellContents = {
cell_type: CellTypes.Markdown,
source: '![ads.png](attachment:ads.png)'
};
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
model.updateAttachmentsFromSource('![ads.png](attachment:ads.png)', cellAttachment);
assert.deepStrictEqual(model.attachments, cellAttachment, 'Cell attachments are not updated correctly');
});
test('Should not update cell attachments if they are not referenced in cell source', async function () {
const cellAttachment = JSON.parse('{"ads.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}');
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let contents: nb.ICellContents = {
cell_type: CellTypes.Markdown,
source: '![ads.png](attachment:ads.png)'
};
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
model.updateAttachmentsFromSource('test', cellAttachment);
assert.notDeepStrictEqual(model.attachments, cellAttachment, 'Cell attachments are updated when they are not referenced in cell source');
});
test('Should not update cell attachments if the attachment reference is not in the correct format', async function () {
const cellAttachment = JSON.parse('{"ads.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}');
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let contents: nb.ICellContents = {
cell_type: CellTypes.Markdown,
source: '![ads.png](attachment:ads.png)'
};
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
model.updateAttachmentsFromSource('ads.png', cellAttachment);
assert.notDeepStrictEqual(model.attachments, cellAttachment, 'Cell attachments are updated when the reference is not in the correct format');
});
test('Should not have cache chart data after new cell created', async function () {
let notebookModel = new NotebookModelStub({
name: '',