Skip to content

Commit c3d5259

Browse files
chore: stabilize tests (#7185)
1 parent c5ad329 commit c3d5259

File tree

2 files changed

+57
-46
lines changed

2 files changed

+57
-46
lines changed

e2e/react-start/rsc/src/routes/rsc-ssr-false.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ function RscSsrFalseComponent() {
298298

299299
const canvasRef = React.useRef<HTMLCanvasElement>(null)
300300
const hasMounted = React.useRef(false)
301+
const isDrawingRef = React.useRef(false)
301302
const [isDrawing, setIsDrawing] = React.useState(false)
302303
const [brushSize, setBrushSize] = React.useState(tools.brushSizes[1])
303304
// Initialize color from localStorage if available, otherwise use default
@@ -362,6 +363,7 @@ function RscSsrFalseComponent() {
362363
const canvas = canvasRef.current
363364
if (!canvas) return
364365

366+
isDrawingRef.current = true
365367
setIsDrawing(true)
366368
const rect = canvas.getBoundingClientRect()
367369
const ctx = canvas.getContext('2d')
@@ -372,7 +374,7 @@ function RscSsrFalseComponent() {
372374
}
373375

374376
const draw = (e: React.MouseEvent<HTMLCanvasElement>) => {
375-
if (!isDrawing) return
377+
if (!isDrawingRef.current) return
376378

377379
const canvas = canvasRef.current
378380
if (!canvas) return
@@ -389,7 +391,8 @@ function RscSsrFalseComponent() {
389391
}
390392

391393
const stopDrawing = () => {
392-
if (isDrawing) {
394+
if (isDrawingRef.current) {
395+
isDrawingRef.current = false
393396
setStrokeCount((c) => {
394397
const newCount = c + 1
395398
// Save stroke count to localStorage

e2e/react-start/rsc/tests/rsc-ssr-false.spec.ts

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { expect } from '@playwright/test'
22
import { 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
611
test.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

Comments
 (0)