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,26 +73,30 @@ 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> {
const children = await bookTreeViewProvider.getChildren(); bookTreeViewProvider.onReadAllTOCFiles(async () => {
should(children).be.Array(); const children = await bookTreeViewProvider.getChildren();
should(children.length).equal(1); should(children).be.Array();
book = children[0]; should(children.length).equal(1);
should(book.title).equal(expectedBook.title); book = children[0];
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> {
const children = await bookTreeViewProvider.getChildren(book); bookTreeViewProvider.onReadAllTOCFiles(async () => {
should(children).be.Array(); const children = await bookTreeViewProvider.getChildren(book);
should(children.length).equal(3); should(children).be.Array();
const notebook = children[0]; should(children.length).equal(3);
const markdown = children[1]; const notebook = children[0];
const externalLink = children[2]; const markdown = children[1];
should(notebook.title).equal(expectedNotebook.title); const externalLink = children[2];
should(notebook.uri).equal(expectedNotebook.url); should(notebook.title).equal(expectedNotebook.title);
should(markdown.title).equal(expectedMarkdown.title); should(notebook.uri).equal(expectedNotebook.url);
should(markdown.uri).equal(expectedMarkdown.url); should(markdown.title).equal(expectedMarkdown.title);
should(externalLink.title).equal(expectedExternalLink.title); should(markdown.uri).equal(expectedMarkdown.url);
should(externalLink.uri).equal(expectedExternalLink.url); should(externalLink.title).equal(expectedExternalLink.title);
should(externalLink.uri).equal(expectedExternalLink.url);
});
}); });
this.afterAll(async function () { this.afterAll(async function () {