mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add test coverage for dacpac wizard import flow (#11483)
* Adding importConfig onPageEnter() test * Removing redundancy from dacpac wizard pages * promisifying file selection so it can be awaited in the test * removing debug prints * PR feedback
This commit is contained in:
@@ -5,10 +5,17 @@
|
||||
|
||||
import 'mocha';
|
||||
import * as should from 'should';
|
||||
import * as sinon from 'sinon';
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
||||
import { DataTierApplicationWizard, PageName } from '../wizard/dataTierApplicationWizard';
|
||||
import { DacFxDataModel } from '../wizard/api/models';
|
||||
import { TestContext, createContext } from './testContext';
|
||||
import { TestDeployConfigPage, TestExtractConfigPage } from './testDacFxConfigPages';
|
||||
import { TestDeployConfigPage, TestExtractConfigPage, TestImportConfigPage } from './testDacFxConfigPages';
|
||||
import { mockConnectionProfile } from './testUtils';
|
||||
|
||||
let wizard: DataTierApplicationWizard;
|
||||
let testContext: TestContext;
|
||||
@@ -20,6 +27,10 @@ describe('Dacfx Wizard Pages', function (): void {
|
||||
wizard.model.server = undefined;
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should open and edit deploy config page correctly', async () => {
|
||||
testContext = createContext();
|
||||
wizard.setPages();
|
||||
@@ -74,4 +85,28 @@ describe('Dacfx Wizard Pages', function (): void {
|
||||
await extractConfigPage.onPageLeave();
|
||||
should.equal(extractConfigPage.Model.filePath, 'DummyPath.dacpac');
|
||||
});
|
||||
|
||||
it('Should open and edit import config page correctly', async () => {
|
||||
const dacpacPath = vscode.Uri.file(path.join(os.tmpdir(), 'myDatabase.dacpac')).fsPath;
|
||||
|
||||
testContext = createContext();
|
||||
wizard.setPages();
|
||||
|
||||
sinon.stub(azdata.connection, 'getConnections').resolves([mockConnectionProfile]);
|
||||
sinon.stub(azdata.connection, 'listDatabases').resolves(['fakeDatabaseName']);
|
||||
sinon.stub(vscode.window, 'showOpenDialog').resolves([vscode.Uri.file(dacpacPath)]);
|
||||
|
||||
let importConfigPage = new TestImportConfigPage(wizard, wizard.pages.get(PageName.importConfig).wizardPage, wizard.model, testContext.viewContext.view);
|
||||
await importConfigPage.start();
|
||||
|
||||
let result = await importConfigPage.onPageEnter();
|
||||
should(result).equal(true, 'onPageEnter() should successfullly load connection profiles');
|
||||
|
||||
testContext.viewContext.fileButtonOnClick.fire(undefined);
|
||||
await importConfigPage.selectionPromise;
|
||||
should(importConfigPage.Model.filePath).equal(dacpacPath);
|
||||
should(importConfigPage.Model.database).equal('myDatabase');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ export interface ViewTestContext {
|
||||
extractOnClick: vscode.EventEmitter<any>,
|
||||
exportOnClick: vscode.EventEmitter<any>,
|
||||
importOnClick: vscode.EventEmitter<any>,
|
||||
fileButtonOnClick: vscode.EventEmitter<any>;
|
||||
}
|
||||
|
||||
export function createViewContext(): ViewTestContext {
|
||||
@@ -63,6 +64,7 @@ export function createViewContext(): ViewTestContext {
|
||||
let extractOnClick: vscode.EventEmitter<any> = new vscode.EventEmitter<any>();
|
||||
let exportOnClick: vscode.EventEmitter<any> = new vscode.EventEmitter<any>();
|
||||
let importOnClick: vscode.EventEmitter<any> = new vscode.EventEmitter<any>();
|
||||
let fileButtonOnClick: vscode.EventEmitter<any> = new vscode.EventEmitter<any>();
|
||||
|
||||
let componentBase: azdata.Component = {
|
||||
id: '',
|
||||
@@ -110,7 +112,13 @@ export function createViewContext(): ViewTestContext {
|
||||
|
||||
let buttonBuilder: azdata.ComponentBuilder<azdata.ButtonComponent> = {
|
||||
component: () => button,
|
||||
withProperties: () => buttonBuilder,
|
||||
withProperties: (properties) => {
|
||||
if ((properties as any).label === '•••') {
|
||||
button.label = '•••';
|
||||
button.onDidClick = fileButtonOnClick.event;
|
||||
}
|
||||
return buttonBuilder;
|
||||
},
|
||||
withValidation: () => buttonBuilder
|
||||
};
|
||||
|
||||
@@ -295,5 +303,6 @@ export function createViewContext(): ViewTestContext {
|
||||
extractOnClick: extractOnClick,
|
||||
exportOnClick: exportOnClick,
|
||||
importOnClick: importOnClick,
|
||||
fileButtonOnClick: fileButtonOnClick
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import { DeployConfigPage } from '../wizard/pages/deployConfigPage';
|
||||
import { ExtractConfigPage } from '../wizard/pages/extractConfigPage';
|
||||
import { DataTierApplicationWizard } from '../wizard/dataTierApplicationWizard';
|
||||
import { SelectOperationPage } from '../wizard/pages/selectOperationpage';
|
||||
import { ImportConfigPage } from '../wizard/pages/importConfigPage';
|
||||
|
||||
export class TestDeployConfigPage extends DeployConfigPage {
|
||||
|
||||
constructor(instance: DataTierApplicationWizard, wizardPage: azdata.window.WizardPage, model: DacFxDataModel, view: azdata.ModelView) {
|
||||
super(instance, wizardPage, model, view);
|
||||
}
|
||||
@@ -30,7 +30,6 @@ export class TestDeployConfigPage extends DeployConfigPage {
|
||||
}
|
||||
|
||||
export class TestExtractConfigPage extends ExtractConfigPage {
|
||||
|
||||
constructor(instance: DataTierApplicationWizard, wizardPage: azdata.window.WizardPage, model: DacFxDataModel, view: azdata.ModelView) {
|
||||
super(instance, wizardPage, model, view);
|
||||
}
|
||||
@@ -41,7 +40,6 @@ export class TestExtractConfigPage extends ExtractConfigPage {
|
||||
}
|
||||
|
||||
export class TestSelectOperationPage extends SelectOperationPage {
|
||||
|
||||
constructor(instance: DataTierApplicationWizard, wizardPage: azdata.window.WizardPage, model: DacFxDataModel, view: azdata.ModelView) {
|
||||
super(instance, wizardPage, model, view);
|
||||
}
|
||||
@@ -50,3 +48,13 @@ export class TestSelectOperationPage extends SelectOperationPage {
|
||||
return this.instance;
|
||||
}
|
||||
}
|
||||
|
||||
export class TestImportConfigPage extends ImportConfigPage {
|
||||
constructor(instance: DataTierApplicationWizard, wizardPage: azdata.window.WizardPage, model: DacFxDataModel, view: azdata.ModelView) {
|
||||
super(instance, wizardPage, model, view);
|
||||
}
|
||||
|
||||
get Model(): DacFxDataModel {
|
||||
return this.model;
|
||||
}
|
||||
}
|
||||
|
||||
22
extensions/dacpac/src/test/testUtils.ts
Normal file
22
extensions/dacpac/src/test/testUtils.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
export const mockConnectionProfile: azdata.connection.ConnectionProfile = {
|
||||
providerId: 'MSSQL',
|
||||
connectionId: 'My Connection ID',
|
||||
connectionName: 'My Connection',
|
||||
serverName: 'My Server',
|
||||
databaseName: 'My Database',
|
||||
userName: 'My User',
|
||||
password: 'My Pwd',
|
||||
authenticationType: 'SqlLogin',
|
||||
savePassword: false,
|
||||
groupFullName: 'My groupName',
|
||||
groupId: 'My GroupId',
|
||||
saveProfile: true,
|
||||
options: {}
|
||||
};
|
||||
Reference in New Issue
Block a user