Skip to content

Commit

Permalink
AAP-34643: Add "Are you sure?" Confirmation for Reset Button (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
manstis authored Dec 3, 2024
1 parent 931b0a2 commit 9c07e17
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/features/lightspeed/playbookGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,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
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
102 changes: 101 additions & 1 deletion test/ui-test/lightspeedUiTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export function lightspeedUIAssetsTest(): void {
let outlineList: WebElement;
let resetButton: WebElement;
let adtView: ViewSection;
let webView: WebView;
let webviewView: InstanceType<typeof WebviewView>;

before(async function () {
Expand Down Expand Up @@ -198,6 +199,23 @@ export function lightspeedUIAssetsTest(): void {
}
});

async function handleResetOutlineDialog(title: string = "Ok") {
await webView.switchBack();
const resetOutlineDialog = new ModalDialog();
await resetOutlineDialog.pushButton(title);
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 playbook with Ansible Lightspeed']"),
);
outlineList = await webView.findWebElement(
By.xpath("//ol[@id='outline-list']"),
);
resetButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='reset-button']"),
);
}

it("Playbook generation webview works as expected (full path) - part 1", async function () {
// Open Ansible Development Tools by clicking the Getting started button on the side bar
const view = (await new ActivityBar().getViewControl(
Expand Down Expand Up @@ -246,7 +264,7 @@ export function lightspeedUIAssetsTest(): void {
await sleep(2000);

// Start operations on Playbook Generation UI
const webView = await getWebviewByLocator(
webView = await getWebviewByLocator(
By.xpath("//*[text()='Create a playbook with Ansible Lightspeed']"),
);

Expand Down Expand Up @@ -300,6 +318,10 @@ export function lightspeedUIAssetsTest(): void {
.undefined;
await resetButton.click();
await sleep(500);

// Confirm reset of Outline
await handleResetOutlineDialog();

text = await outlineList.getText();
expect(!text.includes("# COMMENT\n"));

Expand Down Expand Up @@ -362,6 +384,10 @@ export function lightspeedUIAssetsTest(): void {
// Click reset button and make sure the string "(status=400)" is removed
await resetButton.click();
await sleep(500);

// Confirm reset of Outline
await handleResetOutlineDialog();

text = await outlineList.getText();
expect(!text.includes("(status=400)"));

Expand Down Expand Up @@ -578,6 +604,80 @@ export function lightspeedUIAssetsTest(): void {
}
});

it("Playbook generation (outline reset)", async function () {
// Execute only when TEST_LIGHTSPEED_URL environment variable is defined.
if (!process.env.TEST_LIGHTSPEED_URL) {
this.skip();
}

// Open playbook generation webview.
await workbenchExecuteCommand("Ansible Lightspeed: Playbook generation");
await sleep(2000);
const webView = await getWebviewByLocator(
By.xpath("//*[text()='Create a playbook with Ansible Lightspeed']"),
);

// Set input text and invoke summaries API
const textArea = await webView.findWebElement(
By.xpath("//vscode-text-area"),
);
expect(textArea, "textArea should not be undefined").not.to.be.undefined;
const submitButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='submit-button']"),
);
expect(submitButton, "submitButton should not be undefined").not.to.be
.undefined;
//
// Note: Following line should succeed, but fails for some unknown reasons.
//
// expect((await submitButton.isEnabled()), "submit button should be disabled by default").is.false;
await textArea.sendKeys("Create an azure network.");
expect(
await submitButton.isEnabled(),
"submit button should be enabled now",
).to.be.true;
await submitButton.click();
await sleep(1000);

// Verify outline output and text edit
const 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("Create virtual network peering")).to.be.true;

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

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(),
"submit button should be enabled now",
).to.be.true;

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

// Cancel reset of Outline
await handleResetOutlineDialog("Cancel");

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

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

it("Playbook generation webview works as expected (feature unavailable)", async function () {
// Execute only when TEST_LIGHTSPEED_URL environment variable is defined.
if (!process.env.TEST_LIGHTSPEED_URL) {
Expand Down

0 comments on commit 9c07e17

Please sign in to comment.