mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 11:08:31 -05:00
* 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 * -Added some modifyColumnPage tests * pushing temp changes * -Added some more testcases * -Added tests using available vscode and azdata apis * some minor comment change * removed unnecessary test * added accidently removed test * Added some comments * fixed some broken tests and added comments in fileConfigPage * code clean up and some more comments * fixed the prosePreviewPage test and the download test * added getter and setters * Increasing timeout and fixing a comment * removed unnecessary comments and some other code cleanup * Deleting dotnet files before redownloading them * - made changes in the PR - Moved extensioncode to utils.test for better reusability * added some 'should' messages
150 lines
5.5 KiB
TypeScript
150 lines
5.5 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 * as azdata from 'azdata';
|
|
import { ApiWrapper } from '../../../common/apiWrapper';
|
|
import * as constants from '../../../common/constants';
|
|
import { FlatFileWizard } from '../../../wizard/flatFileWizard';
|
|
import * as should from 'should';
|
|
import { ImportDataModel } from '../../../wizard/api/models';
|
|
import { TestImportDataModel, TestFlatFileProvider } from '../../utils.test';
|
|
import { ImportPage } from '../../../wizard/api/importPage';
|
|
import { SummaryPage } from '../../../wizard/pages/summaryPage';
|
|
import { FlatFileProvider, InsertDataResponse } from '../../../services/contracts';
|
|
|
|
describe('import extension summary page tests', function () {
|
|
|
|
let mockFlatFileWizard: TypeMoq.IMock<FlatFileWizard>;
|
|
let mockImportModel: TypeMoq.IMock<ImportDataModel>;
|
|
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
|
let mockFlatFileProvider: TypeMoq.IMock<FlatFileProvider>;
|
|
|
|
let summaryPage: SummaryPage;
|
|
let wizard: azdata.window.Wizard;
|
|
let page: azdata.window.WizardPage;
|
|
let pages: Map<number, ImportPage> = new Map<number, ImportPage>();
|
|
|
|
beforeEach(async function () {
|
|
// Keeping the original behaviour of apiWrapper until some setup is needed to mock stuff
|
|
mockApiWrapper = TypeMoq.Mock.ofType(ApiWrapper, TypeMoq.MockBehavior.Loose);
|
|
mockApiWrapper.callBase = true;
|
|
|
|
mockFlatFileProvider = TypeMoq.Mock.ofType(TestFlatFileProvider);
|
|
mockFlatFileWizard = TypeMoq.Mock.ofType(FlatFileWizard, TypeMoq.MockBehavior.Loose, undefined, mockFlatFileProvider.object, mockApiWrapper.object);
|
|
mockImportModel = TypeMoq.Mock.ofType(TestImportDataModel, TypeMoq.MockBehavior.Loose);
|
|
|
|
wizard = mockApiWrapper.object.createWizard(constants.wizardNameText);
|
|
page = mockApiWrapper.object.createWizardPage(constants.page4NameText);
|
|
|
|
});
|
|
|
|
it('checking if all components are initialized properly', async function () {
|
|
|
|
await new Promise(function (resolve) {
|
|
page.registerContent(async (view) => {
|
|
summaryPage = new SummaryPage(mockFlatFileWizard.object, page, mockImportModel.object, view, TypeMoq.It.isAny(), mockApiWrapper.object);
|
|
pages.set(1, summaryPage);
|
|
await summaryPage.start();
|
|
resolve();
|
|
|
|
});
|
|
wizard.generateScriptButton.hidden = true;
|
|
|
|
wizard.pages = [page];
|
|
wizard.open();
|
|
});
|
|
|
|
// checking if all the required components are correctly initialized
|
|
should.notEqual(summaryPage.table, undefined, 'table should not be undefined');
|
|
should.notEqual(summaryPage.statusText, undefined, 'statusText should not be undefined');
|
|
should.notEqual(summaryPage.loading, undefined, 'loading should not be undefined');
|
|
should.notEqual(summaryPage.form, undefined, 'form should not be undefined');
|
|
|
|
await summaryPage.onPageLeave();
|
|
await summaryPage.cleanup();
|
|
|
|
});
|
|
|
|
it('handle import updates status Text correctly', async function () {
|
|
|
|
// Creating a test Connection
|
|
let testServerConnection: azdata.connection.Connection = {
|
|
providerName: 'testProviderName',
|
|
connectionId: 'testConnectionId',
|
|
options: {}
|
|
};
|
|
|
|
|
|
// setting up connection objects in model
|
|
mockImportModel.object.server = testServerConnection;
|
|
mockImportModel.object.database = 'testDatabase';
|
|
mockImportModel.object.schema = 'testSchema';
|
|
mockImportModel.object.filePath = 'testFilePath';
|
|
|
|
// Creating test columns
|
|
let testProseColumns = [
|
|
{
|
|
columnName: 'column1',
|
|
dataType: 'nvarchar(50)',
|
|
primaryKey: false,
|
|
nullable: false
|
|
},
|
|
{
|
|
columnName: 'column2',
|
|
dataType: 'nvarchar(50)',
|
|
primaryKey: false,
|
|
nullable: false
|
|
}
|
|
];
|
|
mockImportModel.object.proseColumns = testProseColumns;
|
|
|
|
// setting up a test table insert response from FlatFileProvider
|
|
let testSendInsertDataRequestResponse: InsertDataResponse = {
|
|
result: {
|
|
success: true,
|
|
errorMessage: ''
|
|
}
|
|
};
|
|
mockFlatFileProvider.setup(x => x.sendInsertDataRequest(TypeMoq.It.isAny())).returns(async () => { return testSendInsertDataRequestResponse; });
|
|
|
|
await new Promise(function (resolve) {
|
|
page.registerContent(async (view) => {
|
|
summaryPage = new SummaryPage(mockFlatFileWizard.object, page, mockImportModel.object, view, mockFlatFileProvider.object, mockApiWrapper.object);
|
|
pages.set(1, summaryPage);
|
|
await summaryPage.start();
|
|
summaryPage.setupNavigationValidator();
|
|
resolve();
|
|
});
|
|
wizard.generateScriptButton.hidden = true;
|
|
|
|
wizard.pages = [page];
|
|
wizard.open();
|
|
});
|
|
|
|
// Entering the page. This method will try to create table using FlatFileProvider
|
|
await summaryPage.onPageEnter();
|
|
|
|
// In case of success we should see the success message
|
|
should.equal(summaryPage.statusText.value, constants.updateText);
|
|
|
|
// In case of a failure we should see the error message
|
|
testSendInsertDataRequestResponse = {
|
|
result: {
|
|
success: false,
|
|
errorMessage: 'testError'
|
|
}
|
|
};
|
|
|
|
// mocking the insertDataRequest to fail
|
|
mockFlatFileProvider.setup(x => x.sendInsertDataRequest(TypeMoq.It.isAny())).returns(async () => { return testSendInsertDataRequestResponse; });
|
|
|
|
// Entering the page. This method will try to create table using FlatFileProvider
|
|
await summaryPage.onPageEnter();
|
|
should.equal(summaryPage.statusText.value, constants.summaryErrorSymbol + 'testError');
|
|
|
|
});
|
|
});
|