mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-27 17:23:21 -05:00
Fix split cell not working with attachments (#19587)
This commit is contained in:
@@ -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: '',
|
||||
attachments: cellAttachment
|
||||
};
|
||||
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
|
||||
|
||||
model.source = ' \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: ''
|
||||
};
|
||||
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
|
||||
model.updateAttachmentsFromSource('', 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: ''
|
||||
};
|
||||
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: ''
|
||||
};
|
||||
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: '',
|
||||
|
||||
Reference in New Issue
Block a user