Open History to see the last commit
1import { expect } from '@playwright/test'
2import { test } from '@tanstack/router-e2e-utils'
3import { isSpaMode } from './utils/isSpaMode'
4β
5test.use({
6 whitelistErrors: [
7 /Failed to load resource: the server responded with a status of 404/,
8 ],
9})
10test.describe('Unicode route rendering', () => {
11 test.beforeEach(async ({ page }) => {
12 await page.goto('/specialChars')
13 })
14β
15 test('should render non-latin route correctly with direct navigation', async ({
16 page,
17 baseURL,
18 }) => {
19 await page.goto('/specialChars/λνλ―Όκ΅')
20 await page.waitForURL(
21 `${baseURL}/specialChars/%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD`,
22 )
23β
24 await expect(page.getByTestId('special-non-latin-heading')).toBeInViewport()
25 })
26β
27 test('should render non-latin route correctly during router navigation', async ({
28 page,
29 baseURL,
30 }) => {
31 const nonLatinLink = page.getByTestId('special-non-latin-link')
32β
33 await nonLatinLink.click()
34 await page.waitForURL(
35 `${baseURL}/specialChars/%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD`,
36 )
37β
38 await expect(page.getByTestId('special-non-latin-heading')).toBeInViewport()
39 })
40β
41 test.describe('Special characters in path params', () => {
42 test('should render route correctly on direct navigation', async ({
43 page,
44 baseURL,
45 }) => {
46 await page.goto('/specialChars/λ|')
47 await page.waitForURL(`${baseURL}/specialChars/%EB%8C%80%7C`)
48β
49 const param = await page.getByTestId('special-param').textContent()
50β
51 expect(param).toBe('λ|')
52 })
53β
54 test('should render route correctly on router navigation', async ({
55 page,
56 baseURL,
57 }) => {
58 const link = page.getByTestId('special-param-link')
59β
60 await link.click()
61 await page.waitForURL(`${baseURL}/specialChars/%EB%8C%80%7C`)
62β
63 const param = await page.getByTestId('special-param').textContent()
64β
65 expect(param).toBe('λ|')
66 })
67β
68 test('should not cause redirect loop for curly braces in path params', async ({
69 page,
70 baseURL,
71 }) => {
72 // %7B/%7D (curly braces) must not trigger infinite 307 redirects
73 const res = await page.goto('/specialChars/%7B%7Bapp_name%7D%7D')
74 await page.waitForLoadState('load')
75β
76 // Should not redirect β URL stays encoded
77 expect(page.url()).toBe(`${baseURL}/specialChars/%7B%7Bapp_name%7D%7D`)
78 expect(res!.status()).toBe(200)
79β
80 const param = await page.getByTestId('special-param').textContent()
81 expect(param).toBe('{{app_name}}')
82 })
83 })
84β
85 test.describe('Special characters in search params', () => {
86 test('should render route correctly on direct navigation', async ({
87 page,
88 baseURL,
89 }) => {
90 await page.goto('/specialChars/search?searchParam=λ|')
91β
92 await page.waitForURL(
93 `${baseURL}/specialChars/search?searchParam=%EB%8C%80|`,
94 )
95β
96 await page.waitForLoadState('networkidle')
97β
98 const searchParam = await page
99 .getByTestId('special-search-param')
100 .textContent()
101β
102 expect(searchParam).toBe('λ|')
103β
104 const loadedOn = await page
105 .getByTestId('special-search-loaded-info')
106 .textContent()
107 const beforeLoadOn = await page
108 .getByTestId('special-search-before-load-info')
109 .textContent()
110β
111 if (isSpaMode) {
112 expect(loadedOn).toBe('Loaded on: client')
113 expect(beforeLoadOn).toBe('Before load on: client')
114 } else {
115 expect(loadedOn).toBe('Loaded on: server')
116 expect(beforeLoadOn).toBe('Before load on: server')
117 }
118 })
119β
120 test('should render route correctly on router navigation', async ({
121 page,
122 baseURL,
123 }) => {
124 const link = page.getByTestId('special-searchParam-link')
125β
126 await link.click()
127 await page.waitForURL(
128 `${baseURL}/specialChars/search?searchParam=%EB%8C%80%7C`,
129 )
130β
131 const searchParam = await page
132 .getByTestId('special-search-param')
133 .textContent()
134β
135 expect(searchParam).toBe('λ|')
136 })
137 })
138β
139 test.describe('Special characters in url hash', () => {
140 test('should render route correctly on direct navigation', async ({
141 page,
142 baseURL,
143 }) => {
144 await expect(page.getByTestId('special-hash-link-1')).not.toContainClass(
145 'font-bold',
146 )
147 await expect(page.getByTestId('special-hash-link-2')).not.toContainClass(
148 'font-bold',
149 )
150β
151 await page.goto('/specialChars/hash#λ|')
152β
153 await page.waitForURL(`${baseURL}/specialChars/hash#%EB%8C%80|`)
154 await page.waitForLoadState('load')
155β
156 await expect(page.getByTestId('special-hash-heading')).toBeInViewport()
157β
158 await expect(page.getByTestId('special-hash-link-1')).toContainClass(
159 'font-bold',
160 )
161β
162 await expect(page.getByTestId('special-hash-link-2')).not.toContainClass(
163 'font-bold',
164 )
165β
166 await page.getByTestId('toggle-hash-button').click()
167β
168 const hashValue = await page.getByTestId('special-hash').textContent()
169β
170 expect(hashValue).toBe('λ|')
171 })
172β
173 test('should render route correctly on router navigation', async ({
174 page,
175 baseURL,
176 }) => {
177 await expect(page.getByTestId('special-hash-link-1')).not.toContainClass(
178 'font-bold',
179 )
180β
181 await expect(page.getByTestId('special-hash-link-2')).not.toContainClass(
182 'font-bold',
183 )
184β
185 const link = page.getByTestId('special-hash-link-1')
186β
187 await link.click()
188β
189 await page.waitForURL(`${baseURL}/specialChars/hash#%EB%8C%80|`)
190 await page.waitForLoadState('load')
191β
192 await expect(page.getByTestId('special-hash-heading')).toBeInViewport()
193β
194 await expect(page.getByTestId('special-hash-link-1')).toContainClass(
195 'font-bold',
196 )
197β
198 await expect(page.getByTestId('special-hash-link-2')).not.toContainClass(
199 'font-bold',
200 )
201β
202 await page.getByTestId('toggle-hash-button').click()
203β
204 const hashValue = await page.getByTestId('special-hash').textContent()
205β
206 expect(hashValue).toBe('λ|')
207 })
208 })
209β
210 test.describe('malformed paths', () => {
211 const malformedPathnames = [
212 '/specialChars/malformed/%E0%A4',
213 '/specialChars/malformed/%80',
214 '/specialChars/malformed/%FF',
215 ]
216β
217 test.use({
218 whitelistErrors: [
219 'Failed to load resource: the server responded with a status of 404',
220 'Failed to load resource: the server responded with a status of 400 (Bad Request)',
221 ],
222 })
223β
224 for (const pathname of malformedPathnames) {
225 test(`un-matched malformed path "${pathname}" should return bad request on direct navigation`, async ({
226 page,
227 }) => {
228 const res = await page.goto(pathname)
229β
230 await page.waitForLoadState(`load`)
231β
232 // in spa mode this is caught and handled at server level
233 if (!isSpaMode) {
234 expect(res!.status()).toBe(400)
235 } else {
236 expect(res!.status()).toBe(400)
237 }
238 })
239 }
240β
241 test('malformed path params should return not found on router link', async ({
242 page,
243 baseURL,
244 }) => {
245 await page.goto('/specialChars/malformed')
246 await page.waitForURL(`${baseURL}/specialChars/malformed`)
247β
248 const link = page.getByTestId('special-malformed-path-link')
249β
250 await link.click()
251β
252 await page.waitForLoadState('load')
253β
254 await expect(
255 page.getByTestId('default-not-found-component'),
256 ).toBeInViewport()
257 })
258β
259 test('un-matched malformed paths should return not found on direct navigation in search params', async ({
260 page,
261 baseURL,
262 }) => {
263 await page.goto('/specialChars/malformed/search?searchParam=%E0%A4')
264β
265 await page.waitForURL(
266 `${baseURL}/specialChars/malformed/search?searchParam=%E0%A4`,
267 )
268β
269 await expect(
270 page.getByTestId('special-malformed-search-param'),
271 ).toBeInViewport()
272β
273 const searchParam = await page
274 .getByTestId('special-malformed-search-param')
275 .textContent()
276β
277 expect(searchParam).toBe('οΏ½')
278 })
279 })
280})