mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 01:25:39 -05:00
Notebooks: Add Support for Cell Attachment Images (#14449)
* Add to interfaces * Works E2E * Consolidate interface * Add comments, cleanup * Add some tests * Cleanup * interface cleanup * Add more tests * Add comments * Add type for cell attachment * wip
This commit is contained in:
@@ -61,4 +61,24 @@ suite('NotebookMarkdownRenderer', () => {
|
||||
assert.strictEqual(result.innerHTML, `<p><a href="/maddy/test/.build/someimageurl" data-href="/maddy/test/.build/someimageurl" title="/maddy/test/.build/someimageurl">Link to relative path</a></p>`);
|
||||
}
|
||||
});
|
||||
|
||||
test('cell attachment image', () => {
|
||||
let result: HTMLElement = notebookMarkdownRenderer.renderMarkdown({ value: ``, isTrusted: true }, { cellAttachments: JSON.parse('{"ads.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}') });
|
||||
assert.strictEqual(result.innerHTML, `<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAggg==" alt="altText"></p>`, 'Cell attachment basic test failed when trusted');
|
||||
|
||||
result = notebookMarkdownRenderer.renderMarkdown({ value: ``, isTrusted: false }, { cellAttachments: JSON.parse('{"ads.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}') });
|
||||
assert.strictEqual(result.innerHTML, `<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAggg==" alt="altText"></p>`, 'Cell attachment basic test failed when not trusted');
|
||||
|
||||
result = notebookMarkdownRenderer.renderMarkdown({ value: ``, isTrusted: true });
|
||||
assert.strictEqual(result.innerHTML, `<p><img src="attachment:ads.png" alt="altText"></p>`, 'Cell attachment no attachment included failed');
|
||||
|
||||
result = notebookMarkdownRenderer.renderMarkdown({ value: ``, isTrusted: true }, { cellAttachments: JSON.parse('{"ads2.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}') });
|
||||
assert.strictEqual(result.innerHTML, `<p><img src="attachment:ads.png" alt="altText"></p>`, 'Cell attachment name not found failed');
|
||||
|
||||
result = notebookMarkdownRenderer.renderMarkdown({ value: ``, isTrusted: true }, { cellAttachments: JSON.parse('{"ads2.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}') });
|
||||
assert.strictEqual(result.innerHTML, `<p><img src="attachments:ads.png" alt="altText"></p>`, 'Cell attachment scheme mismatch failed');
|
||||
|
||||
result = notebookMarkdownRenderer.renderMarkdown({ value: ``, isTrusted: true }, { cellAttachments: JSON.parse('{"ads2.png":"image/png"}') });
|
||||
assert.strictEqual(result.innerHTML, `<p><img src="attachment:ads.png" alt="altText"></p>`, 'Cell attachment no image data failed');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1040,4 +1040,37 @@ suite('Cell Model', function (): void {
|
||||
assert.equal(model.savedConnectionName, connectionName);
|
||||
});
|
||||
|
||||
test('Should read attachments name from notebook 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.Code,
|
||||
source: '',
|
||||
attachments: cellAttachment
|
||||
};
|
||||
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
|
||||
assert.deepEqual(model.attachments, contents.attachments);
|
||||
});
|
||||
|
||||
test('Should read attachments name from notebook attachments', async function () {
|
||||
let notebookModel = new NotebookModelStub({
|
||||
name: '',
|
||||
version: '',
|
||||
mimetype: ''
|
||||
});
|
||||
let contents: nb.ICellContents = {
|
||||
cell_type: CellTypes.Code,
|
||||
source: ''
|
||||
};
|
||||
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
|
||||
assert.deepEqual(model.attachments, {});
|
||||
|
||||
contents.attachments = undefined;
|
||||
model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
|
||||
assert.deepEqual(model.attachments, {});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user