11import { expect } from '@playwright/test'
22import { test } from '@tanstack/router-e2e-utils'
33
4+ type Point = {
5+ x : number
6+ y : number
7+ }
8+
49// This warning can occur during rapid navigation/hydration cycles and doesn't affect functionality
510// It's a React development mode warning about async state updates during mounting
611test . use ( {
@@ -20,6 +25,31 @@ test.describe('RSC SSR False Tests - Both loader and component on client', () =>
2025 } )
2126 }
2227
28+ async function drawStroke ( page : any , start : Point , end : Point ) {
29+ await page . getByTestId ( 'drawing-canvas' ) . evaluate (
30+ (
31+ canvas : HTMLCanvasElement ,
32+ { start, end } : { start : Point ; end : Point } ,
33+ ) => {
34+ const rect = canvas . getBoundingClientRect ( )
35+
36+ const createMouseEvent = ( type : string , point : Point ) =>
37+ new MouseEvent ( type , {
38+ bubbles : true ,
39+ cancelable : true ,
40+ clientX : rect . left + point . x ,
41+ clientY : rect . top + point . y ,
42+ } )
43+
44+ canvas . dispatchEvent ( createMouseEvent ( 'mousedown' , start ) )
45+ canvas . dispatchEvent ( createMouseEvent ( 'mousemove' , start ) )
46+ canvas . dispatchEvent ( createMouseEvent ( 'mousemove' , end ) )
47+ canvas . dispatchEvent ( createMouseEvent ( 'mouseup' , end ) )
48+ } ,
49+ { start, end } ,
50+ )
51+ }
52+
2353 test ( 'Page renders with RSC content after initial client load' , async ( {
2454 page,
2555 } ) => {
@@ -117,33 +147,21 @@ test.describe('RSC SSR False Tests - Both loader and component on client', () =>
117147
118148 await expect ( page . getByTestId ( 'canvas-container' ) ) . toBeVisible ( )
119149
120- const canvas = page . getByTestId ( 'drawing-canvas' )
121- const box = await canvas . boundingBox ( )
122- expect ( box ) . not . toBeNull ( )
123-
124150 // Draw a stroke
125- await page . mouse . move ( box ! . x + 50 , box ! . y + 50 )
126- await page . mouse . down ( )
127- await page . mouse . move ( box ! . x + 150 , box ! . y + 100 )
128- await page . mouse . up ( )
151+ await drawStroke ( page , { x : 50 , y : 50 } , { x : 150 , y : 100 } )
129152
130153 // Verify stroke count increased
131- const containerText = await page
132- . getByTestId ( 'canvas-container' )
133- . textContent ( )
134- expect ( containerText ) . toContain ( 'Strokes: 1' )
154+ await expect ( page . getByTestId ( 'canvas-container' ) ) . toContainText (
155+ 'Strokes: 1' ,
156+ )
135157
136158 // Draw another stroke
137- await page . mouse . move ( box ! . x + 100 , box ! . y + 30 )
138- await page . mouse . down ( )
139- await page . mouse . move ( box ! . x + 200 , box ! . y + 80 )
140- await page . mouse . up ( )
159+ await drawStroke ( page , { x : 100 , y : 30 } , { x : 200 , y : 80 } )
141160
142161 // Verify stroke count increased again
143- const containerText2 = await page
144- . getByTestId ( 'canvas-container' )
145- . textContent ( )
146- expect ( containerText2 ) . toContain ( 'Strokes: 2' )
162+ await expect ( page . getByTestId ( 'canvas-container' ) ) . toContainText (
163+ 'Strokes: 2' ,
164+ )
147165 } )
148166
149167 test ( 'Clear canvas button works' , async ( { page } ) => {
@@ -153,26 +171,21 @@ test.describe('RSC SSR False Tests - Both loader and component on client', () =>
153171
154172 await expect ( page . getByTestId ( 'canvas-container' ) ) . toBeVisible ( )
155173
156- const canvas = page . getByTestId ( 'drawing-canvas' )
157- const box = await canvas . boundingBox ( )
158- expect ( box ) . not . toBeNull ( )
159-
160174 // Draw a stroke
161- await page . mouse . move ( box ! . x + 50 , box ! . y + 50 )
162- await page . mouse . down ( )
163- await page . mouse . move ( box ! . x + 150 , box ! . y + 100 )
164- await page . mouse . up ( )
175+ await drawStroke ( page , { x : 50 , y : 50 } , { x : 150 , y : 100 } )
165176
166177 // Verify stroke was recorded
167- let containerText = await page . getByTestId ( 'canvas-container' ) . textContent ( )
168- expect ( containerText ) . toContain ( 'Strokes: 1' )
178+ await expect ( page . getByTestId ( 'canvas-container' ) ) . toContainText (
179+ 'Strokes: 1' ,
180+ )
169181
170182 // Clear canvas
171183 await page . getByTestId ( 'clear-canvas-btn' ) . click ( )
172184
173185 // Verify stroke count reset
174- containerText = await page . getByTestId ( 'canvas-container' ) . textContent ( )
175- expect ( containerText ) . toContain ( 'Strokes: 0' )
186+ await expect ( page . getByTestId ( 'canvas-container' ) ) . toContainText (
187+ 'Strokes: 0' ,
188+ )
176189 } )
177190
178191 test ( 'Save controls are visible and functional' , async ( { page } ) => {
@@ -313,18 +326,12 @@ test.describe('RSC SSR False Tests - Both loader and component on client', () =>
313326 await page . getByTestId ( 'clear-canvas-btn' ) . click ( )
314327
315328 // Draw something
316- const canvas = page . getByTestId ( 'drawing-canvas' )
317- const box = await canvas . boundingBox ( )
318- expect ( box ) . not . toBeNull ( )
319-
320- await page . mouse . move ( box ! . x + 50 , box ! . y + 50 )
321- await page . mouse . down ( )
322- await page . mouse . move ( box ! . x + 150 , box ! . y + 100 )
323- await page . mouse . up ( )
329+ await drawStroke ( page , { x : 50 , y : 50 } , { x : 150 , y : 100 } )
324330
325331 // Verify stroke was counted
326- let containerText = await page . getByTestId ( 'canvas-container' ) . textContent ( )
327- expect ( containerText ) . toContain ( 'Strokes: 1' )
332+ await expect ( page . getByTestId ( 'canvas-container' ) ) . toContainText (
333+ 'Strokes: 1' ,
334+ )
328335
329336 // Reload page
330337 await page . reload ( )
@@ -340,7 +347,8 @@ test.describe('RSC SSR False Tests - Both loader and component on client', () =>
340347 )
341348
342349 // Verify stroke count was also restored
343- containerText = await page . getByTestId ( 'canvas-container' ) . textContent ( )
344- expect ( containerText ) . toContain ( 'Strokes: 1' )
350+ await expect ( page . getByTestId ( 'canvas-container' ) ) . toContainText (
351+ 'Strokes: 1' ,
352+ )
345353 } )
346354} )
0 commit comments