langflow/src/frontend/tests/core/features/componentHoverAdd.spec.ts
Cristhian Zanforlin Lousa ab68e13493
test: Add utility functions to streamline test setup and improve maintainability (#5168)
* change tests to use utils libs

* 🔧 (frontend): add data-testid attribute to buttons in baseModal and secretKeyModal components
🔧 (frontend): add data-testid attribute to buttons in various test files for improved testing
🔧 (frontend): refactor awaitBootstrapTest function to remove skipNewFlow option and improve modal handling

*  (userSettings.spec.ts): add a 1-second timeout before checking for the "Please save" text to ensure it is rendered on the page before interacting with it

*  (userSettings.spec.ts): add comment to clarify waiting for API key creation to complete before proceeding to the next form element

*  (freeze-path.spec.ts): refactor adjustScreenView function to accept a parameter for the number of zoom outs to perform, improving flexibility and reusability in test scenarios.
🔧 (freeze-path.spec.ts): replace adjustScreenView function with initialGPTsetup function for setting up initial GPT configuration in the test scenario.
2024-12-09 20:30:56 +00:00

60 lines
2 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { awaitBootstrapTest } from "../../utils/await-bootstrap-test";
test(
"user can add components by hovering and clicking the plus icon",
{ tag: ["@release", "@components", "@workspace"] },
async ({ page }) => {
// Navigate to homepage and handle initial modal
await awaitBootstrapTest(page);
// Start with blank flow
await page.getByTestId("blank-flow").click();
await page.waitForSelector('[data-testid="sidebar-search-input"]', {
timeout: 3000,
});
// Search for a component
await page.getByTestId("sidebar-search-input").click();
await page.getByTestId("sidebar-search-input").fill("chat input");
await page.waitForSelector('[data-testid="inputsChat Input"]', {
timeout: 2000,
});
// Hover over the component and verify plus icon
const componentLocator = page.getByTestId("inputsChat Input");
// Find the plus icon within the specific component container
const plusIcon = componentLocator.getByTestId("icon-Plus");
// Get the opacity
const opacity = await plusIcon.evaluate((el) =>
window.getComputedStyle(el).getPropertyValue("opacity"),
);
await expect(plusIcon).toBeVisible();
await expect(opacity).toBe("0");
await componentLocator.hover();
// Hover over the component
await expect(plusIcon).toBeVisible();
// Wait for the animation to change the opacity
await page.waitForTimeout(500);
const opacityAfterHover = await plusIcon.evaluate((el) =>
window.getComputedStyle(el).getPropertyValue("opacity"),
);
expect(Number(opacityAfterHover)).toBeGreaterThan(0);
// Click the plus icon associated with this component
await plusIcon.click();
// Wait for the component to be added to the flow
await page.waitForSelector(".react-flow__node", { timeout: 1000 });
// Verify component was added to the flow
const addedComponent = page.locator(".react-flow__node").first();
await expect(addedComponent).toBeVisible();
},
);