From 8fba3e1e3dcdc0a19a58ef711ac4921c18730eef Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Wed, 27 Nov 2024 18:04:47 -0300 Subject: [PATCH] Fix: Unable to Click on Prompt in UI when It is empty and add regression test (#4904) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 📝 (sanitizedHTMLWrapper/index.tsx): Update className from "m-1" to "m-1 w-full" for better styling ✨ (generalBugs-prompt.spec.ts): Add test for user to edit an empty prompt in the application --- .../common/sanitizedHTMLWrapper/index.tsx | 2 +- .../regression/generalBugs-prompt.spec.ts | 105 ++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/frontend/tests/core/regression/generalBugs-prompt.spec.ts diff --git a/src/frontend/src/components/common/sanitizedHTMLWrapper/index.tsx b/src/frontend/src/components/common/sanitizedHTMLWrapper/index.tsx index 975028f54..4ec8e88b8 100644 --- a/src/frontend/src/components/common/sanitizedHTMLWrapper/index.tsx +++ b/src/frontend/src/components/common/sanitizedHTMLWrapper/index.tsx @@ -15,7 +15,7 @@ const SanitizedHTMLWrapper = forwardRef< dangerouslySetInnerHTML={{ __html: sanitizedHTML }} suppressContentEditableWarning={suppressWarning} {...props} - className="m-1" + className="m-1 w-full" /> ); }); diff --git a/src/frontend/tests/core/regression/generalBugs-prompt.spec.ts b/src/frontend/tests/core/regression/generalBugs-prompt.spec.ts new file mode 100644 index 000000000..48e07723b --- /dev/null +++ b/src/frontend/tests/core/regression/generalBugs-prompt.spec.ts @@ -0,0 +1,105 @@ +import { expect, test } from "@playwright/test"; +import * as dotenv from "dotenv"; +import path from "path"; + +test( + "user must be able to edit an empty prompt", + { tag: ["@release", "@starter-project"] }, + async ({ page }) => { + test.skip( + !process?.env?.OPENAI_API_KEY, + "OPENAI_API_KEY required to run this test", + ); + + if (!process.env.CI) { + dotenv.config({ path: path.resolve(__dirname, "../../.env") }); + } + + await page.goto("/"); + await page.waitForSelector('[data-testid="mainpage_title"]', { + timeout: 30000, + }); + + await page.waitForSelector('[id="new-project-btn"]', { + timeout: 30000, + }); + + let modalCount = 0; + try { + const modalTitleElement = await page?.getByTestId("modal-title"); + if (modalTitleElement) { + modalCount = await modalTitleElement.count(); + } + } catch (error) { + modalCount = 0; + } + + while (modalCount === 0) { + await page.getByText("New Flow", { exact: true }).click(); + await page.waitForSelector('[data-testid="modal-title"]', { + timeout: 3000, + }); + modalCount = await page.getByTestId("modal-title")?.count(); + } + + await page.getByTestId("side_nav_options_all-templates").click(); + await page.getByRole("heading", { name: "Basic Prompting" }).click(); + + await page.waitForSelector('[data-testid="fit_view"]', { + timeout: 100000, + }); + + await page.getByTestId("fit_view").click(); + + let outdatedComponents = await page + .getByTestId("icon-AlertTriangle") + .count(); + + while (outdatedComponents > 0) { + await page.getByTestId("icon-AlertTriangle").first().click(); + outdatedComponents = await page.getByTestId("icon-AlertTriangle").count(); + } + + await page.getByTestId("promptarea_prompt_template").click(); + + await page.keyboard.press(`ControlOrMeta+a`); + await page.keyboard.press("Backspace"); + + await page.getByText("Edit Prompt", { exact: true }).click(); + + await page.getByTestId("edit-prompt-sanitized").click(); + + await page + .getByTestId("modal-promptarea_prompt_template") + .fill("THIS IS A TEST"); + + await page.getByText("Edit Prompt", { exact: true }).click(); + + let promptSanitizedText = await page + .getByTestId("edit-prompt-sanitized") + .textContent(); + + expect(promptSanitizedText).toBe("THIS IS A TEST"); + + await page.getByTestId("edit-prompt-sanitized").click(); + + await page.keyboard.press(`ControlOrMeta+a`); + await page.keyboard.press("Backspace"); + + await page.getByText("Edit Prompt", { exact: true }).click(); + + await page.getByTestId("edit-prompt-sanitized").click(); + + await page + .getByTestId("modal-promptarea_prompt_template") + .fill("THIS IS A TEST 2"); + + await page.getByText("Edit Prompt", { exact: true }).click(); + + promptSanitizedText = await page + .getByTestId("edit-prompt-sanitized") + .textContent(); + + expect(promptSanitizedText).toBe("THIS IS A TEST 2"); + }, +);