mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Added unit test for books getChildren() method (#6602)
* started unit tests for books * added first unit test for getchildren() * fixed dependencies and use tmpdir * latest from master
This commit is contained in:
@@ -347,6 +347,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jupyterlab/services": "^3.2.1",
|
"@jupyterlab/services": "^3.2.1",
|
||||||
"@types/js-yaml": "^3.12.1",
|
"@types/js-yaml": "^3.12.1",
|
||||||
|
"@types/rimraf": "^2.0.2",
|
||||||
"decompress": "^4.2.0",
|
"decompress": "^4.2.0",
|
||||||
"error-ex": "^1.3.1",
|
"error-ex": "^1.3.1",
|
||||||
"figures": "^2.0.0",
|
"figures": "^2.0.0",
|
||||||
@@ -374,4 +375,4 @@
|
|||||||
"vscode": "1.1.5"
|
"vscode": "1.1.5"
|
||||||
},
|
},
|
||||||
"enableProposedApi": true
|
"enableProposedApi": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,14 @@ export class BookTreeItem extends vscode.TreeItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get title(): string {
|
||||||
|
return this.book.title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get uri(): string {
|
||||||
|
return this._uri;
|
||||||
|
}
|
||||||
|
|
||||||
public get root(): string {
|
public get root(): string {
|
||||||
return this.book.root;
|
return this.book.root;
|
||||||
}
|
}
|
||||||
@@ -128,4 +136,4 @@ export class BookTreeItem extends vscode.TreeItem {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
|||||||
return array.reduce((acc, val) => Array.isArray(val.sections) ? acc.concat(val).concat(this.flattenArray(val.sections)) : acc.concat(val), []);
|
return array.reduce((acc, val) => Array.isArray(val.sections) ? acc.concat(val).concat(this.flattenArray(val.sections)) : acc.concat(val), []);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getBooks(): BookTreeItem[] {
|
public getBooks(): BookTreeItem[] {
|
||||||
let books: BookTreeItem[] = [];
|
let books: BookTreeItem[] = [];
|
||||||
for (let i in this._tableOfContentsPath) {
|
for (let i in this._tableOfContentsPath) {
|
||||||
let root = path.dirname(path.dirname(this._tableOfContentsPath[i]));
|
let root = path.dirname(path.dirname(this._tableOfContentsPath[i]));
|
||||||
|
|||||||
86
extensions/notebook/src/test/book/book.test.ts
Normal file
86
extensions/notebook/src/test/book/book.test.ts
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import * as vscode from 'vscode';
|
||||||
|
import * as should from 'should';
|
||||||
|
import * as TypeMoq from 'typemoq';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import * as rimraf from 'rimraf';
|
||||||
|
import * as os from 'os';
|
||||||
|
import { BookTreeViewProvider } from '../../book/bookTreeView';
|
||||||
|
import { BookTreeItem } from '../../book/bookTreeItem';
|
||||||
|
|
||||||
|
describe('BookTreeViewProvider.getChildren', function (): void {
|
||||||
|
const rootFolderPath = path.join(os.tmpdir(), 'testBook');
|
||||||
|
const dataFolderPath = path.join(rootFolderPath, '_data');
|
||||||
|
const contentFolderPath = path.join(rootFolderPath, 'content');
|
||||||
|
const configFile = path.join(rootFolderPath, '_config.yml');
|
||||||
|
const tableOfContentsFile = path.join(dataFolderPath, 'toc.yml');
|
||||||
|
const notebookFile = path.join(contentFolderPath, 'notebook.ipynb');
|
||||||
|
const markdownFile = path.join(contentFolderPath, 'markdown.md');
|
||||||
|
const expectedNotebook = {
|
||||||
|
title: 'Notebook',
|
||||||
|
url: '/notebook'
|
||||||
|
};
|
||||||
|
const expectedMarkdown = {
|
||||||
|
title: 'Markdown',
|
||||||
|
url: '/markdown'
|
||||||
|
};
|
||||||
|
const expectedExternalLink = {
|
||||||
|
title: 'GitHub',
|
||||||
|
url: 'https://github.com/',
|
||||||
|
external: true
|
||||||
|
};
|
||||||
|
const expectedBook = {
|
||||||
|
sections: [expectedNotebook, expectedMarkdown, expectedExternalLink],
|
||||||
|
title: 'Test Book'
|
||||||
|
};
|
||||||
|
|
||||||
|
let mockExtensionContext: TypeMoq.IMock<vscode.ExtensionContext>;
|
||||||
|
let bookTreeViewProvider: BookTreeViewProvider;
|
||||||
|
let book: BookTreeItem;
|
||||||
|
|
||||||
|
this.beforeAll(async () => {
|
||||||
|
fs.mkdirSync(rootFolderPath);
|
||||||
|
fs.mkdirSync(dataFolderPath);
|
||||||
|
fs.mkdirSync(contentFolderPath);
|
||||||
|
fs.writeFileSync(configFile, 'title: Test Book');
|
||||||
|
fs.writeFileSync(tableOfContentsFile, '- title: Notebook\n url: /notebook\n- title: Markdown\n url: /markdown\n- title: GitHub\n url: https://github.com/\n external: true');
|
||||||
|
fs.writeFileSync(notebookFile, '');
|
||||||
|
fs.writeFileSync(markdownFile, '');
|
||||||
|
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||||
|
bookTreeViewProvider = new BookTreeViewProvider(rootFolderPath, mockExtensionContext.object);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return all book nodes when element is undefined', async function (): Promise<void> {
|
||||||
|
const children = await bookTreeViewProvider.getChildren();
|
||||||
|
should(children).be.Array();
|
||||||
|
should(children.length).equal(1);
|
||||||
|
book = children[0];
|
||||||
|
should(book.title).equal(expectedBook.title);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return all page nodes when element is a book', async function (): Promise<void> {
|
||||||
|
const children = await bookTreeViewProvider.getChildren(book);
|
||||||
|
should(children).be.Array();
|
||||||
|
should(children.length).equal(3);
|
||||||
|
const notebook = children[0];
|
||||||
|
const markdown = children[1];
|
||||||
|
const externalLink = children[2];
|
||||||
|
should(notebook.title).equal(expectedNotebook.title);
|
||||||
|
should(notebook.uri).equal(expectedNotebook.url);
|
||||||
|
should(markdown.title).equal(expectedMarkdown.title);
|
||||||
|
should(markdown.uri).equal(expectedMarkdown.url);
|
||||||
|
should(externalLink.title).equal(expectedExternalLink.title);
|
||||||
|
should(externalLink.uri).equal(expectedExternalLink.url);
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async function () {
|
||||||
|
if (fs.existsSync(rootFolderPath)) {
|
||||||
|
rimraf.sync(rootFolderPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@types/node" "*"
|
"@types/node" "*"
|
||||||
|
|
||||||
"@types/glob@^7.1.1":
|
"@types/glob@*", "@types/glob@^7.1.1":
|
||||||
version "7.1.1"
|
version "7.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
|
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
|
||||||
integrity sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==
|
integrity sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==
|
||||||
@@ -155,6 +155,14 @@
|
|||||||
"@types/node" "*"
|
"@types/node" "*"
|
||||||
"@types/tough-cookie" "*"
|
"@types/tough-cookie" "*"
|
||||||
|
|
||||||
|
"@types/rimraf@^2.0.2":
|
||||||
|
version "2.0.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-2.0.2.tgz#7f0fc3cf0ff0ad2a99bb723ae1764f30acaf8b6e"
|
||||||
|
integrity sha512-Hm/bnWq0TCy7jmjeN5bKYij9vw5GrDFWME4IuxV08278NtU/VdGbzsBohcCUJ7+QMqmUq5hpRKB39HeQWJjztQ==
|
||||||
|
dependencies:
|
||||||
|
"@types/glob" "*"
|
||||||
|
"@types/node" "*"
|
||||||
|
|
||||||
"@types/temp-write@^3.3.0":
|
"@types/temp-write@^3.3.0":
|
||||||
version "3.3.0"
|
version "3.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/@types/temp-write/-/temp-write-3.3.0.tgz#40fe3d1fae6e98a2e40a13abe83e7a1996ea51ee"
|
resolved "https://registry.yarnpkg.com/@types/temp-write/-/temp-write-3.3.0.tgz#40fe3d1fae6e98a2e40a13abe83e7a1996ea51ee"
|
||||||
|
|||||||
Reference in New Issue
Block a user