Skip to content

Commit

Permalink
Add setting "showConfirmations" #95
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidFeldhoff committed Mar 9, 2021
1 parent 648a98e commit 40fb22a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
],
"default": "Ask for confirmation",
"description": "Specifies if you're asked if a helper function should be deleted if it's not used anymore after 1. a removal of a given/when/then, 2. a removal of a scenario, 3. a rename of a given/when/then if a helper function to the new naming already exists and you switch to using that one"
},
"atddTestScriptor.showConfirmations": {
"type": "boolean",
"default": true,
"description": "Specifies if confirmations will show up on updating/removing elements in general."
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions vscode-extension/src/App logic/Utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class Config {
static getTestSrcFolder(): string | undefined {
return this.getConfig().get<string>('testDirectory');
}
static getShowConfirmations(uri: Uri | undefined): boolean {
return this.getConfig(uri).get<boolean>('showConfirmations', true);
}
private static getConfig(uri?: Uri): WorkspaceConfiguration {
return workspace.getConfiguration(this.app, uri);
}
Expand Down
11 changes: 7 additions & 4 deletions vscode-extension/src/App logic/Utils/informationsOutput.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import * as vscode from 'vscode';
// import { window } from 'vscode';
import { Config } from './config';

export interface InformationOutput {
ask(question: string, options: string[]): Promise<string | undefined>;
ask(question: string, options: string[], defaultOption: string): Promise<string | undefined>;
}
export class VSCodeInformationOutput implements InformationOutput {
async ask(question: string, options: string[]): Promise<string | undefined> {
async ask(question: string, options: string[], defaultOption: string): Promise<string | undefined> {
if (options.length > 0 && !Config.getShowConfirmations(vscode.window.activeTextEditor?.document.uri))
return defaultOption

switch (options.length) {
case 0:
vscode.window.showInformationMessage(question);
Expand All @@ -28,7 +31,7 @@ export class TestInformationOutput implements InformationOutput {
configure(question: string, response: string) {
this.resultMap.set(question, response);
}
async ask(question: string, options: string[]): Promise<string | undefined> {
async ask(question: string, options: string[], defaultOption: string): Promise<string | undefined> {
this.askedQuestions.push({ question, options })
if (this.resultMap.has(question))
return this.resultMap.get(question);
Expand Down
16 changes: 8 additions & 8 deletions vscode-extension/src/Services/WebPanelCommandService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ export class WebPanelCommandService {
if ([MessageState.Deleted, MessageState.Modified].includes(entry.State)) {
let response: string | undefined;
if (entry.State == MessageState.Deleted)
response = await informationOutput.ask(confirmDeletion('this element'), [optionYes, optionNo])
response = await informationOutput.ask(confirmDeletion('this element'), [optionYes, optionNo], optionYes)
else
response = await informationOutput.ask(confirmUpdate('this element'), [optionYes, optionNo])
response = await informationOutput.ask(confirmUpdate('this element'), [optionYes, optionNo], optionYes)
if (response === optionYes) {
let useNewProcedure: boolean = true;
if (entry.State == MessageState.Modified) {
if (await this.middlewareService.checkIfOldAndNewProcedureExists(entry)) {
let optionKeepOld: string = 'Keep old';
let optionSwitchToNew: string = 'Switch to new one';
response = await informationOutput.ask(askWhichProcedureToTake, [optionKeepOld, optionSwitchToNew])
response = await informationOutput.ask(askWhichProcedureToTake, [optionKeepOld, optionSwitchToNew], optionSwitchToNew)
if (response === optionKeepOld)
useNewProcedure = false;
}
Expand All @@ -109,7 +109,7 @@ export class WebPanelCommandService {
if (helperFunctionsWhichCouldBeDeleted.length == 1) {
let responseHelperFunctionShouldBeDeleted: string | undefined;
if (removalMode == Config.removalModeConfirmation)
responseHelperFunctionShouldBeDeleted = await informationOutput.ask(confirmDeletion('the procedure \'' + helperFunctionsWhichCouldBeDeleted[0].procedureName) + '\'', [optionYes, optionNo]);
responseHelperFunctionShouldBeDeleted = await informationOutput.ask(confirmDeletion('the procedure \'' + helperFunctionsWhichCouldBeDeleted[0].procedureName) + '\'', [optionYes, optionNo], optionYes);
if (responseHelperFunctionShouldBeDeleted === optionYes || removalMode == Config.removalModeNoConfirmationButRemoval)
proceduresToDelete = helperFunctionsWhichCouldBeDeleted;
else
Expand All @@ -126,7 +126,7 @@ export class WebPanelCommandService {
if (entry.State == MessageState.Deleted) {
let responseScenarioShouldBeDeleted: string | undefined
if (!entry.internalCall)
responseScenarioShouldBeDeleted = await informationOutput.ask(confirmDeletion('this scenario'), [optionYes, optionNo]);
responseScenarioShouldBeDeleted = await informationOutput.ask(confirmDeletion('this scenario'), [optionYes, optionNo], optionYes);
else
responseScenarioShouldBeDeleted = optionYes
if (responseScenarioShouldBeDeleted === optionYes) {
Expand All @@ -137,7 +137,7 @@ export class WebPanelCommandService {
for (let i = 1; i < proceduresWhichCouldBeDeleted.length; i++) { //i = 1 because scenario-Testprocedure is also inside this this array
let responseHelperFunctionShouldBeDeleted: string | undefined;
if (removalMode == Config.removalModeConfirmation)
responseHelperFunctionShouldBeDeleted = await informationOutput.ask(confirmDeletion('the procedure \'' + proceduresWhichCouldBeDeleted[i].procedureName) + '\'', [optionYes, optionNo]);
responseHelperFunctionShouldBeDeleted = await informationOutput.ask(confirmDeletion('the procedure \'' + proceduresWhichCouldBeDeleted[i].procedureName) + '\'', [optionYes, optionNo], optionYes);
if (responseHelperFunctionShouldBeDeleted === optionYes || removalMode == Config.removalModeNoConfirmationButRemoval) {
proceduresToDelete.push(proceduresWhichCouldBeDeleted[i]);
}
Expand All @@ -147,15 +147,15 @@ export class WebPanelCommandService {
return { wantsToContinue: false, wantsProceduresToBeDeleted: [], updateProcedureCall: false };
}
} else if (entry.State == MessageState.Modified) {
let responseScenarioShouldBeModified: string | undefined = await informationOutput.ask(confirmUpdate('this scenario'), [optionYes, optionNo]);
let responseScenarioShouldBeModified: string | undefined = await informationOutput.ask(confirmUpdate('this scenario'), [optionYes, optionNo], optionYes);
if (responseScenarioShouldBeModified === optionNo) {
return { wantsToContinue: false, wantsProceduresToBeDeleted: [], updateProcedureCall: false };
}
}
return { wantsToContinue: true, wantsProceduresToBeDeleted: [], updateProcedureCall: true };
} else if (TypeChanged.Feature == entry.Type) {
if (entry.State == MessageState.Deleted) {
let responseScenarioShouldBeDeleted: string | undefined = await informationOutput.ask(confirmDeletion('this feature'), [optionYes, optionNo]);
let responseScenarioShouldBeDeleted: string | undefined = await informationOutput.ask(confirmDeletion('this feature'), [optionYes, optionNo], optionYes);
if (responseScenarioShouldBeDeleted == optionNo)
return { wantsToContinue: false, wantsProceduresToBeDeleted: [], updateProcedureCall: false };
}
Expand Down

0 comments on commit 40fb22a

Please sign in to comment.