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β
69 test.describe('Special characters in search params', () => {
70 test('should render route correctly on direct navigation', async ({
71 page,
72 baseURL,
73 }) => {
74 await page.goto('/specialChars/search?searchParam=λ|')
75β
76 await page.waitForURL(
77 `${baseURL}/specialChars/search?searchParam=%EB%8C%80|`,
78 )
79β
80 const searchParam = await page
81 .getByTestId('special-search-param')
82 .textContent()
83β
84 expect(searchParam).toBe('λ|')
85 })
86β
87 test('should render route correctly on router navigation', async ({
88 page,
89 baseURL,
90 }) => {
91 const link = page.getByTestId('special-searchParam-link')
92β
93 await link.click()
94 await page.waitForURL(
95 `${baseURL}/specialChars/search?searchParam=%EB%8C%80%7C`,
96 )
97β
98 const searchParam = await page
99 .getByTestId('special-search-param')
100 .textContent()
101β
102 expect(searchParam).toBe('λ|')
103 })
104 })
105β
106 test.describe('Special characters in url hash', () => {
107 test('should render route correctly on direct navigation', async ({
108 page,
109 baseURL,
110 }) => {
111 await expect(page.getByTestId('special-hash-link-1')).not.toContainClass(
112 'font-bold',
113 )
114 await expect(page.getByTestId('special-hash-link-2')).not.toContainClass(
115 'font-bold',
116 )
117β
118 await page.goto('/specialChars/hash#λ|')
119β
120 await page.waitForURL(`${baseURL}/specialChars/hash#%EB%8C%80|`)
121 await page.waitForLoadState('load')
122β
123 await expect(page.getByTestId('special-hash-heading')).toBeInViewport()
124β
125 await expect(page.getByTestId('special-hash-link-1')).toContainClass(
126 'font-bold',
127 )
128β
129 await expect(page.getByTestId('special-hash-link-2')).not.toContainClass(
130 'font-bold',
131 )
132β
133 await page.getByTestId('toggle-hash-button').click()
134β
135 const hashValue = await page.getByTestId('special-hash').textContent()
136β
137 expect(hashValue).toBe('λ|')
138 })
139β
140 test('should render route correctly on router navigation', async ({
141 page,
142 baseURL,
143 }) => {
144 await expect(page.getByTestId('special-hash-link-1')).not.toContainClass(
145 'font-bold',
146 )
147β
148 await expect(page.getByTestId('special-hash-link-2')).not.toContainClass(
149 'font-bold',
150 )
151β
152 const link = page.getByTestId('special-hash-link-1')
153β
154 await link.click()
155β
156 await page.waitForURL(`${baseURL}/specialChars/hash#%EB%8C%80|`)
157 await page.waitForLoadState('load')
158β
159 await expect(page.getByTestId('special-hash-heading')).toBeInViewport()
160β
161 await expect(page.getByTestId('special-hash-link-1')).toContainClass(
162 'font-bold',
163 )
164β
165 await expect(page.getByTestId('special-hash-link-2')).not.toContainClass(
166 'font-bold',
167 )
168β
169 await page.getByTestId('toggle-hash-button').click()
170β
171 const hashValue = await page.getByTestId('special-hash').textContent()
172β
173 expect(hashValue).toBe('λ|')
174 })
175 })
176β
177 test.describe('malformed paths', () => {
178 const malformedPathnames = [
179 '/specialChars/malformed/%E0%A4',
180 '/specialChars/malformed/%80',
181 '/specialChars/malformed/%FF',
182 ]
183β
184 test.use({
185 whitelistErrors: [
186 'Failed to load resource: the server responded with a status of 404',
187 'Failed to load resource: the server responded with a status of 400 (Bad Request)',
188 ],
189 })
190β
191 for (const pathname of malformedPathnames) {
192 test(`un-matched malformed path "${pathname}" should return bad request on direct navigation`, async ({
193 page,
194 }) => {
195 const res = await page.goto(pathname)
196β
197 await page.waitForLoadState(`load`)
198β
199 // in spa mode this is caught and handled at server level
200 if (!isSpaMode) {
201 expect(res!.status()).toBe(400)
202 } else {
203 expect(res!.status()).toBe(400)
204 }
205 })
206 }
207β
208 test('malformed path params should return not found on router link', async ({
209 page,
210 baseURL,
211 }) => {
212 await page.goto('/specialChars/malformed')
213 await page.waitForURL(`${baseURL}/specialChars/malformed`)
214β
215 const link = page.getByTestId('special-malformed-path-link')
216β
217 await link.click()
218 await page.waitForLoadState('load')
219β
220 await expect(
221 page.getByTestId('default-not-found-component'),
222 ).toBeInViewport()
223 })
224β
225 test('un-matched malformed paths should return not found on direct navigation in search params', async ({
226 page,
227 baseURL,
228 }) => {
229 await page.goto('/specialChars/malformed/search?searchParam=%E0%A4')
230β
231 await page.waitForURL(
232 `${baseURL}/specialChars/malformed/search?searchParam=%E0%A4`,
233 )
234β
235 await expect(
236 page.getByTestId('special-malformed-search-param'),
237 ).toBeInViewport()
238β
239 const searchParam = await page
240 .getByTestId('special-malformed-search-param')
241 .textContent()
242β
243 expect(searchParam).toBe('οΏ½')
244 })
245 })
246})