1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219import { test, expect } from "@playwright/test";
const BASE = "http://localhost:4174";
/**
* Wait for the RSC browser entry to hydrate.
*/
async function waitForHydration(page: import("@playwright/test").Page) {
await expect(async () => {
const ready = await page.evaluate(
() => !!(window as any).__VINEXT_RSC_ROOT__,
);
expect(ready).toBe(true);
}).toPass({ timeout: 10_000 });
}
test.describe("Catch-all routes", () => {
test("renders with single segment", async ({ page }) => {
await page.goto(`${BASE}/docs/getting-started`);
await expect(page.locator("h1")).toHaveText("Documentation");
await expect(page.locator("main > p:first-of-type")).toHaveText(
"Path: getting-started",
);
await expect(page.locator("main > p:nth-of-type(2)")).toHaveText(
"Segments: 1",
);
});
test("renders with multiple segments", async ({ page }) => {
await page.goto(`${BASE}/docs/api/reference/hooks`);
await expect(page.locator("h1")).toHaveText("Documentation");
await expect(page.locator("main > p:first-of-type")).toHaveText(
"Path: api/reference/hooks",
);
await expect(page.locator("main > p:nth-of-type(2)")).toHaveText(
"Segments: 3",
);
});
test("renders with two segments", async ({ page }) => {
await page.goto(`${BASE}/docs/guides/deployment`);
await expect(page.locator("h1")).toHaveText("Documentation");
await expect(page.locator("main > p:first-of-type")).toHaveText(
"Path: guides/deployment",
);
await expect(page.locator("main > p:nth-of-type(2)")).toHaveText(
"Segments: 2",
);
});
});
test.describe("Optional catch-all routes", () => {
test("renders at root (no segments)", async ({ page }) => {
await page.goto(`${BASE}/optional`);
await expect(page.locator("h1")).toHaveText("Optional Catch-All");
await expect(page.locator("main > p:first-of-type")).toHaveText(
"Path: (root)",
);
await expect(page.locator("main > p:nth-of-type(2)")).toHaveText(
"Segments: 0",
);
});
test("renders with single segment", async ({ page }) => {
await page.goto(`${BASE}/optional/hello`);
await expect(page.locator("h1")).toHaveText("Optional Catch-All");
await expect(page.locator("main > p:first-of-type")).toHaveText(
"Path: hello",
);
await expect(page.locator("main > p:nth-of-type(2)")).toHaveText(
"Segments: 1",
);
});
test("renders with deep nesting", async ({ page }) => {
await page.goto(`${BASE}/optional/a/b/c/d`);
await expect(page.locator("h1")).toHaveText("Optional Catch-All");
await expect(page.locator("main > p:first-of-type")).toHaveText(
"Path: a/b/c/d",
);
await expect(page.locator("main > p:nth-of-type(2)")).toHaveText(
"Segments: 4",
);
});
});
test.describe("Route groups", () => {
test("route group URL excludes group name", async ({ page }) => {
await page.goto(`${BASE}/features`);
await expect(page.locator("h1")).toHaveText("Features");
await expect(page.locator("main > p")).toHaveText(
"This page is in a route group.",
);
});
test("route group page is accessible via client navigation", async ({
page,
}) => {
await page.goto(`${BASE}/`);
await waitForHydration(page);
// Navigate to features page โ it's under (marketing) group
await page.evaluate(() => {
window.location.href = "/features";
});
await expect(page.locator("h1")).toHaveText("Features");
expect(page.url()).toBe(`${BASE}/features`);
});
});
test.describe("Nested dynamic routes", () => {
test("category page renders with param", async ({ page }) => {
await page.goto(`${BASE}/shop/electronics`);
await expect(page.locator("h1")).toHaveText("Category: electronics");
});
test("item page renders with both params", async ({ page }) => {
await page.goto(`${BASE}/shop/electronics/phone`);
await expect(page.locator("h1")).toHaveText("Item: phone in electronics");
});
test("different category renders correctly", async ({ page }) => {
await page.goto(`${BASE}/shop/clothing`);
await expect(page.locator("h1")).toHaveText("Category: clothing");
});
test("nested item under different category", async ({ page }) => {
await page.goto(`${BASE}/shop/clothing/shirt`);
await expect(page.locator("h1")).toHaveText("Item: shirt in clothing");
});
test("navigating between categories via client navigation", async ({
page,
}) => {
await page.goto(`${BASE}/shop/electronics`);
await expect(page.locator("h1")).toHaveText("Category: electronics");
await waitForHydration(page);
await page.evaluate(() => {
(window as any).__NAV_MARKER__ = true;
});
// Navigate to item
await page.evaluate(() => {
window.history.pushState(null, "", "/shop/electronics/laptop");
});
// Full navigation to verify rendering
await page.goto(`${BASE}/shop/electronics/laptop`);
await expect(page.locator("h1")).toHaveText(
"Item: laptop in electronics",
);
});
});
test.describe("Server-side redirects", () => {
test("redirect() returns redirect response", async ({ page }) => {
await page.goto(`${BASE}/redirect-test`);
// Should have followed the redirect to /about
expect(page.url()).toBe(`${BASE}/about`);
await expect(page.locator("h1")).toHaveText("About");
});
test("permanentRedirect() returns redirect response", async ({ page }) => {
await page.goto(`${BASE}/permanent-redirect-test`);
// Should have followed the redirect to /about
expect(page.url()).toBe(`${BASE}/about`);
await expect(page.locator("h1")).toHaveText("About");
});
});
test.describe("Dashboard nested not-found", () => {
test("notFound() in nested route renders dashboard-scoped 404", async ({
page,
}) => {
const response = await page.goto(`${BASE}/dashboard/missing`);
expect(response?.status()).toBe(404);
await expect(page.locator("#dashboard-not-found")).toBeVisible();
await expect(page.locator("#dashboard-not-found h2")).toHaveText(
"Dashboard: Page Not Found",
);
});
test("dashboard layout is preserved when nested not-found renders", async ({
page,
}) => {
await page.goto(`${BASE}/dashboard/missing`);
// The dashboard layout should still wrap the not-found page
await expect(page.locator("#dashboard-layout")).toBeVisible();
await expect(page.locator("#dashboard-not-found")).toBeVisible();
});
});
test.describe("Client navigation hooks SSR", () => {
test("usePathname renders correct pathname on SSR", async ({ page }) => {
await page.goto(`${BASE}/client-nav-test`);
await expect(page.locator("h1")).toHaveText("Client Nav Test");
await expect(page.locator('[data-testid="client-pathname"]')).toHaveText(
"/client-nav-test",
);
});
test("useSearchParams renders query param on SSR", async ({ page }) => {
await page.goto(`${BASE}/client-nav-test?q=hello`);
await expect(page.locator('[data-testid="client-pathname"]')).toHaveText(
"/client-nav-test",
);
await expect(page.locator('[data-testid="client-search-q"]')).toHaveText(
"hello",
);
});
test("useSearchParams is empty when no query", async ({ page }) => {
await page.goto(`${BASE}/client-nav-test`);
await expect(page.locator('[data-testid="client-search-q"]')).toHaveText(
"",
);
});
});