mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
fix object management dialog's validation issue (#22556)
* fix validation issue * make message optional * fix errors
This commit is contained in:
@@ -69,7 +69,7 @@ export abstract class DialogBase {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public getErrorMessage(): azdataType.window.DialogMessage {
|
public getErrorMessage(): azdataType.window.DialogMessage | undefined {
|
||||||
return this.dialogObject.message;
|
return this.dialogObject.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ suite('Open Existing Dialog', function (): void {
|
|||||||
const validateResult = await dialog.validate();
|
const validateResult = await dialog.validate();
|
||||||
|
|
||||||
const msg = constants.FileNotExistError('project', 'nonExistentProjectFile');
|
const msg = constants.FileNotExistError('project', 'nonExistentProjectFile');
|
||||||
should.equal(dialog.dialogObject.message.text, msg);
|
should.equal(dialog.dialogObject.message?.text, msg);
|
||||||
should.equal(validateResult, false, 'Validation should fail because project file does not exist, but passed');
|
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 should pass because project file exists, but failed with: ${dialog.dialogObject.message.text}`);
|
should.equal(await dialog.validate(), true, `Validation should pass because project file exists, but failed with: ${dialog.dialogObject.message?.text}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -50,13 +50,13 @@ suite('Open Existing Dialog', function (): void {
|
|||||||
|
|
||||||
const validateResult = await dialog.validate();
|
const validateResult = await dialog.validate();
|
||||||
const msg = constants.CloneParentDirectoryNotExistError(dialog.localClonePathTextBox!.value);
|
const msg = constants.CloneParentDirectoryNotExistError(dialog.localClonePathTextBox!.value);
|
||||||
should.equal(dialog.dialogObject.message.text, msg, 'Dialog message should be correct');
|
should.equal(dialog.dialogObject.message?.text, msg, 'Dialog message should be correct');
|
||||||
should.equal(validateResult, false, 'Validation should fail because clone directory does not exist, but passed');
|
should.equal(validateResult, false, 'Validation should fail because clone directory does not exist, but passed');
|
||||||
|
|
||||||
// validation should pass if directory exists
|
// validation should pass if directory exists
|
||||||
dialog.localClonePathTextBox!.value = os.tmpdir();
|
dialog.localClonePathTextBox!.value = os.tmpdir();
|
||||||
folderExistStub.resolves(true);
|
folderExistStub.resolves(true);
|
||||||
should.equal(await dialog.validate(), true, `Validation should pass because clone directory exists, but failed with: ${dialog.dialogObject.message.text}`);
|
should.equal(await dialog.validate(), true, `Validation should pass because clone directory exists, but failed with: ${dialog.dialogObject.message?.text}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('project browse', async function (): Promise<void> {
|
test('project browse', async function (): Promise<void> {
|
||||||
|
|||||||
@@ -198,13 +198,13 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
|||||||
|
|
||||||
protected async runValidation(showErrorMessage: boolean = true): Promise<boolean> {
|
protected async runValidation(showErrorMessage: boolean = true): Promise<boolean> {
|
||||||
const errors = await this.validateInput();
|
const errors = await this.validateInput();
|
||||||
if (errors.length > 0 && (this.dialogObject.message || showErrorMessage)) {
|
if (errors.length > 0 && (this.dialogObject.message?.text || showErrorMessage)) {
|
||||||
this.dialogObject.message = {
|
this.dialogObject.message = {
|
||||||
text: errors.join(EOL),
|
text: errors.join(EOL),
|
||||||
level: azdata.window.MessageLevel.Error
|
level: azdata.window.MessageLevel.Error
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
this.dialogObject.message = { text: '' };
|
this.dialogObject.message = undefined;
|
||||||
}
|
}
|
||||||
return errors.length === 0;
|
return errors.length === 0;
|
||||||
}
|
}
|
||||||
|
|||||||
2
src/sql/azdata.d.ts
vendored
2
src/sql/azdata.d.ts
vendored
@@ -4985,7 +4985,7 @@ declare module 'azdata' {
|
|||||||
* Set the informational message shown in the dialog. Hidden when the message is
|
* Set the informational message shown in the dialog. Hidden when the message is
|
||||||
* undefined or the text is empty or undefined. The default level is error.
|
* undefined or the text is empty or undefined. The default level is error.
|
||||||
*/
|
*/
|
||||||
message: DialogMessage;
|
message?: DialogMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the dialog name when opening
|
* Set the dialog name when opening
|
||||||
|
|||||||
Reference in New Issue
Block a user