@42-central/ui-react 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-I53TMAV2.js → chunk-2RQLPN4U.js} +3 -3
- package/dist/{chunk-I53TMAV2.js.map → chunk-2RQLPN4U.js.map} +1 -1
- package/dist/{chunk-SOUDKESO.js → chunk-37HYN7PC.js} +3 -3
- package/dist/{chunk-SOUDKESO.js.map → chunk-37HYN7PC.js.map} +1 -1
- package/dist/{chunk-TGGNSSOJ.js → chunk-5EOMSWNO.js} +4 -4
- package/dist/{chunk-TGGNSSOJ.js.map → chunk-5EOMSWNO.js.map} +1 -1
- package/dist/{chunk-K3FZHYJL.js → chunk-7FPSQBWB.js} +3 -3
- package/dist/{chunk-K3FZHYJL.js.map → chunk-7FPSQBWB.js.map} +1 -1
- package/dist/{chunk-WERJ44ZN.js → chunk-DTFSCR3U.js} +3 -3
- package/dist/{chunk-WERJ44ZN.js.map → chunk-DTFSCR3U.js.map} +1 -1
- package/dist/{chunk-PFZMB3US.js → chunk-FQJNQW3G.js} +3 -3
- package/dist/{chunk-PFZMB3US.js.map → chunk-FQJNQW3G.js.map} +1 -1
- package/dist/{chunk-ASKQ6N5V.js → chunk-FSPS7TVD.js} +4 -4
- package/dist/{chunk-ASKQ6N5V.js.map → chunk-FSPS7TVD.js.map} +1 -1
- package/dist/{chunk-GJFCIG34.js → chunk-GEZYGBXY.js} +5 -5
- package/dist/{chunk-GJFCIG34.js.map → chunk-GEZYGBXY.js.map} +1 -1
- package/dist/{chunk-ULF5LOBS.js → chunk-HMNXNKDA.js} +3 -3
- package/dist/{chunk-ULF5LOBS.js.map → chunk-HMNXNKDA.js.map} +1 -1
- package/dist/{chunk-NF2PBGD3.js → chunk-IANYMDKH.js} +3 -3
- package/dist/{chunk-NF2PBGD3.js.map → chunk-IANYMDKH.js.map} +1 -1
- package/dist/{chunk-QEMXXQQO.js → chunk-JKFPRQB2.js} +3 -3
- package/dist/{chunk-QEMXXQQO.js.map → chunk-JKFPRQB2.js.map} +1 -1
- package/dist/{chunk-P7SH3XWY.js → chunk-MQHD3EJE.js} +3 -3
- package/dist/{chunk-P7SH3XWY.js.map → chunk-MQHD3EJE.js.map} +1 -1
- package/dist/{chunk-IUK7OJXZ.js → chunk-OBSZ4NE2.js} +5 -4
- package/dist/chunk-OBSZ4NE2.js.map +1 -0
- package/dist/{chunk-DJ72KP32.js → chunk-OXR7BXZA.js} +3 -3
- package/dist/{chunk-DJ72KP32.js.map → chunk-OXR7BXZA.js.map} +1 -1
- package/dist/{chunk-LIZWCWED.js → chunk-PQZSTI3R.js} +3 -3
- package/dist/{chunk-LIZWCWED.js.map → chunk-PQZSTI3R.js.map} +1 -1
- package/dist/{chunk-7BY5I2RB.js → chunk-S5CQRCTF.js} +4 -4
- package/dist/{chunk-7BY5I2RB.js.map → chunk-S5CQRCTF.js.map} +1 -1
- package/dist/{chunk-BGDVUC3B.js → chunk-TUP7WXQE.js} +3 -3
- package/dist/{chunk-BGDVUC3B.js.map → chunk-TUP7WXQE.js.map} +1 -1
- package/dist/{chunk-KYVXPSNW.js → chunk-V2QZG4IT.js} +3 -3
- package/dist/{chunk-KYVXPSNW.js.map → chunk-V2QZG4IT.js.map} +1 -1
- package/dist/components/alert/index.js +1 -1
- package/dist/components/ambient-background/index.js +1 -1
- package/dist/components/app-shell/index.js +3 -3
- package/dist/components/avatar/index.js +2 -2
- package/dist/components/calendar/index.js +3 -3
- package/dist/components/calendar-heatmap/index.js +2 -2
- package/dist/components/camera/index.js +3 -3
- package/dist/components/carousel/index.js +2 -2
- package/dist/components/code-block/index.js +1 -1
- package/dist/components/code-block/static.js.map +1 -1
- package/dist/components/compare/index.js +2 -2
- package/dist/components/data-table/index.js +10 -10
- package/dist/components/date-picker/index.js +7 -7
- package/dist/components/drawer/index.js +3 -3
- package/dist/components/file-item/index.js +4 -4
- package/dist/components/file-preview/index.js +3 -3
- package/dist/components/file-upload/index.js +4 -4
- package/dist/components/gallery/index.js +2 -2
- package/dist/components/image-cropper/index.js +4 -4
- package/dist/components/indicator/index.js +1 -1
- package/dist/components/kbd/index.js +3 -3
- package/dist/components/lightbox/index.js +4 -4
- package/dist/components/menu/index.js +2 -2
- package/dist/components/modal/index.js +3 -3
- package/dist/components/multi-select/index.js +3 -3
- package/dist/components/overlays/index.js +4 -4
- package/dist/components/password-input/index.js +1 -1
- package/dist/components/phone-input/flag.d.ts +9 -0
- package/dist/components/phone-input/flag.d.ts.map +1 -0
- package/dist/components/phone-input/index.d.ts +4 -0
- package/dist/components/phone-input/index.d.ts.map +1 -0
- package/dist/components/phone-input/index.js +503 -0
- package/dist/components/phone-input/index.js.map +1 -0
- package/dist/components/phone-input/phone-input.d.ts +125 -0
- package/dist/components/phone-input/phone-input.d.ts.map +1 -0
- package/dist/components/phone-input/phone.d.ts +117 -0
- package/dist/components/phone-input/phone.d.ts.map +1 -0
- package/dist/components/photo-capture/index.js +5 -5
- package/dist/components/pills-input/index.js +3 -3
- package/dist/components/schedule/index.js +3 -3
- package/dist/components/segment-group/index.js +3 -3
- package/dist/components/spotlight/index.js +5 -5
- package/dist/components/tabs/index.js +3 -3
- package/dist/components/tags-input/index.js +3 -3
- package/dist/components/time-input/index.js +4 -4
- package/dist/components/timeline/index.d.ts +1 -1
- package/dist/components/timeline/index.d.ts.map +1 -1
- package/dist/components/timeline/index.js +40 -11
- package/dist/components/timeline/index.js.map +1 -1
- package/dist/components/timeline/timeline.d.ts +8 -3
- package/dist/components/timeline/timeline.d.ts.map +1 -1
- package/dist/components/tree-multi-select/index.js +3 -3
- package/dist/index.js +4 -4
- package/dist/lib/dev-warn.d.ts +1 -0
- package/dist/lib/dev-warn.d.ts.map +1 -1
- package/dist/lib/intl.d.ts +5 -0
- package/dist/lib/intl.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/as-child.contract.test.tsx +2 -0
- package/src/components/phone-input/flag.tsx +86 -0
- package/src/components/phone-input/index.ts +14 -0
- package/src/components/phone-input/phone-input.test.tsx +285 -0
- package/src/components/phone-input/phone-input.tsx +527 -0
- package/src/components/phone-input/phone.test.ts +187 -0
- package/src/components/phone-input/phone.ts +298 -0
- package/src/components/timeline/index.ts +1 -0
- package/src/components/timeline/timeline.test.tsx +105 -4
- package/src/components/timeline/timeline.tsx +46 -11
- package/src/lib/dev-warn.ts +1 -1
- package/src/lib/intl-direction.test.tsx +23 -0
- package/src/lib/intl.tsx +8 -2
- package/dist/chunk-IUK7OJXZ.js.map +0 -1
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react"
|
|
2
|
+
import { useState } from "react"
|
|
3
|
+
import { renderToStaticMarkup } from "react-dom/server"
|
|
4
|
+
import { describe, expect, it, vi } from "vitest"
|
|
5
|
+
import { PhoneInput } from "./phone-input"
|
|
6
|
+
|
|
7
|
+
const phone = () => screen.getByRole("textbox") as HTMLInputElement
|
|
8
|
+
const trigger = () => screen.getByRole("button", { name: /^Country/ })
|
|
9
|
+
|
|
10
|
+
/** Type into the field the way a browser does: new value, caret at `caret`, then `input`. */
|
|
11
|
+
const typeAt = (input: HTMLInputElement, value: string, caret = value.length) => {
|
|
12
|
+
const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set
|
|
13
|
+
setValue?.call(input, value)
|
|
14
|
+
input.setSelectionRange(caret, caret)
|
|
15
|
+
fireEvent.input(input)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("PhoneInput — formatting", () => {
|
|
19
|
+
it("formats as you type and reports E.164 with its details", () => {
|
|
20
|
+
const onChange = vi.fn()
|
|
21
|
+
render(<PhoneInput defaultCountry="FR" onChange={onChange} />)
|
|
22
|
+
fireEvent.change(phone(), { target: { value: "0612345678" } })
|
|
23
|
+
expect(phone().value).toBe("06 12 34 56 78")
|
|
24
|
+
expect(onChange).toHaveBeenLastCalledWith("+33612345678", { country: "FR", isValid: true })
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it("reports null once the field is emptied", () => {
|
|
28
|
+
const onChange = vi.fn()
|
|
29
|
+
render(<PhoneInput defaultValue="+33612345678" onChange={onChange} />)
|
|
30
|
+
fireEvent.change(phone(), { target: { value: "" } })
|
|
31
|
+
expect(onChange).toHaveBeenLastCalledWith(null, { country: "FR", isValid: false })
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("keeps the caret where it was on a mid-number insert", () => {
|
|
35
|
+
render(<PhoneInput defaultCountry="FR" />)
|
|
36
|
+
const input = phone()
|
|
37
|
+
input.focus()
|
|
38
|
+
typeAt(input, "06123456")
|
|
39
|
+
expect(input.value).toBe("06 12 34 56")
|
|
40
|
+
// A 9 typed after "06 1": the browser's raw value is "06 192 34 56", caret after the 9.
|
|
41
|
+
typeAt(input, "06 192 34 56", 5)
|
|
42
|
+
expect(input.value).toBe("06 19 23 45 6")
|
|
43
|
+
expect(input.selectionStart).toBe(5)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it("removes the digit before a separator on Backspace instead of doing nothing", () => {
|
|
47
|
+
render(<PhoneInput defaultCountry="FR" defaultValue="+33612345678" />)
|
|
48
|
+
const input = phone()
|
|
49
|
+
input.focus()
|
|
50
|
+
input.setSelectionRange(3, 3)
|
|
51
|
+
fireEvent.keyDown(input, { key: "Backspace" })
|
|
52
|
+
expect(input.value).toBe("01 23 45 67 8")
|
|
53
|
+
expect(input.selectionStart).toBe(1)
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
describe("PhoneInput — country", () => {
|
|
58
|
+
it("defaults to the locale's region", () => {
|
|
59
|
+
render(<PhoneInput locale="fr-FR" />)
|
|
60
|
+
expect(trigger().getAttribute("aria-label")).toBe("Country: France +33")
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it("defaults to no country when the locale's region isn't allowed", () => {
|
|
64
|
+
render(<PhoneInput locale="fr-FR" countries={["BE", "CH"]} />)
|
|
65
|
+
expect(trigger().getAttribute("aria-label")).toBe("Country: none selected")
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it("switches the country when an international number is pasted", () => {
|
|
69
|
+
const onCountryChange = vi.fn()
|
|
70
|
+
render(<PhoneInput defaultCountry="FR" onCountryChange={onCountryChange} />)
|
|
71
|
+
fireEvent.change(phone(), { target: { value: "+44 20 7946 0958" } })
|
|
72
|
+
expect(onCountryChange).toHaveBeenCalledWith("GB")
|
|
73
|
+
expect(trigger().getAttribute("aria-label")).toContain("+44")
|
|
74
|
+
expect(phone().value).toBe("20 7946 0958")
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it("flags a number from outside `countries` as invalid", () => {
|
|
78
|
+
const onChange = vi.fn()
|
|
79
|
+
render(<PhoneInput defaultCountry="FR" countries={["FR"]} onChange={onChange} />)
|
|
80
|
+
fireEvent.change(phone(), { target: { value: "+442079460958" } })
|
|
81
|
+
expect(onChange).toHaveBeenLastCalledWith("+442079460958", { country: "GB", isValid: false })
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it("keeps the number under a country picked from the list, then focuses the input", async () => {
|
|
85
|
+
const onChange = vi.fn()
|
|
86
|
+
const onCountryChange = vi.fn()
|
|
87
|
+
render(
|
|
88
|
+
<PhoneInput
|
|
89
|
+
defaultCountry="US"
|
|
90
|
+
defaultValue="+12015550123"
|
|
91
|
+
onChange={onChange}
|
|
92
|
+
onCountryChange={onCountryChange}
|
|
93
|
+
/>,
|
|
94
|
+
)
|
|
95
|
+
fireEvent.click(trigger())
|
|
96
|
+
const option = await screen.findByRole("option", { name: /Canada/ })
|
|
97
|
+
fireEvent.pointerDown(option)
|
|
98
|
+
fireEvent.pointerUp(option)
|
|
99
|
+
fireEvent.click(option)
|
|
100
|
+
await waitFor(() => expect(onCountryChange).toHaveBeenCalledWith("CA"))
|
|
101
|
+
// +1 is shared: the number is the same E.164, so only the country is reported.
|
|
102
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
103
|
+
expect(phone().value).toBe("(201) 555-0123")
|
|
104
|
+
await waitFor(() => expect(document.activeElement).toBe(phone()))
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it("pins preferred countries at the top, under their own heading", async () => {
|
|
108
|
+
render(<PhoneInput defaultCountry="FR" preferredCountries={["CH", "BE"]} />)
|
|
109
|
+
fireEvent.click(trigger())
|
|
110
|
+
const options = await screen.findAllByRole("option")
|
|
111
|
+
expect(options.slice(0, 2).map((option) => option.getAttribute("data-value"))).toEqual([
|
|
112
|
+
"CH",
|
|
113
|
+
"BE",
|
|
114
|
+
])
|
|
115
|
+
expect(screen.getByText("Suggested")).toBeTruthy()
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it("draws flags through `renderFlag`", () => {
|
|
119
|
+
render(
|
|
120
|
+
<PhoneInput defaultCountry="FR" renderFlag={(code) => <i data-testid={`flag-${code}`} />} />,
|
|
121
|
+
)
|
|
122
|
+
expect(screen.getByTestId("flag-FR")).toBeTruthy()
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
describe("PhoneInput — the dial code as a token", () => {
|
|
127
|
+
const backspaceAtStart = (input: HTMLInputElement) => {
|
|
128
|
+
input.setSelectionRange(0, 0)
|
|
129
|
+
fireEvent.keyDown(input, { key: "Backspace" })
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
it("moves a typed code into the trigger, and Backspace takes its last digit back out", () => {
|
|
133
|
+
const onCountryChange = vi.fn()
|
|
134
|
+
render(<PhoneInput defaultCountry={null} onCountryChange={onCountryChange} />)
|
|
135
|
+
const input = phone()
|
|
136
|
+
input.focus()
|
|
137
|
+
typeAt(input, "+")
|
|
138
|
+
typeAt(input, "+3")
|
|
139
|
+
expect(trigger().getAttribute("aria-label")).toBe("Country: none selected")
|
|
140
|
+
typeAt(input, "+33")
|
|
141
|
+
expect(input.value).toBe("")
|
|
142
|
+
expect(trigger().getAttribute("aria-label")).toBe("Country: France +33")
|
|
143
|
+
expect(onCountryChange).toHaveBeenLastCalledWith("FR")
|
|
144
|
+
|
|
145
|
+
backspaceAtStart(input)
|
|
146
|
+
expect(input.value).toBe("+3")
|
|
147
|
+
expect(input.selectionStart).toBe(2)
|
|
148
|
+
expect(trigger().getAttribute("aria-label")).toBe("Country: none selected")
|
|
149
|
+
expect(onCountryChange).toHaveBeenLastCalledWith(null)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it("gives the code back whole when a number follows, and only re-collapses a finished code", () => {
|
|
153
|
+
render(<PhoneInput defaultCountry={null} />)
|
|
154
|
+
const input = phone()
|
|
155
|
+
input.focus()
|
|
156
|
+
typeAt(input, "+33612")
|
|
157
|
+
expect(input.value).toBe("6 12")
|
|
158
|
+
|
|
159
|
+
backspaceAtStart(input)
|
|
160
|
+
expect(input.value).toBe("+33 6 12")
|
|
161
|
+
expect(input.selectionStart).toBe(3)
|
|
162
|
+
expect(trigger().getAttribute("aria-label")).toBe("Country: none selected")
|
|
163
|
+
|
|
164
|
+
// The browser deletes the code's last 3: `+36` is Hungary, but the caret is inside the code,
|
|
165
|
+
// so it stays text instead of collapsing into a country nobody typed.
|
|
166
|
+
typeAt(input, "+3 6 12", 2)
|
|
167
|
+
expect(input.value.startsWith("+36")).toBe(true)
|
|
168
|
+
expect(input.selectionStart).toBe(2)
|
|
169
|
+
|
|
170
|
+
// Typing the 3 back finishes `+33`, which collapses to France again.
|
|
171
|
+
typeAt(input, "+33 6 1 2", 3)
|
|
172
|
+
expect(input.value).toBe("6 12")
|
|
173
|
+
expect(input.selectionStart).toBe(0)
|
|
174
|
+
expect(trigger().getAttribute("aria-label")).toBe("Country: France +33")
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it("resolves a shared code to its main country, then lets the digits refine it", () => {
|
|
178
|
+
render(<PhoneInput defaultCountry={null} />)
|
|
179
|
+
const input = phone()
|
|
180
|
+
input.focus()
|
|
181
|
+
typeAt(input, "+1")
|
|
182
|
+
expect(trigger().getAttribute("aria-label")).toBe("Country: United States +1")
|
|
183
|
+
typeAt(input, "2045550123")
|
|
184
|
+
expect(trigger().getAttribute("aria-label")).toBe("Country: Canada +1")
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it("never lets the digits override a country the user chose", () => {
|
|
188
|
+
render(<PhoneInput defaultCountry="US" />)
|
|
189
|
+
fireEvent.change(phone(), { target: { value: "2045550123" } })
|
|
190
|
+
expect(trigger().getAttribute("aria-label")).toBe("Country: United States +1")
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
describe("PhoneInput — placeholder", () => {
|
|
195
|
+
it("follows the selected country by default, and has none without one", () => {
|
|
196
|
+
const { rerender } = render(<PhoneInput country="FR" />)
|
|
197
|
+
expect(phone().placeholder).toBe("06 12 34 56 78")
|
|
198
|
+
rerender(<PhoneInput country="US" />)
|
|
199
|
+
expect(phone().placeholder).toBe("(201) 555-0123")
|
|
200
|
+
rerender(<PhoneInput country={null} />)
|
|
201
|
+
expect(phone().placeholder).toBe("")
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it("switches to the example of a country resolved from a typed code", () => {
|
|
205
|
+
render(<PhoneInput defaultCountry={null} />)
|
|
206
|
+
typeAt(phone(), "+44")
|
|
207
|
+
expect(phone().value).toBe("")
|
|
208
|
+
expect(phone().placeholder).toBe("07400 123456")
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
it("takes a fixed string, or a function of the country", () => {
|
|
212
|
+
const { rerender } = render(<PhoneInput country="FR" placeholder="" />)
|
|
213
|
+
expect(phone().placeholder).toBe("")
|
|
214
|
+
rerender(
|
|
215
|
+
<PhoneInput
|
|
216
|
+
country={null}
|
|
217
|
+
placeholder={(country) => (country ? undefined : "+ dial code")}
|
|
218
|
+
/>,
|
|
219
|
+
)
|
|
220
|
+
expect(phone().placeholder).toBe("+ dial code")
|
|
221
|
+
})
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
describe("PhoneInput — controlled", () => {
|
|
225
|
+
it("doesn't reformat the parent's echo of a keystroke", () => {
|
|
226
|
+
const Controlled = () => {
|
|
227
|
+
const [value, setValue] = useState<string | null>(null)
|
|
228
|
+
return <PhoneInput defaultCountry="FR" value={value} onChange={setValue} />
|
|
229
|
+
}
|
|
230
|
+
render(<Controlled />)
|
|
231
|
+
fireEvent.change(phone(), { target: { value: "06" } })
|
|
232
|
+
// E.164 "+336" would display as "6" or "+33 6" if it were re-parsed; the user typed "06".
|
|
233
|
+
expect(phone().value).toBe("06")
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it("replaces the text when the value changes from outside", () => {
|
|
237
|
+
const { rerender } = render(<PhoneInput value="+33612345678" onChange={() => {}} />)
|
|
238
|
+
expect(phone().value).toBe("06 12 34 56 78")
|
|
239
|
+
rerender(<PhoneInput value="+442079460958" onChange={() => {}} />)
|
|
240
|
+
expect(phone().value).toBe("020 7946 0958")
|
|
241
|
+
rerender(<PhoneInput value={null} onChange={() => {}} />)
|
|
242
|
+
expect(phone().value).toBe("")
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
describe("PhoneInput — field and form", () => {
|
|
247
|
+
it("binds the label to the input and flips aria-invalid from `error`", () => {
|
|
248
|
+
render(<PhoneInput label="Phone" error="Invalid number" defaultCountry="FR" />)
|
|
249
|
+
const input = screen.getByLabelText("Phone")
|
|
250
|
+
expect(input).toBe(phone())
|
|
251
|
+
expect(input.getAttribute("aria-invalid")).toBe("true")
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
it("submits the E.164 value under `name`", () => {
|
|
255
|
+
const { container } = render(<PhoneInput name="phone" defaultValue="+33612345678" />)
|
|
256
|
+
const hidden = container.querySelector<HTMLInputElement>('input[type="hidden"][name="phone"]')
|
|
257
|
+
expect(hidden?.value).toBe("+33612345678")
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
it("draws the divider only on the default variant", () => {
|
|
261
|
+
const { rerender } = render(<PhoneInput />)
|
|
262
|
+
expect(trigger().className).toContain("border-e")
|
|
263
|
+
rerender(<PhoneInput variant="unstyled" />)
|
|
264
|
+
expect(trigger().className).not.toContain("border-e")
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
it("lands `testId` on the input", () => {
|
|
268
|
+
render(<PhoneInput testId="phone" />)
|
|
269
|
+
expect(screen.getByTestId("phone")).toBe(phone())
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
it("locks the country picker when disabled or read-only", () => {
|
|
273
|
+
const { rerender } = render(<PhoneInput disabled />)
|
|
274
|
+
expect((trigger() as HTMLButtonElement).disabled).toBe(true)
|
|
275
|
+
rerender(<PhoneInput readOnly />)
|
|
276
|
+
expect((trigger() as HTMLButtonElement).disabled).toBe(true)
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
it("renders on the server with flag placeholders", () => {
|
|
280
|
+
const html = renderToStaticMarkup(<PhoneInput defaultValue="+33612345678" />)
|
|
281
|
+
expect(html).toContain('value="06 12 34 56 78"')
|
|
282
|
+
expect(html).toContain('data-flag="FR"')
|
|
283
|
+
expect(html).not.toContain('<svg viewBox="0 0 513 342"')
|
|
284
|
+
})
|
|
285
|
+
})
|