mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Only serialize attachments in JSON if exists (#14516)
This commit is contained in:
@@ -1048,15 +1048,18 @@ suite('Cell Model', function (): void {
|
|||||||
mimetype: ''
|
mimetype: ''
|
||||||
});
|
});
|
||||||
let contents: nb.ICellContents = {
|
let contents: nb.ICellContents = {
|
||||||
cell_type: CellTypes.Code,
|
cell_type: CellTypes.Markdown,
|
||||||
source: '',
|
source: '',
|
||||||
attachments: cellAttachment
|
attachments: cellAttachment
|
||||||
};
|
};
|
||||||
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
|
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({
|
let notebookModel = new NotebookModelStub({
|
||||||
name: '',
|
name: '',
|
||||||
version: '',
|
version: '',
|
||||||
@@ -1067,10 +1070,9 @@ suite('Cell Model', function (): void {
|
|||||||
source: ''
|
source: ''
|
||||||
};
|
};
|
||||||
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
|
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;
|
let serializedCell = model.toJSON();
|
||||||
model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
|
assert.deepEqual(serializedCell.attachments, undefined, 'JSON should not include attachments if attachments do not exist');
|
||||||
assert.deepEqual(model.attachments, {});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -850,7 +850,7 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
if (this._configurationService?.getValue('notebook.saveConnectionName')) {
|
if (this._configurationService?.getValue('notebook.saveConnectionName')) {
|
||||||
metadata.connection_name = this._savedConnectionName;
|
metadata.connection_name = this._savedConnectionName;
|
||||||
}
|
}
|
||||||
} else if (this._cellType === CellTypes.Markdown) {
|
} else if (this._cellType === CellTypes.Markdown && this._attachments) {
|
||||||
cellJson.attachments = this._attachments;
|
cellJson.attachments = this._attachments;
|
||||||
}
|
}
|
||||||
return cellJson as nb.ICellContents;
|
return cellJson as nb.ICellContents;
|
||||||
@@ -873,7 +873,7 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
this._isParameter = false;
|
this._isParameter = false;
|
||||||
this._isInjectedParameter = false;
|
this._isInjectedParameter = false;
|
||||||
}
|
}
|
||||||
this._attachments = cell.attachments || {};
|
this._attachments = cell.attachments;
|
||||||
this._cellGuid = cell.metadata && cell.metadata.azdata_cell_guid ? cell.metadata.azdata_cell_guid : generateUuid();
|
this._cellGuid = cell.metadata && cell.metadata.azdata_cell_guid ? cell.metadata.azdata_cell_guid : generateUuid();
|
||||||
this.setLanguageFromContents(cell);
|
this.setLanguageFromContents(cell);
|
||||||
this._savedConnectionName = this._metadata.connection_name;
|
this._savedConnectionName = this._metadata.connection_name;
|
||||||
|
|||||||
Reference in New Issue
Block a user