-
Notifications
You must be signed in to change notification settings - Fork 595
/
layouts_test.ts
203 lines (180 loc) · 5.67 KB
/
layouts_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
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
import { assert } from "./deps.ts";
import {
assertNotSelector,
assertSelector,
clickWhenListenerReady,
waitForText,
withFakeServe,
withPageName,
} from "./test_utils.ts";
Deno.test("apply root _layout and _app", async () => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
const doc = await server.getHtml("/");
assert(doc.body.textContent?.includes("it works"));
assertSelector(doc, ".app .root-layout .home-page");
const doc2 = await server.getHtml("/other");
assertSelector(doc2, ".app .root-layout .other-page");
},
);
});
Deno.test("apply sub layouts", async () => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
const doc = await server.getHtml("/foo");
assertSelector(doc, ".app .root-layout .foo-layout .foo-page");
const doc2 = await server.getHtml("/foo/bar");
assertSelector(doc2, ".app .root-layout .foo-layout .bar-page");
},
);
});
Deno.test("skip layouts if not present", async () => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
const doc = await server.getHtml(`/skip/sub`);
assertSelector(doc, ".app .root-layout .sub-layout .sub-page");
},
);
});
Deno.test("check file types", async (t) => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
await t.step(".js", async () => {
const doc = await server.getHtml(`/files/js`);
assertSelector(doc, ".app .root-layout .js-layout .js-page");
});
await t.step(".jsx", async () => {
const doc = await server.getHtml(`/files/jsx`);
assertSelector(doc, ".app .root-layout .jsx-layout .jsx-page");
});
await t.step(".ts", async () => {
const doc = await server.getHtml(`/files/ts`);
assertSelector(doc, ".app .root-layout .ts-layout .ts-page");
});
await t.step(".tsx", async () => {
const doc = await server.getHtml(`/files/tsx`);
assertSelector(doc, ".app .root-layout .tsx-layout .tsx-page");
});
},
);
});
Deno.test("render async layout", async () => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
const doc = await server.getHtml(`/async`);
assertSelector(doc, ".app .root-layout .async-layout .async-page");
},
);
});
Deno.test("render nested async layout", async () => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
const doc = await server.getHtml(`/async/sub`);
assertSelector(
doc,
".app .root-layout .async-layout .async-sub-layout .async-sub-page",
);
},
);
});
Deno.test("can return Response from async layout", async () => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
const doc = await server.getHtml(`/async/redirect`);
assertSelector(
doc,
".app .root-layout .async-layout .async-sub-layout .async-sub-page",
);
},
);
});
Deno.test("disable _app layout", async () => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
const doc = await server.getHtml(`/override/no_app`);
assertNotSelector(doc, "body body");
assertSelector(doc, "body > .override-layout >.no-app");
},
);
});
Deno.test("disable _app in _layout", async () => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
const doc = await server.getHtml(`/override/layout_no_app`);
assertNotSelector(doc, "body body");
assertSelector(doc, "body > .override-layout > .no-app-layout > .page");
},
);
});
Deno.test("override layouts", async () => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
const doc = await server.getHtml(`/override`);
assertSelector(doc, "body > .app > .override-layout > .override-page");
},
);
});
Deno.test("route overrides layout", async () => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
const doc = await server.getHtml(`/override/no_layout`);
assertSelector(doc, "body > .app > .no-layouts");
},
);
});
Deno.test("route overrides layout and app", async () => {
await withFakeServe(
"./tests/fixture_layouts/main.ts",
async (server) => {
const doc = await server.getHtml(`/override/no_layout_no_app`);
assertSelector(doc, "body > .no-app-no-layouts");
},
);
});
Deno.test({
name: "island in dynamic route test",
async fn(t) {
await withPageName(
"./tests/fixture_layouts/main.ts",
async (page, address) => {
async function counterTest(counterId: string, originalValue: number) {
const pElem = await page.waitForSelector(`#${counterId} > p`);
const value = await pElem?.evaluate((el) => el.textContent);
assert(value === `${originalValue}`, `${counterId} first value`);
await clickWhenListenerReady(page, `#b-${counterId}`);
await waitForText(
page,
`#${counterId} > p`,
String(originalValue + 1),
);
}
await page.goto(`${address}/dynamic/acme-corp`, {
waitUntil: "networkidle2",
});
await t.step("Ensure 1 island on 1 page are revived", async () => {
await counterTest("counter", 3);
});
},
);
},
});
Deno.test("mix async app and layouts", async () => {
await withFakeServe(
"./tests/fixture_layouts_2/main.ts",
async (server) => {
const doc = await server.getHtml(`/`);
assertSelector(doc, ".app > .root-layout > .home-page");
},
);
});