|
| 1 | +import { expect, test } from "../fixtures"; |
| 2 | +import { initialPillsCount } from "@constants/pages/aiWelcomePage.constants"; |
| 3 | + |
| 4 | +test.describe("AI Chat and Iframe Communication Suite", () => { |
| 5 | + test.beforeEach(async ({ page }) => { |
| 6 | + await page.goto("/ai"); |
| 7 | + await page.waitForLoadState("networkidle"); |
| 8 | + }); |
| 9 | + |
| 10 | + test("AI landing page loads correctly with all elements", async ({ page }) => { |
| 11 | + await expect(page.getByRole("heading", { name: /Build AI Agents/i })).toBeVisible(); |
| 12 | + await expect(page.getByRole("heading", { name: /Create workflows/i })).toBeVisible(); |
| 13 | + |
| 14 | + await expect(page.getByRole("button", { name: "Start from Template" })).toBeVisible(); |
| 15 | + await expect(page.getByRole("button", { name: "New Project From Scratch" })).toBeVisible(); |
| 16 | + |
| 17 | + const textarea = page.locator('textarea[name="message"]'); |
| 18 | + await expect(textarea).toBeVisible(); |
| 19 | + }); |
| 20 | + |
| 21 | + test("Suggestion pills are visible and clickable", async ({ page }) => { |
| 22 | + const pills = page.locator("button[data-testid^='suggestion-pill-']"); |
| 23 | + await expect(pills.first()).toBeVisible(); |
| 24 | + |
| 25 | + await pills.first().click(); |
| 26 | + |
| 27 | + const textarea = page.locator('textarea[name="message"]'); |
| 28 | + await expect(textarea).toBeFocused(); |
| 29 | + }); |
| 30 | + |
| 31 | + test("More button loads additional suggestion pills", async ({ page }) => { |
| 32 | + const initialPills = page.locator("button[data-testid^='suggestion-pill-']"); |
| 33 | + const initialPillsCountActual = await initialPills.count(); |
| 34 | + expect(initialPillsCountActual).toBe(initialPillsCount); |
| 35 | + |
| 36 | + const initialPillsTitles: string[] = []; |
| 37 | + for (let i = 0; i < initialPillsCountActual; i++) { |
| 38 | + const pillText = await initialPills.nth(i).textContent(); |
| 39 | + if (pillText) { |
| 40 | + initialPillsTitles.push(pillText.trim()); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + expect(initialPillsTitles).toHaveLength(initialPillsCount); |
| 45 | + expect(initialPillsTitles.every((title) => title && title.length > 0)).toBe(true); |
| 46 | + |
| 47 | + const moreButton = page.getByRole("button", { name: "More", exact: true }); |
| 48 | + if (await moreButton.isVisible()) { |
| 49 | + await moreButton.click(); |
| 50 | + |
| 51 | + await page.waitForTimeout(300); |
| 52 | + |
| 53 | + const allVisiblePills = page.locator("button[data-testid^='suggestion-pill-']"); |
| 54 | + const allPillsCount = await allVisiblePills.count(); |
| 55 | + expect(allPillsCount).toBeGreaterThan(initialPillsCount); |
| 56 | + |
| 57 | + const allPillsTitles: string[] = []; |
| 58 | + for (let i = 0; i < allPillsCount; i++) { |
| 59 | + const pillText = await allVisiblePills.nth(i).textContent(); |
| 60 | + if (pillText) { |
| 61 | + allPillsTitles.push(pillText.trim()); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + expect(allPillsTitles).toHaveLength(allPillsCount); |
| 66 | + expect(allPillsTitles.every((title) => title && title.length > 0)).toBe(true); |
| 67 | + |
| 68 | + const initialPillsFromExpanded = allPillsTitles.slice(0, initialPillsCount); |
| 69 | + expect(initialPillsFromExpanded).toEqual(initialPillsTitles); |
| 70 | + |
| 71 | + await expect(moreButton).not.toBeVisible(); |
| 72 | + } |
| 73 | + }); |
| 74 | + |
| 75 | + test("Submit message opens AI chat modal", async ({ page }) => { |
| 76 | + const textarea = page.locator('textarea[name="message"]'); |
| 77 | + await textarea.fill("Create a GitHub webhook automation"); |
| 78 | + |
| 79 | + await page.keyboard.press("Enter"); |
| 80 | + |
| 81 | + const modal = page.locator('[class*="modal"], [role="dialog"], [data-testid="ai-chat-modal"]'); |
| 82 | + await expect(modal.first()).toBeVisible({ timeout: 10000 }); |
| 83 | + }); |
| 84 | + |
| 85 | + test("Empty message shows validation error", async ({ page }) => { |
| 86 | + const textarea = page.locator('textarea[name="message"]'); |
| 87 | + await textarea.focus(); |
| 88 | + await page.keyboard.press("Enter"); |
| 89 | + |
| 90 | + const errorMessage = page.getByText("Please enter a message"); |
| 91 | + await expect(errorMessage).toBeVisible({ timeout: 5000 }); |
| 92 | + }); |
| 93 | + |
| 94 | + test("Textarea clears validation error when typing", async ({ page }) => { |
| 95 | + const textarea = page.locator('textarea[name="message"]'); |
| 96 | + await textarea.focus(); |
| 97 | + await page.keyboard.press("Enter"); |
| 98 | + |
| 99 | + const errorMessage = page.getByText("Please enter a message"); |
| 100 | + await expect(errorMessage).toBeVisible({ timeout: 5000 }); |
| 101 | + |
| 102 | + await textarea.fill("Test message"); |
| 103 | + |
| 104 | + await expect(errorMessage).not.toBeVisible({ timeout: 3000 }); |
| 105 | + }); |
| 106 | + |
| 107 | + test("Navigation buttons work correctly", async ({ page }) => { |
| 108 | + const templateButton = page.getByRole("button", { name: "Start from Template" }); |
| 109 | + await templateButton.click(); |
| 110 | + await expect(page).toHaveURL(/templates-library/); |
| 111 | + |
| 112 | + await page.goto("/ai"); |
| 113 | + |
| 114 | + const learnMoreButton = page.getByRole("button", { name: /Learn more/i }); |
| 115 | + if (await learnMoreButton.isVisible()) { |
| 116 | + await learnMoreButton.click(); |
| 117 | + await expect(page).toHaveURL(/intro/); |
| 118 | + } |
| 119 | + }); |
| 120 | +}); |
| 121 | + |
| 122 | +test.describe("AI Chat Modal Iframe Behavior", () => { |
| 123 | + test("Modal can be closed", async ({ page }) => { |
| 124 | + await page.goto("/ai"); |
| 125 | + await page.waitForLoadState("networkidle"); |
| 126 | + |
| 127 | + const textarea = page.locator('textarea[name="message"]'); |
| 128 | + await textarea.fill("Test automation"); |
| 129 | + await page.keyboard.press("Enter"); |
| 130 | + |
| 131 | + const modal = page.locator('[class*="modal"], [role="dialog"]'); |
| 132 | + await expect(modal.first()).toBeVisible({ timeout: 10000 }); |
| 133 | + |
| 134 | + const closeButton = page.locator( |
| 135 | + '[aria-label*="close" i], [class*="close"], button:has-text("×"), button:has-text("Close")' |
| 136 | + ); |
| 137 | + if (await closeButton.first().isVisible()) { |
| 138 | + await closeButton.first().click(); |
| 139 | + await expect(modal.first()).not.toBeVisible({ timeout: 5000 }); |
| 140 | + } else { |
| 141 | + await page.keyboard.press("Escape"); |
| 142 | + await page.waitForTimeout(500); |
| 143 | + } |
| 144 | + }); |
| 145 | +}); |
0 commit comments