Fix Books Unit Tests (#6702)

* wait for all toc.yml to be found

* add event to signal all toc.yml files read

* add workspae folder parameter back

* remove toc filter
This commit is contained in:
Lucy Zhang
2019-08-12 13:47:29 -07:00
committed by GitHub
parent 68d62f861b
commit e10cad21fe
2 changed files with 27 additions and 17 deletions

View File

@@ -24,12 +24,17 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
private _extensionContext: vscode.ExtensionContext; private _extensionContext: vscode.ExtensionContext;
private _throttleTimer: any; private _throttleTimer: any;
private _resource: string; private _resource: string;
private _onReadAllTOCFiles: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
constructor(workspaceFolders: vscode.WorkspaceFolder[], extensionContext: vscode.ExtensionContext) { constructor(workspaceFolders: vscode.WorkspaceFolder[], extensionContext: vscode.ExtensionContext) {
this.getTableOfContentFiles(workspaceFolders).then(() => undefined, (err) => { console.log(err); }); this.getTableOfContentFiles(workspaceFolders).then(() => undefined, (err) => { console.log(err); });
this._extensionContext = extensionContext; this._extensionContext = extensionContext;
} }
public get onReadAllTOCFiles(): vscode.Event<void> {
return this._onReadAllTOCFiles.event;
}
async getTableOfContentFiles(workspaceFolders: vscode.WorkspaceFolder[]): Promise<void> { async getTableOfContentFiles(workspaceFolders: vscode.WorkspaceFolder[]): Promise<void> {
let notebookConfig = vscode.workspace.getConfiguration(notebookConfigKey); let notebookConfig = vscode.workspace.getConfiguration(notebookConfigKey);
let maxDepth = notebookConfig[maxBookSearchDepth]; let maxDepth = notebookConfig[maxBookSearchDepth];
@@ -46,6 +51,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
} }
let bookOpened: boolean = this._tableOfContentPaths.length > 0; let bookOpened: boolean = this._tableOfContentPaths.length > 0;
vscode.commands.executeCommand('setContext', 'bookOpened', bookOpened); vscode.commands.executeCommand('setContext', 'bookOpened', bookOpened);
this._onReadAllTOCFiles.fire();
} }
async openNotebook(resource: string): Promise<void> { async openNotebook(resource: string): Promise<void> {

View File

@@ -73,14 +73,17 @@ describe('BookTreeViewProvider.getChildren', function (): void {
}); });
it('should return all book nodes when element is undefined', async function (): Promise<void> { it('should return all book nodes when element is undefined', async function (): Promise<void> {
bookTreeViewProvider.onReadAllTOCFiles(async () => {
const children = await bookTreeViewProvider.getChildren(); const children = await bookTreeViewProvider.getChildren();
should(children).be.Array(); should(children).be.Array();
should(children.length).equal(1); should(children.length).equal(1);
book = children[0]; book = children[0];
should(book.title).equal(expectedBook.title); should(book.title).equal(expectedBook.title);
}); });
});
it('should return all page nodes when element is a book', async function (): Promise<void> { it('should return all page nodes when element is a book', async function (): Promise<void> {
bookTreeViewProvider.onReadAllTOCFiles(async () => {
const children = await bookTreeViewProvider.getChildren(book); const children = await bookTreeViewProvider.getChildren(book);
should(children).be.Array(); should(children).be.Array();
should(children.length).equal(3); should(children.length).equal(3);
@@ -94,6 +97,7 @@ describe('BookTreeViewProvider.getChildren', function (): void {
should(externalLink.title).equal(expectedExternalLink.title); should(externalLink.title).equal(expectedExternalLink.title);
should(externalLink.uri).equal(expectedExternalLink.url); should(externalLink.uri).equal(expectedExternalLink.url);
}); });
});
this.afterAll(async function () { this.afterAll(async function () {
if (fs.existsSync(rootFolderPath)) { if (fs.existsSync(rootFolderPath)) {