mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 01:25:39 -05:00
Fix unstable data-workspace tests (#13824)
* stub file existing validation * add error message * change back to calling dialog.validate() * move tests to separate dialogbase file and add more error message validation
This commit is contained in:
@@ -36,9 +36,7 @@ export abstract class DialogBase {
|
||||
|
||||
protected abstract initialize(view: azdata.ModelView): Promise<void>;
|
||||
|
||||
protected async validate(): Promise<boolean> {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
abstract validate(): Promise<boolean>;
|
||||
|
||||
public async open(): Promise<void> {
|
||||
const tab = azdata.window.createTab('');
|
||||
@@ -77,6 +75,10 @@ export abstract class DialogBase {
|
||||
};
|
||||
}
|
||||
|
||||
public getErrorMessage(): azdata.window.DialogMessage {
|
||||
return this._dialogObject.message;
|
||||
}
|
||||
|
||||
protected createHorizontalContainer(view: azdata.ModelView, items: azdata.Component[]): azdata.FlexContainer {
|
||||
return view.modelBuilder.flexContainer().withItems(items, { CSSStyles: { 'margin-right': '5px', 'margin-bottom': '10px' } }).withLayout({ flexFlow: 'row', alignItems: 'center' }).component();
|
||||
}
|
||||
@@ -159,7 +161,7 @@ export abstract class DialogBase {
|
||||
}
|
||||
}
|
||||
|
||||
protected async validateNewWorkspace(sameFolderAsNewProject: boolean): Promise<boolean> {
|
||||
public async validateNewWorkspace(sameFolderAsNewProject: boolean): Promise<boolean> {
|
||||
// workspace file should end in .code-workspace
|
||||
const workspaceValid = this.workspaceInputBox!.value!.endsWith(constants.WorkspaceFileExtension);
|
||||
if (!workspaceValid) {
|
||||
@@ -171,7 +173,7 @@ export abstract class DialogBase {
|
||||
if (!sameFolderAsNewProject) {
|
||||
const workspaceParentDirectoryExists = await directoryExist(path.dirname(this.workspaceInputBox!.value!));
|
||||
if (!workspaceParentDirectoryExists) {
|
||||
this.showErrorMessage(constants.WorkspaceParentDirectoryNotExistError(this.workspaceInputBox!.value!));
|
||||
this.showErrorMessage(constants.WorkspaceParentDirectoryNotExistError(path.dirname(this.workspaceInputBox!.value!)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,7 @@ export class OpenExistingDialog extends DialogBase {
|
||||
try {
|
||||
// the selected location should be an existing directory
|
||||
if (this._targetTypeRadioCardGroup?.selectedCardId === constants.Project) {
|
||||
const fileExists = await fileExist(this._projectFile);
|
||||
if (!fileExists) {
|
||||
this.showErrorMessage(constants.FileNotExistError(constants.Project.toLowerCase(), this._projectFile));
|
||||
if (!await this.validateFile(this._projectFile, constants.Project.toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -47,9 +45,7 @@ export class OpenExistingDialog extends DialogBase {
|
||||
return false;
|
||||
}
|
||||
} else if (this._targetTypeRadioCardGroup?.selectedCardId === constants.Workspace) {
|
||||
const fileExists = await fileExist(this._workspaceFile);
|
||||
if (!fileExists) {
|
||||
this.showErrorMessage(constants.FileNotExistError(constants.Workspace.toLowerCase(), this._workspaceFile));
|
||||
if (!await this.validateFile(this._workspaceFile, constants.Workspace.toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -62,6 +58,16 @@ export class OpenExistingDialog extends DialogBase {
|
||||
}
|
||||
}
|
||||
|
||||
public async validateFile(file: string, fileType: string) {
|
||||
const fileExists = await fileExist(file);
|
||||
if (!fileExists) {
|
||||
this.showErrorMessage(constants.FileNotExistError(fileType, file));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async onComplete(): Promise<void> {
|
||||
try {
|
||||
if (this._targetTypeRadioCardGroup?.selectedCardId === constants.Workspace) {
|
||||
|
||||
Reference in New Issue
Block a user