From 2a6fcee9133bc485c848978e81700eb586c97be2 Mon Sep 17 00:00:00 2001 From: Barbara Valdez <34872381+barbaravaldez@users.noreply.github.com> Date: Mon, 6 Jul 2020 16:58:19 -0700 Subject: [PATCH] Add more tests to local content manager (#10350) * Add more tests * Add descriptive messages to asserts and remove formats check * Address comments --- .../electron-browser/contentManagers.test.ts | 76 +++++++++++++++++-- 1 file changed, 70 insertions(+), 6 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/test/electron-browser/contentManagers.test.ts b/src/sql/workbench/contrib/notebook/test/electron-browser/contentManagers.test.ts index 873835cb3b..7aaecb149c 100644 --- a/src/sql/workbench/contrib/notebook/test/electron-browser/contentManagers.test.ts +++ b/src/sql/workbench/contrib/notebook/test/electron-browser/contentManagers.test.ts @@ -33,6 +33,7 @@ let expectedNotebookContent: nb.INotebookContents = { nbformat: 4, nbformat_minor: 2 }; + let notebookContentString = JSON.stringify(expectedNotebookContent); function verifyMatchesExpectedNotebook(notebook: nb.INotebookContents): void { @@ -131,12 +132,75 @@ suite('Local Content Manager', function (): void { let displayOutput = notebook.cells[0].outputs[0]; assert.equal(displayOutput.data['text/html'], '
'); }); - test('Should create a new empty notebook if content is undefined', async function (): Promise { - // verify that when loading content from an empty string or undefined, a new notebook is created. - let content = await contentManager.loadFromContentString(''); - assert.equal(content.cells.length, 0); - content = await contentManager.loadFromContentString(undefined); - assert.equal(content.cells.length, 0); + test('Should create a new empty notebook if content is undefined', async function (): Promise { + // verify that when loading content from an empty string, a new notebook is created. + let content = await contentManager.loadFromContentString(undefined); + assert.equal(content.metadata, undefined, 'Verify that metadata is undefined'); + // verify that the notebook is empty + assert.equal(content.cells.length, 0, 'Notebook should be empty, so the number of cells should be 0'); + }); + + test('Should create a new empty notebook if content is an empty string', async function (): Promise { + // verify that when loading content from an empty string, a new notebook is created. + let content = await contentManager.loadFromContentString(''); + assert.equal(content.metadata, undefined, 'Verify that metadata is undefined'); + // verify that the notebook is empty + assert.equal(content.cells.length, 0, 'Notebook should be empty, so the number of cells should be 0'); + }); + + test('Should create a markdown cell', async function (): Promise { + let expectedNotebookMarkdownContent: nb.INotebookContents = { + cells: [{ + cell_type: CellTypes.Markdown, + source: '# Header 1' + }], + metadata: { + kernelspec: { + name: 'mssql', + language: 'sql' + } + }, + nbformat: 4, + nbformat_minor: 2 + }; + let markdownNotebookContent = JSON.stringify(expectedNotebookMarkdownContent); + // verify that notebooks support markdown cells + let notebook = await contentManager.loadFromContentString(markdownNotebookContent); + // assert that markdown cell is supported by + // verifying the notebook matches the expectedNotebookMarkdownContent format + assert.equal(notebook.cells.length, 1, 'The number of cells should be equal to 1'); + assert.equal(notebook.cells[0].cell_type, CellTypes.Markdown, 'The cell type should be markdown'); + assert.equal(notebook.cells[0].source, expectedNotebookMarkdownContent.cells[0].source, 'The content of the cell must match the expectedNotebookMarkdownContent'); + }); + + test('Should allow stream for output types', async function (): Promise { + let expectedNotebookStreamOutputContent: nb.INotebookContents = { + cells: [{ + cell_type: CellTypes.Code, + source: [], + metadata: { language: 'python' }, + execution_count: 1, + outputs: [ + { + output_type: 'stream', + text: 'Select * FROM database WHERE x = 0 \nSelect * FROM database WHERE x = 0\n' + } + ] + }], + metadata: { + kernelspec: { + name: 'Python 3', + language: 'python3' + } + }, + nbformat: 4, + nbformat_minor: 2 + }; + let streamOutputContent = JSON.stringify(expectedNotebookStreamOutputContent); + // Verify that the stream output type is supported + let notebook = await contentManager.loadFromContentString(streamOutputContent); + assert.equal(notebook.cells[0].outputs[0].output_type, 'stream', 'Cell output from notebook should be stream'); + assert.equal(notebook.cells[0].cell_type, expectedNotebookStreamOutputContent.cells[0].cell_type, 'Cell type of notebook should match the expectedNotebookStreamOutputContent'); }); });