Files
azuredatastudio/extensions/resource-deployment/src/test/notebookService.test.ts
Alan Ren a0e31fc723 wizard for deploying bdc (#7183)
* wip

* wip2

* wip eod 820

* wip 822

* text component improvements and misc changes

* aria-label

* targetClusterPage wip

* target cluster page

* target cluster page

* wip 827

* wip deployment profile page

* profile page

* service settings page

* wip 0903

* 0909 wip

* 0910

* 0911

* sql instance and working directory

* notebooks

* docker version on windows

* EULA env var

* 917 updates

* address comments

* use async file access

* fix the summary page display issue for ad auth

* add save json file buttons

* use promise for private methds

* review feedbacks

* refactor

* pass json to notebooks

* fix no tool scenario

* bypass tool check if installed

* update hint text

* update notebooks

* workaround azdata first time use

* comments

* accept eula and some text update

* fix the error in package.json

* promise instead of thenable

* comments

* fix typo
2019-09-25 10:04:13 -07:00

98 lines
5.2 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as TypeMoq from 'typemoq';
import 'mocha';
import { NotebookService } from '../services/notebookService';
import assert = require('assert');
import { NotebookInfo } from '../interfaces';
import { IPlatformService } from '../services/platformService';
suite('Notebook Service Tests', function (): void {
test('getNotebook with string parameter', () => {
const mockPlatformService = TypeMoq.Mock.ofType<IPlatformService>();
const notebookService = new NotebookService(mockPlatformService.object, '');
const notebookInput = 'test-notebook.ipynb';
mockPlatformService.setup((service) => service.platform()).returns(() => { return 'win32'; });
let returnValue = notebookService.getNotebook(notebookInput);
assert.equal(returnValue, notebookInput, 'returned notebook name does not match expected value');
mockPlatformService.verify((service) => service.platform(), TypeMoq.Times.never());
mockPlatformService.reset();
mockPlatformService.setup((service) => service.platform()).returns(() => { return 'win32'; });
returnValue = notebookService.getNotebook('');
assert.equal(returnValue, '', 'returned notebook name does not match expected value is not an empty string');
mockPlatformService.verify((service) => service.platform(), TypeMoq.Times.never());
});
test('getNotebook with NotebookInfo parameter', () => {
const mockPlatformService = TypeMoq.Mock.ofType<IPlatformService>();
const notebookService = new NotebookService(mockPlatformService.object, '');
const notebookWin32 = 'test-notebook-win32.ipynb';
const notebookDarwin = 'test-notebook-darwin.ipynb';
const notebookLinux = 'test-notebook-linux.ipynb';
const notebookInput: NotebookInfo = {
darwin: notebookDarwin,
win32: notebookWin32,
linux: notebookLinux
};
mockPlatformService.setup((service) => service.platform()).returns(() => { return 'win32'; });
let returnValue = notebookService.getNotebook(notebookInput);
assert.equal(returnValue, notebookWin32, 'returned notebook name does not match expected value for win32 platform');
mockPlatformService.verify((service) => service.platform(), TypeMoq.Times.once());
mockPlatformService.reset();
mockPlatformService.setup((service) => service.platform()).returns(() => { return 'darwin'; });
returnValue = notebookService.getNotebook(notebookInput);
assert.equal(returnValue, notebookDarwin, 'returned notebook name does not match expected value for darwin platform');
mockPlatformService.verify((service) => service.platform(), TypeMoq.Times.once());
mockPlatformService.reset();
mockPlatformService.setup((service) => service.platform()).returns(() => { return 'linux'; });
returnValue = notebookService.getNotebook(notebookInput);
assert.equal(returnValue, notebookLinux, 'returned notebook name does not match expected value for linux platform');
mockPlatformService.verify((service) => service.platform(), TypeMoq.Times.once());
});
test('findNextUntitledEditorName with no name conflict', () => {
const mockPlatformService = TypeMoq.Mock.ofType<IPlatformService>();
const notebookService = new NotebookService(mockPlatformService.object, '');
const notebookFileName = 'mynotebook.ipynb';
const sourceNotebookPath = `./notebooks/${notebookFileName}`;
const expectedTargetFile = 'mynotebook';
mockPlatformService.setup((service) => service.isNotebookNameUsed(TypeMoq.It.isAnyString()))
.returns((path) => { return false; });
const actualFileName = notebookService.findNextUntitledEditorName(sourceNotebookPath);
mockPlatformService.verify((service) => service.isNotebookNameUsed(TypeMoq.It.isAnyString()), TypeMoq.Times.once());
assert.equal(actualFileName, expectedTargetFile, 'target file name is not correct');
});
test('findNextUntitledEditorName with name conflicts', () => {
const mockPlatformService = TypeMoq.Mock.ofType<IPlatformService>();
const notebookService = new NotebookService(mockPlatformService.object, '');
const notebookFileName = 'mynotebook.ipynb';
const sourceNotebookPath = `./notebooks/${notebookFileName}`;
const expectedFileName = 'mynotebook-2';
const expected1stAttemptTargetFile = 'mynotebook';
const expected2ndAttemptTargetFile = 'mynotebook-1';
mockPlatformService.setup((service) => service.isNotebookNameUsed(TypeMoq.It.isAnyString()))
.returns((path) => {
// list all the possible values here and handle them
// if we only handle the expected value and return true for anything else, the test might run forever until times out
if (path === expected1stAttemptTargetFile || path === expected2ndAttemptTargetFile) {
return true;
}
return false;
});
const actualFileName = notebookService.findNextUntitledEditorName(sourceNotebookPath);
mockPlatformService.verify((service) => service.isNotebookNameUsed(TypeMoq.It.isAnyString()), TypeMoq.Times.exactly(3));
assert.equal(actualFileName, expectedFileName, 'target file name is not correct');
});
});