1 import { render } from "@testing-library/react"
2 import * as React from "react"
3 import { I18nProvider } from "react-aria"
4
5 import { DatePicker } from "../date-picker"
6
7 describe("DateSegment", () => {
8 it.each(["en-US", "fr-FR"])(
9 "renders every date/time separator as a spacing span in %s",
10 (locale) => {
11 const { container } = render(
12 <I18nProvider locale={locale}>
13 <DatePicker
14 granularity="minute"
15 value={new Date(2026, 8, 9, 9, 5)}
16 aria-label="Date"
17 />
18 </I18nProvider>
19 )
20
21 /**
22 * The literal between the date and the time depends on the locale:
23 * ", " in en-US, a lone " " in fr-FR. Both must become the spacing
24 * span. A ", " left as text is a visible comma without a gap; a " "
25 * left as text collapses and glues the date to the time.
26 *
27 * Node's ICU also emits a " " before the day period in en-US
28 * (09:05 AM), so the number of spans is not asserted: what matters is
29 * that no separator survives as text.
30 */
31 expect(container.querySelector("span.mx-1")).not.toBeNull()
32
33 const leafTexts = Array.from(container.querySelectorAll("div"))
34 .filter((element) => element.children.length === 0)
35 .map((element) => element.textContent ?? "")
36
37 expect(leafTexts).not.toContain(", ")
38 expect(
39 leafTexts.filter((text) => text.length > 0 && text.trim() === "")
40 ).toHaveLength(0)
41 }
42 )
43 })