mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 01:25:36 -05:00
Add more tests to local content manager (#10350)
* Add more tests * Add descriptive messages to asserts and remove formats check * Address comments
This commit is contained in:
@@ -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 = <nb.IDisplayData>notebook.cells[0].outputs[0];
|
||||
assert.equal(displayOutput.data['text/html'], '<div></div>');
|
||||
});
|
||||
test('Should create a new empty notebook if content is undefined', async function (): Promise<void> {
|
||||
// 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<void> {
|
||||
// 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<void> {
|
||||
// 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<void> {
|
||||
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<void> {
|
||||
let expectedNotebookStreamOutputContent: nb.INotebookContents = {
|
||||
cells: [{
|
||||
cell_type: CellTypes.Code,
|
||||
source: [],
|
||||
metadata: { language: 'python' },
|
||||
execution_count: 1,
|
||||
outputs: [
|
||||
<nb.IStreamResult>{
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user