Skip to content

Commit 2652d1d

Browse files
authored
AAP-34643: Add "Are you sure?" Confirmation for Reset Button (#1701)
1 parent c469ea4 commit 2652d1d

File tree

10 files changed

+259
-75
lines changed

10 files changed

+259
-75
lines changed

src/features/lightspeed/playbookGeneration.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,25 @@ export async function showPlaybookGenerationPage(extensionUri: vscode.Uri) {
240240
panel.dispose();
241241
break;
242242
}
243+
case "resetOutline": {
244+
vscode.window
245+
.showInformationMessage(
246+
"Are you sure?",
247+
{
248+
modal: true,
249+
detail: "Resetting the outline will loose your changes.",
250+
},
251+
"Ok",
252+
)
253+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
254+
.then((value: any) => {
255+
if (value === "Ok") {
256+
panel.webview.postMessage({
257+
command: "resetOutline",
258+
});
259+
}
260+
});
261+
}
243262
}
244263
});
245264

src/features/lightspeed/roleGeneration.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,25 @@ export async function showRoleGenerationPage(extensionUri: vscode.Uri) {
245245
panel.dispose();
246246
break;
247247
}
248+
case "resetOutline": {
249+
vscode.window
250+
.showInformationMessage(
251+
"Are you sure?",
252+
{
253+
modal: true,
254+
detail: "Resetting the outline will loose your changes.",
255+
},
256+
"Ok",
257+
)
258+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
259+
.then((value: any) => {
260+
if (value === "Ok") {
261+
panel.webview.postMessage({
262+
command: "resetOutline",
263+
});
264+
}
265+
});
266+
}
248267
}
249268
});
250269

src/webview/apps/lightspeed/playbookGeneration/main.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ window.addEventListener("message", async (event) => {
114114
}
115115
break;
116116
}
117+
case "resetOutline": {
118+
setButtonEnabled("reset-button", false);
119+
outline.reset();
120+
outline.focus();
121+
}
117122
}
118123
});
119124

@@ -179,8 +184,9 @@ async function submitInput() {
179184
}
180185

181186
function reset() {
182-
outline.reset();
183-
outline.focus();
187+
vscode.postMessage({
188+
command: "resetOutline",
189+
});
184190
}
185191

186192
function backToPage1() {

src/webview/apps/lightspeed/roleGeneration/main.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ window.addEventListener("message", async (event) => {
154154
}
155155
break;
156156
}
157+
case "resetOutline": {
158+
setButtonEnabled("reset-button", false);
159+
outline.reset();
160+
outline.focus();
161+
}
157162
}
158163
});
159164

@@ -225,8 +230,9 @@ async function submitInput() {
225230
}
226231

227232
function reset() {
228-
outline.reset();
229-
outline.focus();
233+
vscode.postMessage({
234+
command: "resetOutline",
235+
});
230236
}
231237

232238
function backToPage1() {

test/ui-test/lightspeedRoleGenTest.ts

Lines changed: 73 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import {
1010
EditorView,
1111
ModalDialog,
1212
until,
13+
WebView,
1314
} from "vscode-extension-tester";
1415
import {
1516
sleep,
1617
getWebviewByLocator,
1718
workbenchExecuteCommand,
19+
dismissNotifications,
1820
} from "./uiTestHelper";
1921

2022
config.truncateThreshold = 0;
@@ -40,11 +42,7 @@ describe("Verify Role generation feature works as expected", function () {
4042
);
4143
await workbenchExecuteCommand("View: Close All Editor Groups");
4244

43-
const notifications = await workbench.getNotifications();
44-
for (let i = 0; i < notifications.length; i++) {
45-
const n = notifications[i];
46-
await n.dismiss();
47-
}
45+
await dismissNotifications(workbench);
4846
});
4947

5048
after(async function () {
@@ -106,13 +104,15 @@ describe("Verify Role generation feature works as expected", function () {
106104
});
107105

108106
describe("Verify Role generation reset button works as expected", function () {
107+
let webView: WebView;
108+
109109
before(function () {
110110
if (!process.env.TEST_LIGHTSPEED_URL) {
111111
this.skip();
112112
}
113113
});
114114

115-
it("Go on the 2nd page and change the collection name", async function () {
115+
async function setupPage1() {
116116
await VSBrowser.instance.openResources(
117117
"test/units/lightspeed/utils/samples/",
118118
);
@@ -122,28 +122,30 @@ describe("Verify Role generation reset button works as expected", function () {
122122
);
123123
await workbenchExecuteCommand("View: Close All Editor Groups");
124124

125-
const notifications = await workbench.getNotifications();
126-
for (let i = 0; i < notifications.length; i++) {
127-
const n = notifications[i];
128-
await n.dismiss();
129-
}
125+
await dismissNotifications(workbench);
130126

131127
await workbenchExecuteCommand("Ansible Lightspeed: Role generation");
132128
await sleep(500);
133-
const webView = await getWebviewByLocator(
129+
webView = await getWebviewByLocator(
134130
By.xpath("//*[text()='Create a role with Ansible Lightspeed']"),
135131
);
136132
const textArea = await webView.findWebElement(
137133
By.xpath("//vscode-text-area"),
138134
);
139135
await textArea.sendKeys("Install and configure Nginx");
136+
}
140137

141-
(
142-
await webView.findWebElement(
143-
By.xpath("//vscode-button[@id='submit-button']"),
144-
)
145-
).click();
138+
async function gotoPage2() {
139+
const submitButton = await webView.findWebElement(
140+
By.xpath("//vscode-button[@id='submit-button']"),
141+
);
142+
await submitButton.click();
146143
await sleep(5000);
144+
}
145+
146+
it("Go on the 2nd page and change the collection name", async function () {
147+
await setupPage1();
148+
await gotoPage2();
147149

148150
await webView.findWebElement(
149151
By.xpath("//*[contains(text(), 'Review the suggested')]"),
@@ -158,5 +160,59 @@ describe("Verify Role generation reset button works as expected", function () {
158160
await getWebviewByLocator(
159161
By.xpath("//*[text()='What do you want the role to accomplish?']"),
160162
);
163+
164+
await workbenchExecuteCommand("View: Close All Editor Groups");
165+
});
166+
167+
it("Role generation (outline reset, cancel)", async function () {
168+
await setupPage1();
169+
await gotoPage2();
170+
171+
// Verify outline output and text edit
172+
let outlineList = await webView.findWebElement(
173+
By.xpath("//ol[@id='outline-list']"),
174+
);
175+
expect(outlineList, "An ordered list should exist.").to.be.not.undefined;
176+
let text = await outlineList.getText();
177+
expect(text.includes("Install the Nginx packages")).to.be.true;
178+
179+
// Test Reset button
180+
await outlineList.sendKeys("# COMMENT\n");
181+
text = await outlineList.getText();
182+
expect(text.includes("# COMMENT\n"));
183+
184+
let resetButton = await webView.findWebElement(
185+
By.xpath("//vscode-button[@id='reset-button']"),
186+
);
187+
expect(resetButton, "resetButton should not be undefined").not.to.be
188+
.undefined;
189+
expect(await resetButton.isEnabled(), "reset button should be enabled now")
190+
.to.be.true;
191+
192+
await resetButton.click();
193+
await sleep(500);
194+
195+
// Cancel reset of Outline
196+
await webView.switchBack();
197+
const resetOutlineDialog = new ModalDialog();
198+
await resetOutlineDialog.pushButton("Cancel");
199+
await sleep(250);
200+
// Sadly we need to switch context and so we must reload the WebView elements
201+
webView = await getWebviewByLocator(
202+
By.xpath("//*[text()='Create a role with Ansible Lightspeed']"),
203+
);
204+
outlineList = await webView.findWebElement(
205+
By.xpath("//ol[@id='outline-list']"),
206+
);
207+
resetButton = await webView.findWebElement(
208+
By.xpath("//vscode-button[@id='reset-button']"),
209+
);
210+
211+
text = await outlineList.getText();
212+
expect(text.includes("# COMMENT\n"));
213+
expect(await resetButton.isEnabled(), "reset button should be enabled now")
214+
.to.be.true;
215+
216+
await workbenchExecuteCommand("View: Close All Editor Groups");
161217
});
162218
});

test/ui-test/lightspeedUiTestPlaybookExpTestNoLSTest.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import { expect } from "chai";
44
import { Workbench } from "vscode-extension-tester";
5-
import { sleep, workbenchExecuteCommand } from "./uiTestHelper";
5+
import {
6+
sleep,
7+
workbenchExecuteCommand,
8+
dismissNotifications,
9+
} from "./uiTestHelper";
610

711
describe("Verify playbook generation page is not opened when Lightspeed is not enabled", function () {
812
let workbench: Workbench;
@@ -15,11 +19,7 @@ describe("Verify playbook generation page is not opened when Lightspeed is not e
1519
await sleep(3000);
1620

1721
workbench = await new Workbench();
18-
const notifications = await workbench.getNotifications();
19-
for (let i = 0; i < notifications.length; i++) {
20-
const n = notifications[i];
21-
await n.dismiss();
22-
}
22+
await dismissNotifications(workbench);
2323
});
2424

2525
it("Playbook generation command shows an error message when Lightspeed is not enabled", async function () {

0 commit comments

Comments
 (0)