Skip to content

Commit

Permalink
AAP-34643: Add "Are you sure?" Confirmation for Reset Button (#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
manstis authored Dec 5, 2024
1 parent c469ea4 commit 2652d1d
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 75 deletions.
19 changes: 19 additions & 0 deletions src/features/lightspeed/playbookGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,25 @@ export async function showPlaybookGenerationPage(extensionUri: vscode.Uri) {
panel.dispose();
break;
}
case "resetOutline": {
vscode.window
.showInformationMessage(
"Are you sure?",
{
modal: true,
detail: "Resetting the outline will loose your changes.",
},
"Ok",
)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.then((value: any) => {
if (value === "Ok") {
panel.webview.postMessage({
command: "resetOutline",
});
}
});
}
}
});

Expand Down
19 changes: 19 additions & 0 deletions src/features/lightspeed/roleGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,25 @@ export async function showRoleGenerationPage(extensionUri: vscode.Uri) {
panel.dispose();
break;
}
case "resetOutline": {
vscode.window
.showInformationMessage(
"Are you sure?",
{
modal: true,
detail: "Resetting the outline will loose your changes.",
},
"Ok",
)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.then((value: any) => {
if (value === "Ok") {
panel.webview.postMessage({
command: "resetOutline",
});
}
});
}
}
});

Expand Down
10 changes: 8 additions & 2 deletions src/webview/apps/lightspeed/playbookGeneration/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ window.addEventListener("message", async (event) => {
}
break;
}
case "resetOutline": {
setButtonEnabled("reset-button", false);
outline.reset();
outline.focus();
}
}
});

Expand Down Expand Up @@ -179,8 +184,9 @@ async function submitInput() {
}

function reset() {
outline.reset();
outline.focus();
vscode.postMessage({
command: "resetOutline",
});
}

function backToPage1() {
Expand Down
10 changes: 8 additions & 2 deletions src/webview/apps/lightspeed/roleGeneration/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ window.addEventListener("message", async (event) => {
}
break;
}
case "resetOutline": {
setButtonEnabled("reset-button", false);
outline.reset();
outline.focus();
}
}
});

Expand Down Expand Up @@ -225,8 +230,9 @@ async function submitInput() {
}

function reset() {
outline.reset();
outline.focus();
vscode.postMessage({
command: "resetOutline",
});
}

function backToPage1() {
Expand Down
90 changes: 73 additions & 17 deletions test/ui-test/lightspeedRoleGenTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import {
EditorView,
ModalDialog,
until,
WebView,
} from "vscode-extension-tester";
import {
sleep,
getWebviewByLocator,
workbenchExecuteCommand,
dismissNotifications,
} from "./uiTestHelper";

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

const notifications = await workbench.getNotifications();
for (let i = 0; i < notifications.length; i++) {
const n = notifications[i];
await n.dismiss();
}
await dismissNotifications(workbench);
});

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

describe("Verify Role generation reset button works as expected", function () {
let webView: WebView;

before(function () {
if (!process.env.TEST_LIGHTSPEED_URL) {
this.skip();
}
});

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

const notifications = await workbench.getNotifications();
for (let i = 0; i < notifications.length; i++) {
const n = notifications[i];
await n.dismiss();
}
await dismissNotifications(workbench);

await workbenchExecuteCommand("Ansible Lightspeed: Role generation");
await sleep(500);
const webView = await getWebviewByLocator(
webView = await getWebviewByLocator(
By.xpath("//*[text()='Create a role with Ansible Lightspeed']"),
);
const textArea = await webView.findWebElement(
By.xpath("//vscode-text-area"),
);
await textArea.sendKeys("Install and configure Nginx");
}

(
await webView.findWebElement(
By.xpath("//vscode-button[@id='submit-button']"),
)
).click();
async function gotoPage2() {
const submitButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='submit-button']"),
);
await submitButton.click();
await sleep(5000);
}

it("Go on the 2nd page and change the collection name", async function () {
await setupPage1();
await gotoPage2();

await webView.findWebElement(
By.xpath("//*[contains(text(), 'Review the suggested')]"),
Expand All @@ -158,5 +160,59 @@ describe("Verify Role generation reset button works as expected", function () {
await getWebviewByLocator(
By.xpath("//*[text()='What do you want the role to accomplish?']"),
);

await workbenchExecuteCommand("View: Close All Editor Groups");
});

it("Role generation (outline reset, cancel)", async function () {
await setupPage1();
await gotoPage2();

// Verify outline output and text edit
let outlineList = await webView.findWebElement(
By.xpath("//ol[@id='outline-list']"),
);
expect(outlineList, "An ordered list should exist.").to.be.not.undefined;
let text = await outlineList.getText();
expect(text.includes("Install the Nginx packages")).to.be.true;

// Test Reset button
await outlineList.sendKeys("# COMMENT\n");
text = await outlineList.getText();
expect(text.includes("# COMMENT\n"));

let resetButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='reset-button']"),
);
expect(resetButton, "resetButton should not be undefined").not.to.be
.undefined;
expect(await resetButton.isEnabled(), "reset button should be enabled now")
.to.be.true;

await resetButton.click();
await sleep(500);

// Cancel reset of Outline
await webView.switchBack();
const resetOutlineDialog = new ModalDialog();
await resetOutlineDialog.pushButton("Cancel");
await sleep(250);
// Sadly we need to switch context and so we must reload the WebView elements
webView = await getWebviewByLocator(
By.xpath("//*[text()='Create a role with Ansible Lightspeed']"),
);
outlineList = await webView.findWebElement(
By.xpath("//ol[@id='outline-list']"),
);
resetButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='reset-button']"),
);

text = await outlineList.getText();
expect(text.includes("# COMMENT\n"));
expect(await resetButton.isEnabled(), "reset button should be enabled now")
.to.be.true;

await workbenchExecuteCommand("View: Close All Editor Groups");
});
});
12 changes: 6 additions & 6 deletions test/ui-test/lightspeedUiTestPlaybookExpTestNoLSTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import { expect } from "chai";
import { Workbench } from "vscode-extension-tester";
import { sleep, workbenchExecuteCommand } from "./uiTestHelper";
import {
sleep,
workbenchExecuteCommand,
dismissNotifications,
} from "./uiTestHelper";

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

workbench = await new Workbench();
const notifications = await workbench.getNotifications();
for (let i = 0; i < notifications.length; i++) {
const n = notifications[i];
await n.dismiss();
}
await dismissNotifications(workbench);
});

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

0 comments on commit 2652d1d

Please sign in to comment.