From 3c4ffd2a9c937d9988ada263e6c5369fbfd64b92 Mon Sep 17 00:00:00 2001 From: Barbara Valdez <34872381+barbaravaldez@users.noreply.github.com> Date: Fri, 5 Feb 2021 10:45:59 -0800 Subject: [PATCH] Fix book tests on Windows. (#14173) * fix tests * fix reveal active item test * show error message * revert trusted book test back to original --- extensions/notebook/src/book/bookModel.ts | 3 ++- extensions/notebook/src/test/book/book.test.ts | 9 +++++---- extensions/notebook/src/test/book/bookTocManager.test.ts | 8 ++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/extensions/notebook/src/book/bookModel.ts b/extensions/notebook/src/book/bookModel.ts index c148645f59..bb7bfc0a85 100644 --- a/extensions/notebook/src/book/bookModel.ts +++ b/extensions/notebook/src/book/bookModel.ts @@ -253,7 +253,8 @@ export class BookModel { ); notebooks.push(markdown); } else { - this._errorMessage = loc.missingFileError(sections[i].title, root); + this._errorMessage = loc.missingFileError(sections[i].title, book.title); + vscode.window.showErrorMessage(this._errorMessage); } } } diff --git a/extensions/notebook/src/test/book/book.test.ts b/extensions/notebook/src/test/book/book.test.ts index 53bae78071..bffb9aea2a 100644 --- a/extensions/notebook/src/test/book/book.test.ts +++ b/extensions/notebook/src/test/book/book.test.ts @@ -242,7 +242,7 @@ describe('BooksTreeViewTests', function () { }); it('revealActiveDocumentInViewlet should return correct bookItem for highlight', async () => { - let notebook1Path = path.join(rootFolderPath, 'Book', 'content', 'notebook1.ipynb'); + let notebook1Path = vscode.Uri.file(path.join(rootFolderPath, 'Book', 'content', 'notebook1.ipynb')).fsPath; let currentSelection = await bookTreeViewProvider.findAndExpandParentNode(notebook1Path); equalBookItems(currentSelection, expectedNotebook1); }); @@ -653,7 +653,7 @@ describe('BooksTreeViewTests', function () { it('should show error if notebook or markdown file is missing', async function (): Promise { let books: BookTreeItem[] = bookTreeViewProvider.currentBook.bookItems; let children = await bookTreeViewProvider.currentBook.getSections({ sections: [] }, books[0].sections, rootFolderPath, books[0].book); - should(bookTreeViewProvider.currentBook.errorMessage).equal('Missing file : Notebook1 from '.concat(bookTreeViewProvider.currentBook.bookPath)); + should(bookTreeViewProvider.currentBook.errorMessage).equal('Missing file : Notebook1 from '.concat(bookTreeViewProvider.currentBook.bookItems[0].title)); // rest of book should be detected correctly even with a missing file equalBookItems(children[0], expectedNotebook2); }); @@ -798,11 +798,12 @@ describe('BooksTreeViewTests', function () { }); it('openNotebookFolder without folderPath should prompt for folder path and invoke loadNotebooksInFolder', async () => { - sinon.stub(vscode.window, 'showOpenDialog').returns(Promise.resolve([vscode.Uri.file(rootFolderPath)])); + const uri = vscode.Uri.file(rootFolderPath); + sinon.stub(vscode.window, 'showOpenDialog').returns(Promise.resolve([uri])); let loadNotebooksSpy = sinon.spy(bookTreeViewProvider, 'loadNotebooksInFolder'); await bookTreeViewProvider.openNotebookFolder(); - should(loadNotebooksSpy.calledWith(rootFolderPath)).be.true('openNotebookFolder should have called loadNotebooksInFolder passing the folderPath'); + should(loadNotebooksSpy.calledWith(uri.fsPath)).be.true('openNotebookFolder should have called loadNotebooksInFolder passing the folderPath'); }); it('openNotebookFolder with folderPath shouldn\'t prompt for folder path but invoke loadNotebooksInFolder with the provided folderPath', async () => { diff --git a/extensions/notebook/src/test/book/bookTocManager.test.ts b/extensions/notebook/src/test/book/bookTocManager.test.ts index 0e32e1150c..4b8b14eb12 100644 --- a/extensions/notebook/src/test/book/bookTocManager.test.ts +++ b/extensions/notebook/src/test/book/bookTocManager.test.ts @@ -16,7 +16,6 @@ import * as rimraf from 'rimraf'; import { promisify } from 'util'; import { BookModel } from '../../book/bookModel'; import { MockExtensionContext } from '../common/stubs'; -import { BookVersion } from '../../book/bookVersionHandler'; import { BookTreeViewProvider } from '../../book/bookTreeView'; import { NavigationProviders } from '../../common/constants'; import * as loc from '../../common/localizedConstants'; @@ -517,11 +516,8 @@ describe('BookTocManagerTests', function () { await bookTocManager.updateBook(notebook, targetBook); await bookTocManager.updateBook(duplicatedNotebook, targetBook); const listFiles = await fs.promises.readdir(run.targetBook.bookContentFolderPath); - if (run.version === BookVersion.v1) { - should(JSON.stringify(listFiles)).be.equal(JSON.stringify(['notebook5 - 2.ipynb', 'notebook5.ipynb', 'sectionC']), 'Should modify the name of the file'); - } else { - should(JSON.stringify(listFiles)).be.equal(JSON.stringify(['_config.yml', '_toc.yml', 'notebook5 - 2.ipynb', 'notebook5.ipynb', 'sectionC']), 'Should modify the name of the file'); - } + should(JSON.stringify(listFiles).includes('notebook5 - 2.ipynb')).be.true('Should rename the notebook to notebook5 - 2.ipynb'); + should(JSON.stringify(listFiles).includes('notebook5.ipynb')).be.true('Should keep notebook5.ipynb'); }); it('Recovery method is called after error', async () => {