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:
Aasim Khan
2020-06-16 13:24:48 -07:00
committed by GitHub
parent 94bc0d9559
commit f725ee96b9
22 changed files with 1356 additions and 231 deletions

View File

@@ -5,12 +5,14 @@
import * as azdata from 'azdata';
import { ImportDataModel } from './models';
import { ApiWrapper } from '../../common/apiWrapper';
export abstract class BasePage {
protected readonly wizardPage: azdata.window.WizardPage;
protected readonly model: ImportDataModel;
protected readonly view: azdata.ModelView;
protected _apiWrapper: ApiWrapper;
/**
* This method constructs all the elements of the page.
@@ -42,8 +44,8 @@ export abstract class BasePage {
*/
public abstract setupNavigationValidator(): void;
protected async getServerValues(): Promise<{ connection: azdata.connection.Connection, displayName: string, name: string }[]> {
let cons = await azdata.connection.getActiveConnections();
public async getServerValues(): Promise<{ connection: azdata.connection.Connection, displayName: string, name: string }[]> {
let cons = await this._apiWrapper.getActiveConnections();
// This user has no active connections ABORT MISSION
if (!cons || cons.length === 0) {
return undefined;
@@ -90,10 +92,10 @@ export abstract class BasePage {
return values;
}
protected async getDatabaseValues(): Promise<{ displayName: string, name: string }[]> {
public async getDatabaseValues(): Promise<{ displayName: string, name: string }[]> {
let idx = -1;
let count = -1;
let values = (await azdata.connection.listDatabases(this.model.server.connectionId)).map(db => {
let values = (await this._apiWrapper.listDatabases(this.model.server.connectionId)).map(db => {
count++;
if (this.model.database && db === this.model.database) {
idx = count;
@@ -109,10 +111,7 @@ export abstract class BasePage {
let tmp = values[0];
values[0] = values[idx];
values[idx] = tmp;
} else {
this.deleteDatabaseValues();
}
return values;
}
@@ -121,8 +120,4 @@ export abstract class BasePage {
delete this.model.serverId;
delete this.model.database;
}
protected deleteDatabaseValues() {
return;
}
}

View File

@@ -8,6 +8,7 @@ import * as azdata from 'azdata';
import { FlatFileProvider } from '../../services/contracts';
import { FlatFileWizard } from '../flatFileWizard';
import { BasePage } from './basePage';
import { ApiWrapper } from '../../common/apiWrapper';
export abstract class ImportPage extends BasePage {
@@ -17,12 +18,14 @@ export abstract class ImportPage extends BasePage {
protected readonly view: azdata.ModelView;
protected readonly provider: FlatFileProvider;
protected constructor(instance: FlatFileWizard, wizardPage: azdata.window.WizardPage, model: ImportDataModel, view: azdata.ModelView, provider: FlatFileProvider) {
constructor(instance: FlatFileWizard, wizardPage: azdata.window.WizardPage, model: ImportDataModel, view: azdata.ModelView, provider: FlatFileProvider, apiWrapper: ApiWrapper) {
super();
this.instance = instance;
this.wizardPage = wizardPage;
this.model = model;
this.view = view;
this.provider = provider;
this._apiWrapper = apiWrapper;
}
}