mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 17:22:51 -05:00
Code refactoring for extension testing (#10529)
* Setting up tests on import extension * -Added API wrappers for all the azdata and vscode APIs to make them easily mockable -Added some unit tests for the import extension -Some code logic separations * -added code report for the import extension in ci * Did some more code refractoring * -Added json report generation * updated vscodetestcoverage to latest version in import extension. * -remove duplicate codecoverageConfig.json
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import * as azdata from 'azdata';
|
||||
import { FlatFileProvider } from '../services/contracts';
|
||||
import { ImportDataModel } from './api/models';
|
||||
@@ -14,16 +12,23 @@ import { FileConfigPage } from './pages/fileConfigPage';
|
||||
import { ProsePreviewPage } from './pages/prosePreviewPage';
|
||||
import { ModifyColumnsPage } from './pages/modifyColumnsPage';
|
||||
import { SummaryPage } from './pages/summaryPage';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import * as constants from '../common/constants';
|
||||
|
||||
export class FlatFileWizard {
|
||||
private readonly provider: FlatFileProvider;
|
||||
private wizard: azdata.window.Wizard;
|
||||
public wizard: azdata.window.Wizard;
|
||||
public page1: azdata.window.WizardPage;
|
||||
public page2: azdata.window.WizardPage;
|
||||
public page3: azdata.window.WizardPage;
|
||||
public page4: azdata.window.WizardPage;
|
||||
|
||||
private importAnotherFileButton: azdata.window.Button;
|
||||
|
||||
constructor(provider: FlatFileProvider) {
|
||||
constructor(
|
||||
provider: FlatFileProvider,
|
||||
private _apiWrapper: ApiWrapper
|
||||
) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@@ -38,37 +43,24 @@ export class FlatFileWizard {
|
||||
|
||||
let pages: Map<number, ImportPage> = new Map<number, ImportPage>();
|
||||
|
||||
let currentConnection = await azdata.connection.getCurrentConnection();
|
||||
let connectionId: string = await this.getConnectionId();
|
||||
|
||||
let connectionId: string;
|
||||
|
||||
if (!currentConnection) {
|
||||
connectionId = (await azdata.connection.openConnectionDialog(['MSSQL'])).connectionId;
|
||||
if (!connectionId) {
|
||||
vscode.window.showErrorMessage(localize('import.needConnection', "Please connect to a server before using this wizard."));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (currentConnection.providerId !== 'MSSQL') {
|
||||
vscode.window.showErrorMessage(localize('import.needSQLConnection', "SQL Server Import extension does not support this type of connection"));
|
||||
return;
|
||||
}
|
||||
connectionId = currentConnection.connectionId;
|
||||
if (!connectionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
model.serverId = connectionId;
|
||||
|
||||
this.wizard = azdata.window.createWizard(localize('flatFileImport.wizardName', "Import flat file wizard"));
|
||||
let page1 = azdata.window.createWizardPage(localize('flatFileImport.page1Name', "Specify Input File"));
|
||||
let page2 = azdata.window.createWizardPage(localize('flatFileImport.page2Name', "Preview Data"));
|
||||
let page3 = azdata.window.createWizardPage(localize('flatFileImport.page3Name', "Modify Columns"));
|
||||
let page4 = azdata.window.createWizardPage(localize('flatFileImport.page4Name', "Summary"));
|
||||
this.wizard = this._apiWrapper.createWizard(constants.wizardNameText);
|
||||
this.page1 = this._apiWrapper.createWizardPage(constants.page1NameText);
|
||||
this.page2 = this._apiWrapper.createWizardPage(constants.page2NameText);
|
||||
this.page3 = this._apiWrapper.createWizardPage(constants.page3NameText);
|
||||
this.page4 = this._apiWrapper.createWizardPage(constants.page4NameText);
|
||||
|
||||
let fileConfigPage: FileConfigPage;
|
||||
|
||||
page1.registerContent(async (view) => {
|
||||
fileConfigPage = new FileConfigPage(this, page1, model, view, this.provider);
|
||||
this.page1.registerContent(async (view) => {
|
||||
fileConfigPage = new FileConfigPage(this, this.page1, model, view, this.provider, this._apiWrapper);
|
||||
pages.set(0, fileConfigPage);
|
||||
await fileConfigPage.start().then(() => {
|
||||
fileConfigPage.setupNavigationValidator();
|
||||
@@ -77,29 +69,29 @@ export class FlatFileWizard {
|
||||
});
|
||||
|
||||
let prosePreviewPage: ProsePreviewPage;
|
||||
page2.registerContent(async (view) => {
|
||||
prosePreviewPage = new ProsePreviewPage(this, page2, model, view, this.provider);
|
||||
this.page2.registerContent(async (view) => {
|
||||
prosePreviewPage = new ProsePreviewPage(this, this.page2, model, view, this.provider, this._apiWrapper);
|
||||
pages.set(1, prosePreviewPage);
|
||||
await prosePreviewPage.start();
|
||||
});
|
||||
|
||||
let modifyColumnsPage: ModifyColumnsPage;
|
||||
page3.registerContent(async (view) => {
|
||||
modifyColumnsPage = new ModifyColumnsPage(this, page3, model, view, this.provider);
|
||||
this.page3.registerContent(async (view) => {
|
||||
modifyColumnsPage = new ModifyColumnsPage(this, this.page3, model, view, this.provider, this._apiWrapper);
|
||||
pages.set(2, modifyColumnsPage);
|
||||
await modifyColumnsPage.start();
|
||||
});
|
||||
|
||||
let summaryPage: SummaryPage;
|
||||
|
||||
page4.registerContent(async (view) => {
|
||||
summaryPage = new SummaryPage(this, page4, model, view, this.provider);
|
||||
this.page4.registerContent(async (view) => {
|
||||
summaryPage = new SummaryPage(this, this.page4, model, view, this.provider, this._apiWrapper);
|
||||
pages.set(3, summaryPage);
|
||||
await summaryPage.start();
|
||||
});
|
||||
|
||||
|
||||
this.importAnotherFileButton = azdata.window.createButton(localize('flatFileImport.importNewFile', "Import new file"));
|
||||
this.importAnotherFileButton = this._apiWrapper.createButton(constants.importNewFileText);
|
||||
this.importAnotherFileButton.onClick(() => {
|
||||
//TODO replace this with proper cleanup for all the pages
|
||||
this.wizard.close();
|
||||
@@ -126,11 +118,33 @@ export class FlatFileWizard {
|
||||
//not needed for this wizard
|
||||
this.wizard.generateScriptButton.hidden = true;
|
||||
|
||||
this.wizard.pages = [page1, page2, page3, page4];
|
||||
this.wizard.pages = [this.page1, this.page2, this.page3, this.page4];
|
||||
|
||||
this.wizard.open();
|
||||
}
|
||||
|
||||
public async getConnectionId(): Promise<string> {
|
||||
let currentConnection = await this._apiWrapper.getCurrentConnection();
|
||||
|
||||
let connectionId: string;
|
||||
|
||||
if (!currentConnection) {
|
||||
let connection = await this._apiWrapper.openConnectionDialog(constants.supportedProviders);
|
||||
if (!connection) {
|
||||
this._apiWrapper.showErrorMessage(constants.needConnectionText);
|
||||
return undefined;
|
||||
}
|
||||
connectionId = connection.connectionId;
|
||||
} else {
|
||||
if (currentConnection.providerId !== 'MSSQL') {
|
||||
this._apiWrapper.showErrorMessage(constants.needSqlConnectionText);
|
||||
return undefined;
|
||||
}
|
||||
connectionId = currentConnection.connectionId;
|
||||
}
|
||||
return connectionId;
|
||||
}
|
||||
|
||||
public setImportAnotherFileVisibility(visibility: boolean) {
|
||||
this.importAnotherFileButton.hidden = !visibility;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user