Skip to content

Commit d8765f7

Browse files
authored
[codex] simplify landing page DOM structure (#1272)
* refactor: simplify landing page DOM structure Simplify the landing page markup by removing single-child wrappers and moving layout classes onto the surviving elements where needed. Add responsive visual snapshots for the major landing page sections at desktop, tablet, and mobile widths so the refactor has a stable regression baseline. * test: scope landing page snapshots to section roots Render the full landing page in browser tests and target section roots by data-testid instead of route helper exports. Refresh the existing landing page snapshots and increase the mobile viewport height so tall sections capture without extra white space. * test: isolate landing page snapshot captures Clone selected landing page sections into a top-level sandbox before screenshotting so Vitest captures the component instead of page scroll context. Refresh the landing page snapshots and add the page-level getByTestId binding used by the new harness. * test: load hljs in vitest setup Mirror the landing page highlight.js registration in browser tests. Add regression coverage for highlighted playground code in the live render and sandboxed snapshot copy. * test: fix landing page snapshot capture Render selected landing sections inside a normal test wrapper before capturing screenshots. Refresh the affected landing-page screenshots so the playground hero retains syntax highlighting in the stored baselines.
1 parent bd1bd05 commit d8765f7

22 files changed

Lines changed: 360 additions & 134 deletions

__tests__/LandingPage_.test.res

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
open ReactRouter
22
open Vitest
33

4+
@module("vitest")
5+
external testWithTimeout: (string, unit => promise<unit>, int) => unit = "test"
6+
47
let expectedExample = `module Button = {
58
@react.component
69
let make = (~count) => {
@@ -15,6 +18,126 @@ let expectedExample = `module Button = {
1518
}
1619
}`
1720

21+
let snapshotSection = async (~width, ~height, ~sectionTestId, ~screenshotName) => {
22+
await viewport(width, height)
23+
24+
let screen = await render(
25+
<MemoryRouter initialEntries=["/"]>
26+
<LandingPage />
27+
</MemoryRouter>,
28+
)
29+
30+
let sourceSection = switch document->WebAPI.Document.querySelector(
31+
`[data-testid="${sectionTestId}"]`,
32+
) {
33+
| Value(section) => section
34+
| Null => failwith(`expected to find section ${sectionTestId}`)
35+
}
36+
37+
let sandboxTestId = `${sectionTestId}-snapshot`
38+
let snapshotHtml = sourceSection.outerHTML
39+
await screen->unmount
40+
41+
let snapshotScreen = await render(
42+
<div
43+
dataTestId=sandboxTestId
44+
style={{width: `${width->Int.toString}px`, margin: "0"}}
45+
dangerouslySetInnerHTML={"__html": snapshotHtml}
46+
/>,
47+
)
48+
49+
let snapshotTarget = await snapshotScreen->getByTestId(sandboxTestId)
50+
await element(snapshotTarget)->toBeVisible
51+
await element(snapshotTarget)->toMatchScreenshot(screenshotName)
52+
await snapshotScreen->unmount
53+
}
54+
55+
let snapshotResponsive = async (~sectionTestId, ~screenshotBase) => {
56+
await snapshotSection(
57+
~width=1440,
58+
~height=1800,
59+
~sectionTestId,
60+
~screenshotName={`${screenshotBase}-desktop`},
61+
)
62+
63+
await snapshotSection(
64+
~width=900,
65+
~height=1800,
66+
~sectionTestId,
67+
~screenshotName={`${screenshotBase}-tablet`},
68+
)
69+
70+
await snapshotSection(
71+
~width=600,
72+
~height=1800,
73+
~sectionTestId,
74+
~screenshotName={`${screenshotBase}-mobile`},
75+
)
76+
}
77+
78+
testWithTimeout(
79+
"landing intro snapshots",
80+
async () => {
81+
await snapshotResponsive(~sectionTestId="landing-intro", ~screenshotBase="landing-page-intro")
82+
},
83+
30000,
84+
)
85+
86+
testWithTimeout(
87+
"landing playground hero snapshots",
88+
async () => {
89+
await snapshotResponsive(
90+
~sectionTestId="landing-playground-hero",
91+
~screenshotBase="landing-page-playground-hero",
92+
)
93+
},
94+
30000,
95+
)
96+
97+
testWithTimeout(
98+
"landing quick install snapshots",
99+
async () => {
100+
await snapshotResponsive(
101+
~sectionTestId="landing-quick-install",
102+
~screenshotBase="landing-page-quick-install",
103+
)
104+
},
105+
30000,
106+
)
107+
108+
testWithTimeout(
109+
"landing other selling points snapshots",
110+
async () => {
111+
await snapshotResponsive(
112+
~sectionTestId="landing-other-selling-points",
113+
~screenshotBase="landing-page-other-selling-points",
114+
)
115+
},
116+
30000,
117+
)
118+
119+
testWithTimeout(
120+
"landing trusted by snapshots",
121+
async () => {
122+
await snapshotResponsive(
123+
~sectionTestId="landing-trusted-by",
124+
~screenshotBase="landing-page-trusted-by",
125+
)
126+
},
127+
30000,
128+
)
129+
130+
testWithTimeout(
131+
"landing curated resources snapshots",
132+
async () => {
133+
await snapshotResponsive(
134+
~sectionTestId="landing-curated-resources",
135+
~screenshotBase="landing-page-curated-resources",
136+
)
137+
},
138+
30000,
139+
)
140+
18141
test(
19142
"landing page playground link uses compressed code that the playground can decode",
20143
async () => {
@@ -53,3 +176,94 @@ test(
53176
expect(decodedCode->Option.getOrThrow)->toBe(expectedExample)
54177
},
55178
)
179+
180+
test("landing page playground hero renders highlighted code tokens", async () => {
181+
let screen = await render(
182+
<MemoryRouter initialEntries=["/"]>
183+
<LandingPage />
184+
</MemoryRouter>,
185+
)
186+
187+
let _ = await screen->getByText("Write in ReScript")
188+
189+
let rescriptCodeBlock = switch document->WebAPI.Document.querySelector(
190+
"[data-testid='landing-playground-hero'] code.lang-res",
191+
) {
192+
| Value(codeBlock) => codeBlock
193+
| Null => failwith("expected landing playground hero to render the ReScript code block")
194+
}
195+
196+
let javascriptCodeBlock = switch document->WebAPI.Document.querySelector(
197+
"[data-testid='landing-playground-hero'] code.lang-js",
198+
) {
199+
| Value(codeBlock) => codeBlock
200+
| Null => failwith("expected landing playground hero to render the JavaScript code block")
201+
}
202+
203+
expect(rescriptCodeBlock.innerHTML->String.includes("<span"))->toBe(true)
204+
expect(javascriptCodeBlock.innerHTML->String.includes("<span"))->toBe(true)
205+
})
206+
207+
test(
208+
"landing page playground hero keeps highlight styling in the sandboxed snapshot copy",
209+
async () => {
210+
await viewport(1440, 1800)
211+
212+
let screen = await render(
213+
<MemoryRouter initialEntries=["/"]>
214+
<LandingPage />
215+
</MemoryRouter>,
216+
)
217+
218+
let sourceSection = switch document->WebAPI.Document.querySelector(
219+
"[data-testid='landing-playground-hero']",
220+
) {
221+
| Value(section) => section
222+
| Null => failwith("expected to find the landing playground hero section")
223+
}
224+
225+
let sandboxTestId = "landing-playground-hero-sandbox"
226+
let snapshotHtml = sourceSection.outerHTML
227+
await screen->unmount
228+
229+
let snapshotScreen = await render(
230+
<div
231+
dataTestId=sandboxTestId
232+
style={{width: "1440px", margin: "0"}}
233+
dangerouslySetInnerHTML={"__html": snapshotHtml}
234+
/>,
235+
)
236+
237+
let _ = await snapshotScreen->getByTestId(sandboxTestId)
238+
239+
let sandbox = switch document->WebAPI.Document.querySelector(
240+
"[data-testid='landing-playground-hero-sandbox']",
241+
) {
242+
| Value(sandbox) => sandbox
243+
| Null => failwith("expected to find the sandboxed landing playground hero")
244+
}
245+
246+
let sandboxRect: WebAPI.DOMAPI.domRect = sandbox->WebAPI.Element.getBoundingClientRect
247+
248+
let rescriptCodeBlock = switch document->WebAPI.Document.querySelector(
249+
"[data-testid='landing-playground-hero-sandbox'] code.lang-res",
250+
) {
251+
| Value(codeBlock) => codeBlock
252+
| Null =>
253+
failwith("expected sandboxed landing playground hero to render the ReScript code block")
254+
}
255+
256+
let javascriptCodeBlock = switch document->WebAPI.Document.querySelector(
257+
"[data-testid='landing-playground-hero-sandbox'] code.lang-js",
258+
) {
259+
| Value(codeBlock) => codeBlock
260+
| Null =>
261+
failwith("expected sandboxed landing playground hero to render the JavaScript code block")
262+
}
263+
264+
expect(sandboxRect.width > 1000.0)->toBe(true)
265+
expect(rescriptCodeBlock.innerHTML->String.includes("<span"))->toBe(true)
266+
expect(javascriptCodeBlock.innerHTML->String.includes("<span"))->toBe(true)
267+
await snapshotScreen->unmount
268+
},
269+
)
32.5 KB
Loading
28.9 KB
Loading
32.1 KB
Loading
26.2 KB
Loading
22.8 KB
Loading
26 KB
Loading
126 KB
Loading
119 KB
Loading
107 KB
Loading

0 commit comments

Comments
 (0)