|
| 1 | +import { expect, test } from '@playwright/test' |
| 2 | +import { sandboxes } from '../sandboxes' |
| 3 | +import { previewFrame } from '../utils/assertions' |
| 4 | +import { launchSandbox } from '../utils/sandboxProcess' |
| 5 | + |
| 6 | +// Skip on Windows due to path handling differences that affect Nativewind/Reanimated |
| 7 | +// TODO: Re-enable when Windows path issues are fully resolved |
| 8 | +const isWindows = process.platform === 'win32' |
| 9 | + |
| 10 | +const sandbox = sandboxes.find((entry) => entry.name === 'react-native-web') |
| 11 | + |
| 12 | +if (!sandbox) { |
| 13 | + throw new Error('Sandbox definition not found: react-native-web') |
| 14 | +} |
| 15 | + |
| 16 | +test.describe(sandbox.name, () => { |
| 17 | + test.skip(isWindows, 'Skipped on Windows due to path compatibility issues') |
| 18 | + |
| 19 | + let server: Awaited<ReturnType<typeof launchSandbox>> | null = null |
| 20 | + |
| 21 | + test.beforeAll(async () => { |
| 22 | + server = await launchSandbox(sandbox) |
| 23 | + }) |
| 24 | + |
| 25 | + test.afterAll(async () => { |
| 26 | + if (server) { |
| 27 | + await server.stop() |
| 28 | + server = null |
| 29 | + } |
| 30 | + }) |
| 31 | + |
| 32 | + test('should load the home page with Button docs', async ({ page }) => { |
| 33 | + const currentServer = server |
| 34 | + if (!currentServer) { |
| 35 | + throw new Error('Storybook server failed to start') |
| 36 | + } |
| 37 | + |
| 38 | + await page.goto(currentServer.url, { waitUntil: 'networkidle' }) |
| 39 | + |
| 40 | + const frame = previewFrame(page) |
| 41 | + const docsRoot = frame.locator('#storybook-docs:not([hidden])') |
| 42 | + await expect(docsRoot).toBeVisible() |
| 43 | + |
| 44 | + // Check that Button component docs are rendered |
| 45 | + const title = docsRoot.locator('h1') |
| 46 | + await expect(title).toBeVisible() |
| 47 | + await expect(title).toHaveText('Button') |
| 48 | + }) |
| 49 | + |
| 50 | + test('should render Button component with React Native Web primitives', async ({ |
| 51 | + page, |
| 52 | + }) => { |
| 53 | + const currentServer = server |
| 54 | + if (!currentServer) { |
| 55 | + throw new Error('Storybook server failed to start') |
| 56 | + } |
| 57 | + |
| 58 | + // Navigate to Primary story |
| 59 | + await page.goto( |
| 60 | + `${currentServer.url}?path=/story/components-button--primary`, |
| 61 | + { |
| 62 | + waitUntil: 'networkidle', |
| 63 | + }, |
| 64 | + ) |
| 65 | + |
| 66 | + const frame = previewFrame(page) |
| 67 | + |
| 68 | + // The button text should be visible |
| 69 | + // TouchableOpacity renders as a div, and Text renders as a span |
| 70 | + const buttonText = frame.getByText('Primary Button') |
| 71 | + await expect(buttonText).toBeVisible() |
| 72 | + }) |
| 73 | + |
| 74 | + test('should render Card component', async ({ page }) => { |
| 75 | + const currentServer = server |
| 76 | + if (!currentServer) { |
| 77 | + throw new Error('Storybook server failed to start') |
| 78 | + } |
| 79 | + |
| 80 | + // Navigate to Card Default story |
| 81 | + await page.goto( |
| 82 | + `${currentServer.url}?path=/story/components-card--default`, |
| 83 | + { |
| 84 | + waitUntil: 'networkidle', |
| 85 | + }, |
| 86 | + ) |
| 87 | + |
| 88 | + const frame = previewFrame(page) |
| 89 | + |
| 90 | + // Check card title is rendered |
| 91 | + const cardTitle = frame.getByText('Card Title') |
| 92 | + await expect(cardTitle).toBeVisible() |
| 93 | + |
| 94 | + // Check card content is rendered |
| 95 | + const cardContent = frame.getByText( |
| 96 | + 'This is the card content. You can put any React Native components here.', |
| 97 | + ) |
| 98 | + await expect(cardContent).toBeVisible() |
| 99 | + }) |
| 100 | + |
| 101 | + test('should show props table with docgen', async ({ page }) => { |
| 102 | + const currentServer = server |
| 103 | + if (!currentServer) { |
| 104 | + throw new Error('Storybook server failed to start') |
| 105 | + } |
| 106 | + |
| 107 | + // Navigate to Button docs |
| 108 | + await page.goto(`${currentServer.url}?path=/docs/components-button--docs`, { |
| 109 | + waitUntil: 'networkidle', |
| 110 | + }) |
| 111 | + |
| 112 | + const frame = previewFrame(page) |
| 113 | + const docsRoot = frame.locator('#storybook-docs:not([hidden])') |
| 114 | + await expect(docsRoot).toBeVisible() |
| 115 | + |
| 116 | + // Check that props table shows expected props from docgen |
| 117 | + const labelProp = docsRoot.getByText('The button label') |
| 118 | + await expect(labelProp).toBeVisible() |
| 119 | + |
| 120 | + const variantProp = docsRoot.getByText('Visual variant of the button') |
| 121 | + await expect(variantProp).toBeVisible() |
| 122 | + }) |
| 123 | + |
| 124 | + test('should render Nativewind styled components', async ({ page }) => { |
| 125 | + const currentServer = server |
| 126 | + if (!currentServer) { |
| 127 | + throw new Error('Storybook server failed to start') |
| 128 | + } |
| 129 | + |
| 130 | + // Navigate to Nativewind Showcase story |
| 131 | + await page.goto( |
| 132 | + `${currentServer.url}?path=/story/nativewind-showcase--showcase`, |
| 133 | + { |
| 134 | + waitUntil: 'networkidle', |
| 135 | + }, |
| 136 | + ) |
| 137 | + |
| 138 | + const frame = previewFrame(page) |
| 139 | + |
| 140 | + // Check that the Nativewind container is rendered |
| 141 | + const container = frame.locator('[data-testid="nativewind-container"]') |
| 142 | + await expect(container).toBeVisible() |
| 143 | + |
| 144 | + // Check that the title is rendered |
| 145 | + const title = frame.locator('[data-testid="nativewind-title"]') |
| 146 | + await expect(title).toBeVisible() |
| 147 | + await expect(title).toHaveText('Nativewind v4') |
| 148 | + |
| 149 | + // Verify Tailwind CSS styles are applied (background color from purple-500) |
| 150 | + // The gradient starts with purple-500 (#a855f7) which gets applied as background |
| 151 | + const containerStyles = await container.evaluate((el) => { |
| 152 | + const styles = window.getComputedStyle(el) |
| 153 | + return { |
| 154 | + padding: styles.padding, |
| 155 | + borderRadius: styles.borderRadius, |
| 156 | + } |
| 157 | + }) |
| 158 | + |
| 159 | + // Check that Tailwind utilities are applied (p-8 = 32px padding, rounded-3xl = 24px border-radius) |
| 160 | + expect(containerStyles.padding).toBe('32px') |
| 161 | + expect(containerStyles.borderRadius).toBe('24px') |
| 162 | + }) |
| 163 | + |
| 164 | + test('should render Reanimated animated components', async ({ page }) => { |
| 165 | + const currentServer = server |
| 166 | + if (!currentServer) { |
| 167 | + throw new Error('Storybook server failed to start') |
| 168 | + } |
| 169 | + |
| 170 | + // Navigate to Reanimated Showcase story |
| 171 | + await page.goto( |
| 172 | + `${currentServer.url}?path=/story/reanimated-animations--showcase`, |
| 173 | + { |
| 174 | + waitUntil: 'networkidle', |
| 175 | + }, |
| 176 | + ) |
| 177 | + |
| 178 | + const frame = previewFrame(page) |
| 179 | + |
| 180 | + // Check that the showcase container is rendered |
| 181 | + const showcase = frame.locator('[data-testid="reanimated-showcase"]') |
| 182 | + await expect(showcase).toBeVisible() |
| 183 | + |
| 184 | + // Check that the FadeInBox component is rendered |
| 185 | + const fadeInBox = frame.locator('[data-testid="reanimated-fade-in"]') |
| 186 | + await expect(fadeInBox).toBeVisible() |
| 187 | + |
| 188 | + // Verify the FadeInBox has expected text |
| 189 | + const fadeInText = fadeInBox.getByText('Fade In') |
| 190 | + await expect(fadeInText).toBeVisible() |
| 191 | + |
| 192 | + // Wait for animation to complete and verify opacity is applied |
| 193 | + await page.waitForTimeout(1500) // Wait for 1000ms animation + buffer |
| 194 | + |
| 195 | + const opacity = await fadeInBox.evaluate((el) => { |
| 196 | + return window.getComputedStyle(el).opacity |
| 197 | + }) |
| 198 | + |
| 199 | + // After animation completes, opacity should be 1 |
| 200 | + expect(Number.parseFloat(opacity)).toBeCloseTo(1, 1) |
| 201 | + }) |
| 202 | + |
| 203 | + test('should render Reanimated FadeIn story individually', async ({ |
| 204 | + page, |
| 205 | + }) => { |
| 206 | + const currentServer = server |
| 207 | + if (!currentServer) { |
| 208 | + throw new Error('Storybook server failed to start') |
| 209 | + } |
| 210 | + |
| 211 | + // Navigate to FadeIn story |
| 212 | + await page.goto( |
| 213 | + `${currentServer.url}?path=/story/reanimated-animations--fade-in`, |
| 214 | + { |
| 215 | + waitUntil: 'networkidle', |
| 216 | + }, |
| 217 | + ) |
| 218 | + |
| 219 | + const frame = previewFrame(page) |
| 220 | + |
| 221 | + // Check that the FadeInBox component is rendered |
| 222 | + const fadeInBox = frame.locator('[data-testid="reanimated-fade-in"]') |
| 223 | + await expect(fadeInBox).toBeVisible() |
| 224 | + |
| 225 | + // Verify the component has the correct background color (#6366f1 = indigo-500) |
| 226 | + const bgColor = await fadeInBox.evaluate((el) => { |
| 227 | + return window.getComputedStyle(el).backgroundColor |
| 228 | + }) |
| 229 | + |
| 230 | + // #6366f1 in RGB is rgb(99, 102, 241) |
| 231 | + expect(bgColor).toBe('rgb(99, 102, 241)') |
| 232 | + }) |
| 233 | +}) |
0 commit comments