Preserve error messages if workspace validation fails in tests (#13901)

* preserving error messages if test fails

* change name of var to due scope change
This commit is contained in:
Benjin Dubishar
2021-01-11 17:50:34 -08:00
committed by GitHub
parent f37fb0b1d5
commit b69572a7c9
3 changed files with 25 additions and 17 deletions

View File

@@ -17,7 +17,7 @@ interface Deferred<T> {
export abstract class DialogBase {
protected _toDispose: vscode.Disposable[] = [];
protected _dialogObject: azdata.window.Dialog;
public dialogObject: azdata.window.Dialog;
protected initDialogComplete: Deferred<void> | undefined;
protected initDialogPromise: Promise<void> = new Promise<void>((resolve, reject) => this.initDialogComplete = { resolve, reject });
protected workspaceDescriptionFormComponent: azdata.FormComponent | undefined;
@@ -25,11 +25,11 @@ export abstract class DialogBase {
protected workspaceInputFormComponent: azdata.FormComponent | undefined;
constructor(dialogTitle: string, dialogName: string, dialogWidth: azdata.window.DialogWidth = 600) {
this._dialogObject = azdata.window.createModelViewDialog(dialogTitle, dialogName, dialogWidth);
this._dialogObject.okButton.label = constants.OkButtonText;
this.register(this._dialogObject.cancelButton.onClick(() => this.onCancelButtonClicked()));
this.register(this._dialogObject.okButton.onClick(() => this.onOkButtonClicked()));
this._dialogObject.registerCloseValidator(async () => {
this.dialogObject = azdata.window.createModelViewDialog(dialogTitle, dialogName, dialogWidth);
this.dialogObject.okButton.label = constants.OkButtonText;
this.register(this.dialogObject.cancelButton.onClick(() => this.onCancelButtonClicked()));
this.register(this.dialogObject.okButton.onClick(() => this.onOkButtonClicked()));
this.dialogObject.registerCloseValidator(async () => {
return this.validate();
});
}
@@ -43,8 +43,8 @@ export abstract class DialogBase {
tab.registerContent(async (view: azdata.ModelView) => {
return this.initialize(view);
});
this._dialogObject.content = [tab];
azdata.window.openDialog(this._dialogObject);
this.dialogObject.content = [tab];
azdata.window.openDialog(this.dialogObject);
await this.initDialogPromise;
}
@@ -69,14 +69,14 @@ export abstract class DialogBase {
}
protected showErrorMessage(message: string): void {
this._dialogObject.message = {
this.dialogObject.message = {
text: message,
level: azdata.window.MessageLevel.Error
};
}
public getErrorMessage(): azdata.window.DialogMessage {
return this._dialogObject.message;
return this.dialogObject.message;
}
protected createHorizontalContainer(view: azdata.ModelView, items: azdata.Component[]): azdata.FlexContainer {

View File

@@ -48,7 +48,6 @@ export class OpenExistingDialog extends DialogBase {
}
catch (err) {
this.showErrorMessage(err?.message ? err.message : err);
console.log(err?.message ? err.message : err);
return false;
}
}

View File

@@ -26,14 +26,18 @@ suite('Open Existing Dialog', function (): void {
await dialog.open();
dialog._targetTypeRadioCardGroup?.updateProperty( 'selectedCardId', constants.Project);
dialog._filePathTextBox!.value = '';
dialog._filePathTextBox!.value = 'nonExistentProjectFile';
dialog.workspaceInputBox!.value = 'test.code-workspace';
should.equal(await dialog.validate(), false, 'Validation fail because project file does not exist');
const validateResult = await dialog.validate();
const msg = constants.FileNotExistError('project', 'nonExistentProjectFile');
should.equal(dialog.dialogObject.message.text, msg);
should.equal(validateResult, false, 'Validation should fail because project file does not exist, but passed');
// create a project file
dialog._filePathTextBox!.value = await createProjectFile('testproj');
should.equal(await dialog.validate(), true, 'Validation pass because project file exists');
should.equal(await dialog.validate(), true, `Validation should pass because project file exists, but failed with: ${dialog.dialogObject.message.text}`);
});
test('Should validate workspace file exists', async function (): Promise<void> {
@@ -42,13 +46,18 @@ suite('Open Existing Dialog', function (): void {
await dialog.open();
dialog._targetTypeRadioCardGroup?.updateProperty( 'selectedCardId', constants.Workspace);
dialog._filePathTextBox!.value = '';
should.equal(await dialog.validate(), false, 'Validation fail because workspace file does not exist');
dialog._filePathTextBox!.value = 'nonExistentWorkspaceFile';
const validateResult = await dialog.validate();
const msg = constants.FileNotExistError('workspace', 'nonExistentWorkspaceFile');
should.equal(dialog.dialogObject.message.text, msg);
should.equal(validateResult, false, 'Validation should fail because workspace file does not exist, but passed');
// create a workspace file
dialog._filePathTextBox!.value = generateUniqueWorkspaceFilePath();
await fs.writeFile(dialog._filePathTextBox!.value , '');
should.equal(await dialog.validate(), true, 'Validation pass because workspace file exists');
should.equal(await dialog.validate(), true, `Validation should pass because workspace file exists, but failed with: ${dialog.dialogObject.message.text}`);
});