Skip to content

Commit a69214e

Browse files
committed
test(solid): add params.spec.ts to start/router
1 parent f4a544f commit a69214e

2 files changed

Lines changed: 171 additions & 0 deletions

File tree

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import { expect, test } from '@playwright/test'
2+
3+
test.describe('params operations + prefix/suffix', () => {
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('/params-ps')
6+
})
7+
8+
test.describe('named params', () => {
9+
const NAMED_PARAMS_PAIRS = [
10+
// Test ID | Expected href
11+
{
12+
id: 'l-to-named-foo',
13+
pathname: '/params-ps/named/foo',
14+
params: { foo: 'foo' },
15+
destHeadingId: 'ParamsNamedFoo',
16+
},
17+
{
18+
id: 'l-to-named-prefixfoo',
19+
pathname: '/params-ps/named/prefixfoo',
20+
params: { foo: 'foo' },
21+
destHeadingId: 'ParamsNamedFooPrefix',
22+
},
23+
{
24+
id: 'l-to-named-foosuffix',
25+
pathname: '/params-ps/named/foosuffix',
26+
params: { foo: 'foo' },
27+
destHeadingId: 'ParamsNamedFooSuffix',
28+
},
29+
] satisfies Array<{
30+
id: string
31+
pathname: string
32+
params: Record<string, string>
33+
destHeadingId: string
34+
}>
35+
36+
test.describe('Link', () => {
37+
NAMED_PARAMS_PAIRS.forEach(({ id, pathname }) => {
38+
test(`interpolation for testid="${id}" has href="${pathname}"`, async ({
39+
page,
40+
}) => {
41+
const link = page.getByTestId(id)
42+
await expect(link).toHaveAttribute('href', pathname)
43+
})
44+
})
45+
46+
NAMED_PARAMS_PAIRS.forEach(({ id, pathname }) => {
47+
test(`navigation for testid="${id}" succeeds to href="${pathname}"`, async ({
48+
page,
49+
}) => {
50+
const link = page.getByTestId(id)
51+
await link.click()
52+
await page.waitForLoadState('networkidle')
53+
const pagePathname = new URL(page.url()).pathname
54+
expect(pagePathname).toBe(pathname)
55+
})
56+
})
57+
})
58+
59+
NAMED_PARAMS_PAIRS.forEach(({ pathname, params, destHeadingId }) => {
60+
test(`on first-load to "${pathname}" has correct params`, async ({
61+
page,
62+
}) => {
63+
await page.goto(pathname)
64+
await page.waitForLoadState('networkidle')
65+
const pagePathname = new URL(page.url()).pathname
66+
expect(pagePathname).toBe(pathname)
67+
68+
const headingEl = page.getByRole('heading', { name: destHeadingId })
69+
await expect(headingEl).toBeVisible()
70+
71+
const paramsEl = page.getByTestId('params-output')
72+
const paramsText = await paramsEl.innerText()
73+
const paramsObj = JSON.parse(paramsText)
74+
expect(paramsObj).toEqual(params)
75+
})
76+
})
77+
})
78+
79+
test.describe('wildcard param', () => {
80+
const WILDCARD_PARAM_PAIRS = [
81+
// Test ID | Expected href
82+
{
83+
id: 'l-to-wildcard-foo',
84+
pathname: '/params-ps/wildcard/foo',
85+
params: { '*': 'foo', _splat: 'foo' },
86+
destHeadingId: 'ParamsWildcardSplat',
87+
},
88+
{
89+
id: 'l-to-wildcard-prefixfoo',
90+
pathname: '/params-ps/wildcard/prefixfoo',
91+
params: { '*': 'foo', _splat: 'foo' },
92+
destHeadingId: 'ParamsWildcardSplatPrefix',
93+
},
94+
{
95+
id: 'l-to-wildcard-foosuffix',
96+
pathname: '/params-ps/wildcard/foosuffix',
97+
params: { '*': 'foo', _splat: 'foo' },
98+
destHeadingId: 'ParamsWildcardSplatSuffix',
99+
},
100+
] satisfies Array<{
101+
id: string
102+
pathname: string
103+
params: Record<string, string>
104+
destHeadingId: string
105+
}>
106+
107+
test.describe('Link', () => {
108+
WILDCARD_PARAM_PAIRS.forEach(({ id, pathname }) => {
109+
test(`interpolation for testid="${id}" has href="${pathname}"`, async ({
110+
page,
111+
}) => {
112+
const link = page.getByTestId(id)
113+
await expect(link).toHaveAttribute('href', pathname)
114+
})
115+
})
116+
117+
WILDCARD_PARAM_PAIRS.forEach(({ id, pathname }) => {
118+
test(`navigation for testid="${id}" succeeds to href="${pathname}"`, async ({
119+
page,
120+
}) => {
121+
const link = page.getByTestId(id)
122+
await link.click()
123+
await page.waitForLoadState('networkidle')
124+
const pagePathname = new URL(page.url()).pathname
125+
expect(pagePathname).toBe(pathname)
126+
})
127+
})
128+
})
129+
130+
WILDCARD_PARAM_PAIRS.forEach(({ pathname, params, destHeadingId }) => {
131+
test(`on first-load to "${pathname}" has correct params`, async ({
132+
page,
133+
}) => {
134+
await page.goto(pathname)
135+
await page.waitForLoadState('networkidle')
136+
const pagePathname = new URL(page.url()).pathname
137+
expect(pagePathname).toBe(pathname)
138+
139+
const headingEl = page.getByRole('heading', { name: destHeadingId })
140+
await expect(headingEl).toBeVisible()
141+
142+
const paramsEl = page.getByTestId('params-output')
143+
const paramsText = await paramsEl.innerText()
144+
const paramsObj = JSON.parse(paramsText)
145+
expect(paramsObj).toEqual(params)
146+
})
147+
})
148+
})
149+
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { expect } from '@playwright/test'
2+
3+
import { test } from '@tanstack/router-e2e-utils'
4+
5+
test.beforeEach(async ({ page }) => {
6+
await page.goto('/')
7+
})
8+
9+
test.use({
10+
whitelistErrors: [
11+
/Failed to load resource: the server responded with a status of 404/,
12+
],
13+
})
14+
test.describe('Unicode route rendering', () => {
15+
test('should render non-latin route correctly', async ({ page, baseURL }) => {
16+
await page.goto('/대한민국')
17+
18+
await expect(page.locator('body')).toContainText('Hello "/대한민국"!')
19+
20+
expect(page.url()).toBe(`${baseURL}/%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD`)
21+
})
22+
})

0 commit comments

Comments
 (0)