forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
splat-routes-test.ts
129 lines (109 loc) · 3.39 KB
/
splat-routes-test.ts
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
import { test, expect } from "@playwright/test";
import { createFixture, js } from "./helpers/create-fixture.js";
import type { Fixture } from "./helpers/create-fixture.js";
test.describe("rendering", () => {
let fixture: Fixture;
let ROOT_$ = "FLAT";
let ROOT_INDEX = "ROOT_INDEX";
let FLAT_$ = "FLAT";
let PARENT = "PARENT";
let NESTED_$ = "NESTED_$";
let NESTED_INDEX = "NESTED_INDEX";
let PARENTLESS_$ = "PARENTLESS_$";
test.beforeAll(async () => {
fixture = await createFixture({
files: {
"app/root.tsx": js`
import { Links, Meta, Outlet, Scripts } from "@remix-run/react";
export default function Root() {
return (
<html lang="en">
<head>
<Meta />
<Links />
</head>
<body>
<Outlet />
<Scripts />
</body>
</html>
);
}
`,
"app/routes/_index.tsx": js`
export default function() {
return <h2>${ROOT_INDEX}</h2>;
}
`,
"app/routes/$.tsx": js`
export default function() {
return <h2>${ROOT_$}</h2>;
}
`,
"app/routes/flat.$.tsx": js`
export default function() {
return <h2>${FLAT_$}</h2>
}
`,
"app/routes/nested.tsx": js`
import { Outlet } from "@remix-run/react";
export default function() {
return (
<div>
<h2>${PARENT}</h2>
<Outlet/>
</div>
)
}
`,
"app/routes/nested.$.tsx": js`
export default function() {
return <h2>${NESTED_$}</h2>
}
`,
"app/routes/nested._index.tsx": js`
export default function() {
return <h2>${NESTED_INDEX}</h2>
}
`,
"app/routes/parentless.$.tsx": js`
export default function() {
return <h2>${PARENTLESS_$}</h2>
}
`,
},
});
});
test("flat exact match", async () => {
let res = await fixture.requestDocument("/flat");
expect(await res.text()).toMatch(FLAT_$);
});
test("flat deep match", async () => {
let res = await fixture.requestDocument("/flat/swig");
expect(await res.text()).toMatch(FLAT_$);
});
test("prioritizes index over root splat", async () => {
let res = await fixture.requestDocument("/");
expect(await res.text()).toMatch(ROOT_INDEX);
});
test("matches root splat", async () => {
let res = await fixture.requestDocument("/twisted/sugar");
expect(await res.text()).toMatch(ROOT_$);
});
test("prioritizes index over splat for parent route match", async () => {
let res = await fixture.requestDocument("/nested");
expect(await res.text()).toMatch(NESTED_INDEX);
});
test("nested child", async () => {
let res = await fixture.requestDocument("/nested/sodalicious");
expect(await res.text()).toMatch(NESTED_$);
});
test("parentless exact match", async () => {
let res = await fixture.requestDocument("/parentless");
expect(await res.text()).toMatch(PARENTLESS_$);
});
test("parentless deep match", async () => {
let res = await fixture.requestDocument("/parentless/chip");
expect(await res.text()).toMatch(PARENTLESS_$);
});
});