Add persistence and connect dialog to Arc view (#11014)

* Add controller persistence and info prompting

* more stuff

* clean up

* Add arc tests to scripts
This commit is contained in:
Charles Gagnon
2020-06-19 14:35:11 -07:00
committed by GitHub
parent c879d77b62
commit f278e2a7a2
17 changed files with 576 additions and 176 deletions

View File

@@ -0,0 +1,102 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as should from 'should';
import 'mocha';
import * as TypeMoq from 'typemoq';
import { AzureArcTreeDataProvider } from '../../../ui/tree/azureArcTreeDataProvider';
import { ControllerModel } from '../../../models/controllerModel';
import { ControllerTreeNode } from '../../../ui/tree/controllerTreeNode';
import { LoadingControllerNode } from '../../../ui/tree/loadingTreeNode';
describe('AzureArcTreeDataProvider tests', function (): void {
let treeDataProvider: AzureArcTreeDataProvider;
beforeEach(function (): void {
const mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
const mockGlobalState = TypeMoq.Mock.ofType<vscode.Memento>();
mockGlobalState.setup(x => x.update(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve());
mockExtensionContext.setup(x => x.globalState).returns(() => mockGlobalState.object);
//treeDataProviderMock = TypeMoq.Mock.ofType<AzureArcTreeDataProvider>();
treeDataProvider = new AzureArcTreeDataProvider(mockExtensionContext.object);
});
describe('addOrUpdateController', function (): void {
it('Multiple Controllers are added correctly', async function (): Promise<void> {
treeDataProvider['_loading'] = false;
let children = await treeDataProvider.getChildren();
should(children.length).equal(0, 'There initially shouldn\'t be any children');
const controllerModelMock = TypeMoq.Mock.ofType<ControllerModel>();
await treeDataProvider.addOrUpdateController(controllerModelMock.object, '');
should(children.length).equal(1, 'Controller node should be added correctly');
// Add a couple more
const controllerModelMock2 = TypeMoq.Mock.ofType<ControllerModel>();
const controllerModelMock3 = TypeMoq.Mock.ofType<ControllerModel>();
await treeDataProvider.addOrUpdateController(controllerModelMock2.object, '');
await treeDataProvider.addOrUpdateController(controllerModelMock3.object, '');
should(children.length).equal(3, 'Additional Controller nodes should be added correctly');
});
it('Adding a Controller more than once doesn\'t create duplicates', async function (): Promise<void> {
treeDataProvider['_loading'] = false;
let children = await treeDataProvider.getChildren();
should(children.length).equal(0, 'There initially shouldn\'t be any children');
const controllerModel = new ControllerModel(treeDataProvider, { url: '127.0.0.1', username: 'sa', rememberPassword: true });
await treeDataProvider.addOrUpdateController(controllerModel, '');
should(children.length).equal(1, 'Controller node should be added correctly');
await treeDataProvider.addOrUpdateController(controllerModel, '');
should(children.length).equal(1, 'Shouldn\'t add duplicate controller node');
});
it('Updating an existing controller works as expected', async function (): Promise<void> {
treeDataProvider['_loading'] = false;
let children = await treeDataProvider.getChildren();
should(children.length).equal(0, 'There initially shouldn\'t be any children');
const controllerModel = new ControllerModel(treeDataProvider, { url: '127.0.0.1', username: 'sa', rememberPassword: true });
await treeDataProvider.addOrUpdateController(controllerModel, '');
should(children.length).equal(1, 'Controller node should be added correctly');
should((<ControllerTreeNode>children[0]).model.info.rememberPassword).be.true('Info was not set correctly initially');
const controllerModel2 = new ControllerModel(treeDataProvider, { url: '127.0.0.1', username: 'sa', rememberPassword: false });
await treeDataProvider.addOrUpdateController(controllerModel2, '');
should(children.length).equal(1, 'Shouldn\'t add duplicate controller node');
should((<ControllerTreeNode>children[0]).model.info.rememberPassword).be.false('Info was not updated correctly');
});
});
describe('getChildren', function (): void {
it('should return a loading node before loading stored controllers is completed', async function (): Promise<void> {
treeDataProvider['_loading'] = true;
let children = await treeDataProvider.getChildren();
should(children.length).equal(1, 'While loading we should return the loading node');
should(children[0] instanceof LoadingControllerNode).be.true('Node returned was not a LoadingControllerNode');
});
it('should return no children after loading', async function (): Promise<void> {
treeDataProvider['_loading'] = false;
let children = await treeDataProvider.getChildren();
should(children.length).equal(0, 'After loading we should have 0 children');
});
});
describe('removeController', function (): void {
it('removing a controller should work as expected', async function (): Promise<void> {
treeDataProvider['_loading'] = false;
const controllerModel = new ControllerModel(treeDataProvider, { url: '127.0.0.1', username: 'sa', rememberPassword: true });
const controllerModel2 = new ControllerModel(treeDataProvider, { url: '127.0.0.2', username: 'cloudsa', rememberPassword: true });
await treeDataProvider.addOrUpdateController(controllerModel, '');
await treeDataProvider.addOrUpdateController(controllerModel2, '');
const children = <ControllerTreeNode[]>(await treeDataProvider.getChildren());
await treeDataProvider.removeController(children[0]);
should((await treeDataProvider.getChildren()).length).equal(1, 'Node should have been removed');
await treeDataProvider.removeController(children[0]);
should((await treeDataProvider.getChildren()).length).equal(1, 'Removing same node again should do nothing');
await treeDataProvider.removeController(children[1]);
should((await treeDataProvider.getChildren()).length).equal(0, 'Removing other node should work');
await treeDataProvider.removeController(children[1]);
should((await treeDataProvider.getChildren()).length).equal(0, 'Removing other node again should do nothing');
});
});
});