From e10cad21fe3077ea88901a337a7f6507ca0a934f Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Mon, 12 Aug 2019 13:47:29 -0700 Subject: [PATCH] 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 --- extensions/notebook/src/book/bookTreeView.ts | 6 +++ .../notebook/src/test/book/book.test.ts | 38 ++++++++++--------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/extensions/notebook/src/book/bookTreeView.ts b/extensions/notebook/src/book/bookTreeView.ts index 8f1677a865..a699869d08 100644 --- a/extensions/notebook/src/book/bookTreeView.ts +++ b/extensions/notebook/src/book/bookTreeView.ts @@ -24,12 +24,17 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider = new vscode.EventEmitter(); constructor(workspaceFolders: vscode.WorkspaceFolder[], extensionContext: vscode.ExtensionContext) { this.getTableOfContentFiles(workspaceFolders).then(() => undefined, (err) => { console.log(err); }); this._extensionContext = extensionContext; } + public get onReadAllTOCFiles(): vscode.Event { + return this._onReadAllTOCFiles.event; + } + async getTableOfContentFiles(workspaceFolders: vscode.WorkspaceFolder[]): Promise { let notebookConfig = vscode.workspace.getConfiguration(notebookConfigKey); let maxDepth = notebookConfig[maxBookSearchDepth]; @@ -46,6 +51,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider 0; vscode.commands.executeCommand('setContext', 'bookOpened', bookOpened); + this._onReadAllTOCFiles.fire(); } async openNotebook(resource: string): Promise { diff --git a/extensions/notebook/src/test/book/book.test.ts b/extensions/notebook/src/test/book/book.test.ts index 213676d7c0..d4c0565a75 100644 --- a/extensions/notebook/src/test/book/book.test.ts +++ b/extensions/notebook/src/test/book/book.test.ts @@ -73,26 +73,30 @@ describe('BookTreeViewProvider.getChildren', function (): void { }); it('should return all book nodes when element is undefined', async function (): Promise { - const children = await bookTreeViewProvider.getChildren(); - should(children).be.Array(); - should(children.length).equal(1); - book = children[0]; - should(book.title).equal(expectedBook.title); + bookTreeViewProvider.onReadAllTOCFiles(async () => { + 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 { - 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); + bookTreeViewProvider.onReadAllTOCFiles(async () => { + 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); + }); }); this.afterAll(async function () {