Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

transition.spec.ts

102 lines2.6 KB

1import { expect, test } from '@playwright/test'
2​
3test('transitions/count/create-resource should keep old values visible during navigation', async ({
4 page,
5}) => {
6 const burstClicks = async (count: number) => {
7 await page
8 .getByTestId('increase-button')
9 .evaluate((element, clickCount) => {
10 for (let index = 0; index < clickCount; index++) {
11 ;(element as HTMLAnchorElement).click()
12 }
13 }, count)
14 }
15​
16 await page.goto('/transition/count/create-resource')
17​
18 await expect(page.getByTestId('n-value')).toContainText('n: 1')
19 await expect(page.getByTestId('double-value')).toContainText('double: 2')
20​
21 const bodyTexts: Array<string> = []
22​
23 const pollInterval = setInterval(async () => {
24 const text = await page
25 .locator('body')
26 .textContent()
27 .catch(() => '')
28 if (text) bodyTexts.push(text)
29 }, 50)
30​
31 // 1 click
32​
33 await burstClicks(1)
34​
35 await expect(page.getByTestId('n-value')).toContainText('n: 1', {
36 timeout: 2_000,
37 })
38 await expect(page.getByTestId('double-value')).toContainText('double: 2', {
39 timeout: 2_000,
40 })
41​
42 await page.waitForTimeout(200)
43​
44 await expect(page.getByTestId('n-value')).toContainText('n: 2', {
45 timeout: 2000,
46 })
47 await expect(page.getByTestId('double-value')).toContainText('double: 4', {
48 timeout: 2000,
49 })
50​
51 // 2 clicks
52​
53 await burstClicks(2)
54​
55 await expect(page.getByTestId('n-value')).toContainText('n: 2', {
56 timeout: 2000,
57 })
58 await expect(page.getByTestId('double-value')).toContainText('double: 4', {
59 timeout: 2000,
60 })
61​
62 await page.waitForTimeout(200)
63​
64 await expect(page.getByTestId('n-value')).toContainText('n: 4', {
65 timeout: 2000,
66 })
67 await expect(page.getByTestId('double-value')).toContainText('double: 8', {
68 timeout: 2000,
69 })
70​
71 // 3 clicks
72​
73 await burstClicks(3)
74​
75 await expect(page.getByTestId('n-value')).toContainText('n: 4', {
76 timeout: 2000,
77 })
78 await expect(page.getByTestId('double-value')).toContainText('double: 8', {
79 timeout: 2000,
80 })
81​
82 await page.waitForTimeout(200)
83​
84 await expect(page.getByTestId('n-value')).toContainText('n: 7', {
85 timeout: 2000,
86 })
87 await expect(page.getByTestId('double-value')).toContainText('double: 14', {
88 timeout: 2000,
89 })
90​
91 clearInterval(pollInterval)
92​
93 // With proper transitions, old values should remain visible until new ones arrive
94 const hasLoadingText = bodyTexts.some((text) => text.includes('Loading...'))
95​
96 if (hasLoadingText) {
97 throw new Error(
98 'FAILED: "Loading..." appeared during navigation. ' +
99 'Solid Router should use transitions to keep old values visible.',
100 )
101 }
102})