|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { TestHelpers } from "./utils/test-helpers"; |
| 3 | + |
| 4 | +test.describe("Homepage", () => { |
| 5 | + let testHelpers: TestHelpers; |
| 6 | + |
| 7 | + test.beforeEach(async ({ page }) => { |
| 8 | + testHelpers = new TestHelpers(page); |
| 9 | + await page.goto("/"); |
| 10 | + }); |
| 11 | + |
| 12 | + test("should display the main header and navigation", async ({ page }) => { |
| 13 | + await expect(page.getByRole("banner")).toBeVisible(); |
| 14 | + await expect( |
| 15 | + page.getByRole("heading", { name: "Component Party" }), |
| 16 | + ).toBeVisible(); |
| 17 | + }); |
| 18 | + |
| 19 | + test("should display default frameworks on first visit", async () => { |
| 20 | + // Clear localStorage to simulate first visit |
| 21 | + await testHelpers.clearFrameworkSelection(); |
| 22 | + |
| 23 | + // Wait for frameworks to load |
| 24 | + await testHelpers.waitForFrameworksToLoad(); |
| 25 | + |
| 26 | + const selectedFrameworks = await testHelpers.getSelectedFrameworks(); |
| 27 | + expect(selectedFrameworks).toContain("react"); |
| 28 | + expect(selectedFrameworks).toContain("svelte5"); |
| 29 | + }); |
| 30 | + |
| 31 | + test("should allow toggling framework selection", async ({ page }) => { |
| 32 | + // Wait for frameworks to load |
| 33 | + await testHelpers.waitForFrameworksToLoad(); |
| 34 | + |
| 35 | + // Deselect React |
| 36 | + await testHelpers.deselectFramework("react"); |
| 37 | + |
| 38 | + // Verify React is no longer selected |
| 39 | + const selectedFrameworks = await testHelpers.getSelectedFrameworks(); |
| 40 | + expect(selectedFrameworks).not.toContain("react"); |
| 41 | + |
| 42 | + // Reselect React |
| 43 | + await testHelpers.selectFramework("react"); |
| 44 | + |
| 45 | + // Wait for the selection to update |
| 46 | + await testHelpers.waitForFrameworksToLoad(); |
| 47 | + |
| 48 | + // Verify React is selected again |
| 49 | + const selectedFrameworksAfter = await testHelpers.getSelectedFrameworks(); |
| 50 | + expect(selectedFrameworksAfter).toContain("react"); |
| 51 | + }); |
| 52 | + |
| 53 | + test("should show framework selection prompt when no frameworks are selected", async ({ |
| 54 | + page, |
| 55 | + }) => { |
| 56 | + // Clear localStorage to simulate first visit |
| 57 | + await testHelpers.clearFrameworkSelection(); |
| 58 | + |
| 59 | + await testHelpers.waitForFrameworksToLoad(); |
| 60 | + |
| 61 | + // Deselect all frameworks |
| 62 | + await testHelpers.deselectAllFrameworks(); |
| 63 | + |
| 64 | + await expect(page.getByTestId("empty-state")).toBeVisible(); |
| 65 | + await expect(page.getByTestId("empty-state-message")).toContainText( |
| 66 | + "Please select a framework", |
| 67 | + ); |
| 68 | + }); |
| 69 | + |
| 70 | + test("should display content sections when frameworks are selected", async ({ |
| 71 | + page, |
| 72 | + }) => { |
| 73 | + // Wait for frameworks to be selected |
| 74 | + await testHelpers.waitForFrameworksToLoad(); |
| 75 | + |
| 76 | + // Wait for content to load |
| 77 | + await testHelpers.waitForContentToLoad(); |
| 78 | + |
| 79 | + // Check that we have content sections |
| 80 | + await expect(page.getByRole("heading", { level: 1 })).toHaveCount(7); // 6 main sections + 1 header |
| 81 | + |
| 82 | + // Check for specific sections using test IDs |
| 83 | + await expect(page.getByTestId("section-reactivity")).toBeVisible(); |
| 84 | + await expect(page.getByTestId("section-templating")).toBeVisible(); |
| 85 | + }); |
| 86 | +}); |
0 commit comments