Add and fix notebook extension unit tests (#10156)

This commit is contained in:
Charles Gagnon
2020-04-24 22:05:36 -07:00
committed by GitHub
parent c26bd3f8f7
commit 586c28bf79
7 changed files with 220 additions and 55 deletions

View File

@@ -3,7 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import * as should from 'should';
import * as path from 'path';
@@ -199,11 +198,11 @@ describe('BookTreeViewProviderTests', function () {
it('should set notebooks trusted to true on trustBook', async () => {
let notebook1Path = path.join(rootFolderPath, 'Book', 'content', 'notebook1.ipynb');
let bookTrustManager: BookTrustManager = new BookTrustManager(bookTreeViewProvider.books, appContext.apiWrapper);
let isTrusted = bookTrustManager.isNotebookTrustedByDefault(notebook1Path);
let isTrusted = bookTrustManager.isNotebookTrustedByDefault(vscode.Uri.file(notebook1Path).fsPath);
should(isTrusted).equal(false, 'Notebook should not be trusted by default');
bookTreeViewProvider.trustBook(bookTreeViewProvider.currentBook.bookItems[0]);
isTrusted = bookTrustManager.isNotebookTrustedByDefault(notebook1Path);
isTrusted = bookTrustManager.isNotebookTrustedByDefault(vscode.Uri.file(notebook1Path).fsPath);
should(isTrusted).equal(true, 'Failed to set trust on trustBook');
});
@@ -212,11 +211,10 @@ describe('BookTreeViewProviderTests', function () {
let notebook1Path = path.join(rootFolderPath, 'Book', 'content', 'notebook1.ipynb');
let notebook2Path = path.join(rootFolderPath, 'Book', 'content', 'notebook2.ipynb');
let notebook3Path = path.join(rootFolderPath, 'Book', 'content', 'notebook3.ipynb');
let result: azdata.nb.NavigationResult;
await bookTreeViewProvider.currentBook.getNavigation(vscode.Uri.file(notebook2Path)).then(navigationResult => { result = navigationResult;});
const result = await bookTreeViewProvider.currentBook.getNavigation(vscode.Uri.file(notebook2Path));
should(result.hasNavigation).be.true('getNavigation failed to get previous and next urls');
should(result.next.fsPath).equal(notebook3Path, 'getNavigation failed to get the next url');
should(result.previous.fsPath).equal(notebook1Path, 'getNavigation failed to get the previous url');
should(result.next.fsPath).equal(vscode.Uri.file(notebook3Path).fsPath, 'getNavigation failed to get the next url');
should(result.previous.fsPath).equal(vscode.Uri.file(notebook1Path).fsPath, 'getNavigation failed to get the previous url');
});
@@ -264,7 +262,7 @@ describe('BookTreeViewProviderTests', function () {
it('should ignore toc.yml files not in _data folder', async () => {
await bookTreeViewProvider.currentBook.loadTableOfContentFiles(rootFolderPath);
let path = bookTreeViewProvider.currentBook.tableOfContentsPath;
should(path.toLocaleLowerCase()).equal(tableOfContentsFile.replace(/\\/g, '/').toLocaleLowerCase());
should(vscode.Uri.file(path).fsPath).equal(vscode.Uri.file(tableOfContentsFile).fsPath);
});
this.afterAll(async function (): Promise<void> {

View File

@@ -130,8 +130,8 @@ describe('BookTrustManagerTests', function () {
let isNotebook1Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri1);
let isNotebook2Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri2);
should(isNotebook1Trusted).be.true("Notebook 1 should be trusted");
should(isNotebook2Trusted).be.true("Notebook 2 should be trusted");
should(isNotebook1Trusted).be.true('Notebook 1 should be trusted');
should(isNotebook2Trusted).be.true('Notebook 2 should be trusted');
});
@@ -139,42 +139,42 @@ describe('BookTrustManagerTests', function () {
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook.ipynb');
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrusted).be.false("Notebook should be trusted");
should(isNotebookTrusted).be.false('Notebook should be trusted');
});
it('should trust notebook after book has been trusted within a workspace', async () => {
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook.ipynb');
let isNotebookTrustedBeforeChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrustedBeforeChange).be.false("Notebook should NOT be trusted");
should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted');
// add another book subfolder
bookTrustManager.setBookAsTrusted('/SubFolder2/');
let isNotebookTrustedAfterChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrustedAfterChange).be.true("Notebook should be trusted");
should(isNotebookTrustedAfterChange).be.true('Notebook should be trusted');
});
it('should NOT trust a notebook when untrusting a book within a workspace', async () => {
let notebookUri = path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook.ipynb');
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrusted).be.true("Notebook should be trusted");
should(isNotebookTrusted).be.true('Notebook should be trusted');
// remove trusted subfolders
trustedSubFolders = [];
let isNotebookTrustedAfterChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrustedAfterChange).be.false("Notebook should not be trusted after book removal");
should(isNotebookTrustedAfterChange).be.false('Notebook should not be trusted after book removal');
});
it('should NOT trust an unknown book within a workspace', async () => {
let notebookUri = path.join(path.sep, 'randomfolder', 'randomsubfolder', 'content', 'randomnotebook.ipynb');
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrusted).be.false("Random notebooks should not be trusted");
should(isNotebookTrusted).be.false('Random notebooks should not be trusted');
});
it('should NOT trust notebook inside trusted subfolder when absent in table of contents ', async () => {
@@ -183,7 +183,7 @@ describe('BookTrustManagerTests', function () {
let notebookUri = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notInToc.ipynb');
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrusted).be.false("Notebook should NOT be trusted");
should(isNotebookTrusted).be.false('Notebook should NOT be trusted');
});
});
@@ -274,8 +274,8 @@ describe('BookTrustManagerTests', function () {
let isNotebook1Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri1);
let isNotebook2Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri2);
should(isNotebook1Trusted).be.true("Notebook 1 should be trusted");
should(isNotebook2Trusted).be.true("Notebook 2 should be trusted");
should(isNotebook1Trusted).be.true('Notebook 1 should be trusted');
should(isNotebook2Trusted).be.true('Notebook 2 should be trusted');
});
@@ -283,20 +283,20 @@ describe('BookTrustManagerTests', function () {
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook.ipynb');
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrusted).be.false("Notebook should be trusted");
should(isNotebookTrusted).be.false('Notebook should be trusted');
});
it('should trust notebook after book has been added to a folder', async () => {
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample','notebook.ipynb');
let isNotebookTrustedBeforeChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrustedBeforeChange).be.false("Notebook should NOT be trusted");
should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted');
bookTrustManager.setBookAsTrusted('/temp/SubFolder2/');
let isNotebookTrustedAfterChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrustedAfterChange).be.true("Notebook should be trusted");
should(isNotebookTrustedAfterChange).be.true('Notebook should be trusted');
});
it('should NOT trust a notebook when untrusting a book in folder', async () => {
@@ -304,20 +304,20 @@ describe('BookTrustManagerTests', function () {
let notebookUri = path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook.ipynb');
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrusted).be.true("Notebook should be trusted");
should(isNotebookTrusted).be.true('Notebook should be trusted');
trustedFolders = [];
let isNotebookTrustedAfterChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrustedAfterChange).be.false("Notebook should not be trusted after book removal");
should(isNotebookTrustedAfterChange).be.false('Notebook should not be trusted after book removal');
});
it('should NOT trust an unknown book', async () => {
let notebookUri = path.join(path.sep, 'randomfolder', 'randomsubfolder', 'content', 'randomnotebook.ipynb');
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrusted).be.false("Random notebooks should not be trusted");
should(isNotebookTrusted).be.false('Random notebooks should not be trusted');
});
it('should NOT trust notebook inside trusted subfolder when absent in table of contents ', async () => {
@@ -326,7 +326,7 @@ describe('BookTrustManagerTests', function () {
let notebookUri = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notInToc.ipynb');
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
should(isNotebookTrusted).be.false("Notebook should NOT be trusted");
should(isNotebookTrusted).be.false('Notebook should NOT be trusted');
});
});