|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +const DECISION_JAR_FEATURES = [ |
| 4 | + "Shake-to-decide or tap for random selection from custom jars", |
| 5 | + "AI-powered suggestions to expand your options (up to 50/day on Premium)", |
| 6 | + "Decision history tracking to identify choice patterns", |
| 7 | + "QR code sharing for instant jar importing with friends", |
| 8 | +]; |
| 9 | + |
| 10 | +const SOBERS_FEATURES = [ |
| 11 | + "Secure sponsor-sponsee pairing with invite code system", |
| 12 | + "Sobriety timeline with transparent relapse tracking", |
| 13 | + "Task management with sponsor assignment and sponsee completion notes", |
| 14 | + "Visual journey timeline displaying milestones, tasks, and step progress", |
| 15 | +]; |
| 16 | + |
| 17 | +const VOLVOX_BOT_FEATURES = [ |
| 18 | + "AI chat for context-aware Discord replies", |
| 19 | + "AI auto-moderation with configurable thresholds and actions", |
| 20 | + "Reputation and XP tracking with role rewards", |
| 21 | + "Long-term user memory for personalized interactions", |
| 22 | +]; |
| 23 | + |
| 24 | +const HOMEPAGE_FEATURES = [ |
| 25 | + ...DECISION_JAR_FEATURES, |
| 26 | + ...SOBERS_FEATURES, |
| 27 | + ...VOLVOX_BOT_FEATURES, |
| 28 | +]; |
| 29 | + |
| 30 | +type FeatureRenderState = { |
| 31 | + clientWidth: number; |
| 32 | + isHorizontallyClipped: boolean; |
| 33 | + isMissing: boolean; |
| 34 | + overflow: string; |
| 35 | + scrollWidth: number; |
| 36 | + text: string; |
| 37 | + textOverflow: string; |
| 38 | + whiteSpace: string; |
| 39 | +}; |
| 40 | + |
| 41 | +test("homepage product feature previews show their full text", async ({ |
| 42 | + page, |
| 43 | +}) => { |
| 44 | + await page.setViewportSize({ width: 680, height: 743 }); |
| 45 | + await page.goto("/"); |
| 46 | + |
| 47 | + const renderStates = await page.evaluate((featureTexts) => { |
| 48 | + const productSection = document.querySelector("#products"); |
| 49 | + if (!productSection) { |
| 50 | + throw new Error("Products section was not rendered"); |
| 51 | + } |
| 52 | + |
| 53 | + return featureTexts.map((text): FeatureRenderState => { |
| 54 | + const featureElement = Array.from( |
| 55 | + productSection.querySelectorAll("span"), |
| 56 | + ).find((element) => element.textContent?.trim() === text); |
| 57 | + |
| 58 | + if (!featureElement) { |
| 59 | + return { |
| 60 | + clientWidth: 0, |
| 61 | + isHorizontallyClipped: false, |
| 62 | + isMissing: true, |
| 63 | + overflow: "", |
| 64 | + scrollWidth: 0, |
| 65 | + text, |
| 66 | + textOverflow: "", |
| 67 | + whiteSpace: "", |
| 68 | + }; |
| 69 | + } |
| 70 | + |
| 71 | + const computedStyle = window.getComputedStyle(featureElement); |
| 72 | + |
| 73 | + return { |
| 74 | + clientWidth: featureElement.clientWidth, |
| 75 | + isHorizontallyClipped: |
| 76 | + featureElement.scrollWidth > featureElement.clientWidth, |
| 77 | + isMissing: false, |
| 78 | + overflow: computedStyle.overflow, |
| 79 | + scrollWidth: featureElement.scrollWidth, |
| 80 | + text, |
| 81 | + textOverflow: computedStyle.textOverflow, |
| 82 | + whiteSpace: computedStyle.whiteSpace, |
| 83 | + }; |
| 84 | + }); |
| 85 | + }, HOMEPAGE_FEATURES); |
| 86 | + |
| 87 | + expect(renderStates).toEqual( |
| 88 | + expect.arrayContaining( |
| 89 | + HOMEPAGE_FEATURES.map((text) => |
| 90 | + expect.objectContaining({ |
| 91 | + isHorizontallyClipped: false, |
| 92 | + isMissing: false, |
| 93 | + overflow: "visible", |
| 94 | + text, |
| 95 | + textOverflow: "clip", |
| 96 | + whiteSpace: "normal", |
| 97 | + }), |
| 98 | + ), |
| 99 | + ), |
| 100 | + ); |
| 101 | +}); |
0 commit comments