mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
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:
@@ -17,7 +17,7 @@ interface Deferred<T> {
|
|||||||
|
|
||||||
export abstract class DialogBase {
|
export abstract class DialogBase {
|
||||||
protected _toDispose: vscode.Disposable[] = [];
|
protected _toDispose: vscode.Disposable[] = [];
|
||||||
protected _dialogObject: azdata.window.Dialog;
|
public dialogObject: azdata.window.Dialog;
|
||||||
protected initDialogComplete: Deferred<void> | undefined;
|
protected initDialogComplete: Deferred<void> | undefined;
|
||||||
protected initDialogPromise: Promise<void> = new Promise<void>((resolve, reject) => this.initDialogComplete = { resolve, reject });
|
protected initDialogPromise: Promise<void> = new Promise<void>((resolve, reject) => this.initDialogComplete = { resolve, reject });
|
||||||
protected workspaceDescriptionFormComponent: azdata.FormComponent | undefined;
|
protected workspaceDescriptionFormComponent: azdata.FormComponent | undefined;
|
||||||
@@ -25,11 +25,11 @@ export abstract class DialogBase {
|
|||||||
protected workspaceInputFormComponent: azdata.FormComponent | undefined;
|
protected workspaceInputFormComponent: azdata.FormComponent | undefined;
|
||||||
|
|
||||||
constructor(dialogTitle: string, dialogName: string, dialogWidth: azdata.window.DialogWidth = 600) {
|
constructor(dialogTitle: string, dialogName: string, dialogWidth: azdata.window.DialogWidth = 600) {
|
||||||
this._dialogObject = azdata.window.createModelViewDialog(dialogTitle, dialogName, dialogWidth);
|
this.dialogObject = azdata.window.createModelViewDialog(dialogTitle, dialogName, dialogWidth);
|
||||||
this._dialogObject.okButton.label = constants.OkButtonText;
|
this.dialogObject.okButton.label = constants.OkButtonText;
|
||||||
this.register(this._dialogObject.cancelButton.onClick(() => this.onCancelButtonClicked()));
|
this.register(this.dialogObject.cancelButton.onClick(() => this.onCancelButtonClicked()));
|
||||||
this.register(this._dialogObject.okButton.onClick(() => this.onOkButtonClicked()));
|
this.register(this.dialogObject.okButton.onClick(() => this.onOkButtonClicked()));
|
||||||
this._dialogObject.registerCloseValidator(async () => {
|
this.dialogObject.registerCloseValidator(async () => {
|
||||||
return this.validate();
|
return this.validate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -43,8 +43,8 @@ export abstract class DialogBase {
|
|||||||
tab.registerContent(async (view: azdata.ModelView) => {
|
tab.registerContent(async (view: azdata.ModelView) => {
|
||||||
return this.initialize(view);
|
return this.initialize(view);
|
||||||
});
|
});
|
||||||
this._dialogObject.content = [tab];
|
this.dialogObject.content = [tab];
|
||||||
azdata.window.openDialog(this._dialogObject);
|
azdata.window.openDialog(this.dialogObject);
|
||||||
await this.initDialogPromise;
|
await this.initDialogPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,14 +69,14 @@ export abstract class DialogBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected showErrorMessage(message: string): void {
|
protected showErrorMessage(message: string): void {
|
||||||
this._dialogObject.message = {
|
this.dialogObject.message = {
|
||||||
text: message,
|
text: message,
|
||||||
level: azdata.window.MessageLevel.Error
|
level: azdata.window.MessageLevel.Error
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public getErrorMessage(): azdata.window.DialogMessage {
|
public getErrorMessage(): azdata.window.DialogMessage {
|
||||||
return this._dialogObject.message;
|
return this.dialogObject.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected createHorizontalContainer(view: azdata.ModelView, items: azdata.Component[]): azdata.FlexContainer {
|
protected createHorizontalContainer(view: azdata.ModelView, items: azdata.Component[]): azdata.FlexContainer {
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ export class OpenExistingDialog extends DialogBase {
|
|||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
this.showErrorMessage(err?.message ? err.message : err);
|
this.showErrorMessage(err?.message ? err.message : err);
|
||||||
console.log(err?.message ? err.message : err);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,14 +26,18 @@ suite('Open Existing Dialog', function (): void {
|
|||||||
await dialog.open();
|
await dialog.open();
|
||||||
|
|
||||||
dialog._targetTypeRadioCardGroup?.updateProperty( 'selectedCardId', constants.Project);
|
dialog._targetTypeRadioCardGroup?.updateProperty( 'selectedCardId', constants.Project);
|
||||||
dialog._filePathTextBox!.value = '';
|
dialog._filePathTextBox!.value = 'nonExistentProjectFile';
|
||||||
dialog.workspaceInputBox!.value = 'test.code-workspace';
|
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
|
// create a project file
|
||||||
dialog._filePathTextBox!.value = await createProjectFile('testproj');
|
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> {
|
test('Should validate workspace file exists', async function (): Promise<void> {
|
||||||
@@ -42,13 +46,18 @@ suite('Open Existing Dialog', function (): void {
|
|||||||
await dialog.open();
|
await dialog.open();
|
||||||
|
|
||||||
dialog._targetTypeRadioCardGroup?.updateProperty( 'selectedCardId', constants.Workspace);
|
dialog._targetTypeRadioCardGroup?.updateProperty( 'selectedCardId', constants.Workspace);
|
||||||
dialog._filePathTextBox!.value = '';
|
dialog._filePathTextBox!.value = 'nonExistentWorkspaceFile';
|
||||||
should.equal(await dialog.validate(), false, 'Validation fail because workspace file does not exist');
|
|
||||||
|
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
|
// create a workspace file
|
||||||
dialog._filePathTextBox!.value = generateUniqueWorkspaceFilePath();
|
dialog._filePathTextBox!.value = generateUniqueWorkspaceFilePath();
|
||||||
await fs.writeFile(dialog._filePathTextBox!.value , '');
|
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}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user