Use azdata-test modelview stubs (#13818)

This commit is contained in:
Charles Gagnon
2020-12-16 16:28:02 -08:00
committed by GitHub
parent 7b06194199
commit 7f38e87ef3
13 changed files with 152 additions and 386 deletions

View File

@@ -3,29 +3,22 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import * as path from 'path';
import * as should from 'should';
import * as sinon from 'sinon';
import * as vscode from 'vscode';
import { Deferred } from '../../../common/promise';
import { FilePicker } from '../../../ui/components/filePicker';
import { createModelViewMock } from '../../stubs';
import { createModelViewMock } from 'azdata-test/out/mocks/modelView/modelViewMock';
import { StubButton } from 'azdata-test/out/stubs/modelView/stubButton';
let filePicker: FilePicker;
const initialPath = path.join('path', 'to', '.kube','config');
const newFileUri = vscode.Uri.file(path.join('path', 'to', 'new', '.kube', 'config'));
let filePathInputBox: azdata.InputBoxComponent;
let browseButton: azdata.ButtonComponent;
let flexContainer: azdata.FlexContainer;
const browseButtonEmitter = new vscode.EventEmitter<undefined>();
describe('filePicker', function (): void {
beforeEach(async () => {
const { mockModelBuilder, mockInputBoxBuilder, mockButtonBuilder, mockFlexBuilder } = createModelViewMock(browseButtonEmitter);
filePicker = new FilePicker(mockModelBuilder.object, initialPath, (_disposable) => { });
filePathInputBox = mockInputBoxBuilder.object.component();
browseButton = mockButtonBuilder.object.component();
flexContainer = mockFlexBuilder.object.component();
const { modelBuilderMock } = createModelViewMock();
filePicker = new FilePicker(modelBuilderMock.object, initialPath, (_disposable) => { });
});
afterEach(() => {
@@ -33,22 +26,22 @@ describe('filePicker', function (): void {
});
it('browse Button chooses new FilePath', async () => {
should(filePathInputBox.value).should.not.be.undefined();
should(filePicker.filePathInputBox.value).should.not.be.undefined();
filePicker.value!.should.equal(initialPath);
flexContainer.items.should.deepEqual([filePathInputBox, browseButton]);
filePicker.component().items.length.should.equal(2, 'Filepicker container should have two components');
const deferred = new Deferred();
sinon.stub(vscode.window, 'showOpenDialog').callsFake(async (_options) => {
deferred.resolve();
return [newFileUri];
});
browseButtonEmitter.fire(undefined); //simulate the click of the browseButton
(filePicker.filePickerButton as StubButton).click();
await deferred;
filePicker.value!.should.equal(newFileUri.fsPath);
});
describe('getters and setters', async () => {
it('component getter', () => {
should(filePicker.component()).equal(flexContainer);
should(filePicker.component()).not.be.undefined();
});
[true, false].forEach(testValue => {
it(`Test readOnly with testValue: ${testValue}`, () => {