Skip to content

Commit

Permalink
Disable explanation thumbs up and thumbs down buttons after selection (
Browse files Browse the repository at this point in the history
  • Loading branch information
mabashian authored Dec 9, 2024
1 parent 9935973 commit 8eedb08
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/webview/apps/lightspeed/playbookExplanation/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function sendThumbsup() {
"thumbsdown-button",
) as Button;
thumbsUpButton.setAttribute("class", "iconButtonSelected");
thumbsUpButton.setAttribute("disabled", "true");
thumbsDownButton.setAttribute("class", "iconButton");
thumbsDownButton.setAttribute("disabled", "true");
vscode.postMessage({
command: "thumbsUp",
action: ThumbsUpDownAction.UP,
Expand All @@ -51,7 +53,9 @@ function sendThumbsdown() {
"thumbsdown-button",
) as Button;
thumbsUpButton.setAttribute("class", "iconButton");
thumbsUpButton.setAttribute("disabled", "true");
thumbsDownButton.setAttribute("class", "iconButtonSelected");
thumbsDownButton.setAttribute("disabled", "true");
vscode.postMessage({
command: "thumbsDown",
action: ThumbsUpDownAction.DOWN,
Expand Down
72 changes: 72 additions & 0 deletions test/ui-test/lightspeedUiTestPlaybookExpTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,64 @@ import {

config.truncateThreshold = 0;

async function testThumbsButtonInteraction(buttonToClick: string) {
const folder = "lightspeed";
const filePath = getFixturePath(folder, "playbook_1.yml");

// Open file in the editor
await VSBrowser.instance.openResources(filePath);

// Open playbook explanation webview.
await workbenchExecuteCommand("Explain the playbook with Ansible Lightspeed");
await sleep(2000);

await new EditorView().openEditor("Explanation", 1);
// Locate the playbook explanation webview
const webView = await getWebviewByLocator(
By.xpath("//div[contains(@class, 'playbookGeneration') ]"),
);
const thumbsUpButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='thumbsup-button']"),
);
expect(thumbsUpButton, "thumbsUpButton should not be undefined").not.to.be
.undefined;

const thumbsDownButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='thumbsdown-button']"),
);
expect(thumbsDownButton, "thumbsDownButton should not be undefined").not.to.be
.undefined;

expect(
await thumbsUpButton.isEnabled(),
`Thumbs up button should be enabled now`,
).to.be.true;

expect(
await thumbsDownButton.isEnabled(),
`Thumbs down button should be enabled now`,
).to.be.true;

const button =
buttonToClick === "thumbsup" ? thumbsUpButton : thumbsDownButton;
await button.click();

await sleep(2000);

expect(
await thumbsUpButton.getAttribute("disabled"),
"Thumbs up button should be disabled now",
).equals("true");

expect(
await thumbsDownButton.getAttribute("disabled"),
"Thumbs down button should be disabled now",
).equals("true");

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

describe("Verify playbook explanation features work as expected", function () {
beforeEach(function () {
if (!process.env.TEST_LIGHTSPEED_URL) {
Expand Down Expand Up @@ -56,6 +114,20 @@ describe("Verify playbook explanation features work as expected", function () {
await webView.switchBack();
await workbenchExecuteCommand("View: Close All Editor Groups");
});

it("Playbook explanation thumbs up/down button disabled after thumbs up", async function () {
if (!process.env.TEST_LIGHTSPEED_URL) {
this.skip();
}
await testThumbsButtonInteraction("thumbsup");
});

it("Playbook explanation thumbs up/down button disabled after thumbs down", async function () {
if (!process.env.TEST_LIGHTSPEED_URL) {
this.skip();
}
await testThumbsButtonInteraction("thumbsdown");
});
});

describe("Feedback webview provider works as expected", function () {
Expand Down

0 comments on commit 8eedb08

Please sign in to comment.