@charcuterie/ui 4.28.2 → 4.28.3
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/Avatar/Avatar.d.ts.map +1 -1
- package/dist/Avatar/Avatar.js +6 -15
- package/dist/Avatar/Avatar.js.map +1 -1
- package/dist/PortraitTiles/PortraitAvatar.d.ts +5 -0
- package/dist/PortraitTiles/PortraitAvatar.d.ts.map +1 -1
- package/dist/PortraitTiles/PortraitAvatar.js +9 -6
- package/dist/PortraitTiles/PortraitAvatar.js.map +1 -1
- package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.d.ts +29 -0
- package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.d.ts.map +1 -0
- package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.js +38 -0
- package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.js.map +1 -0
- package/dist/motion.testHelpers.d.ts +35 -0
- package/dist/motion.testHelpers.d.ts.map +1 -0
- package/dist/motion.testHelpers.js +44 -0
- package/dist/motion.testHelpers.js.map +1 -0
- package/dist/useImageFailure.d.ts +52 -0
- package/dist/useImageFailure.d.ts.map +1 -0
- package/dist/useImageFailure.js +71 -0
- package/dist/useImageFailure.js.map +1 -0
- package/dist/waitForImages.testHelpers.d.ts +33 -0
- package/dist/waitForImages.testHelpers.d.ts.map +1 -0
- package/dist/waitForImages.testHelpers.js +48 -0
- package/dist/waitForImages.testHelpers.js.map +1 -0
- package/package.json +1 -1
- package/src/Avatar/Avatar.test.tsx +54 -1
- package/src/Avatar/Avatar.tsx +7 -19
- package/src/GroupedList/GroupedList.test.tsx +22 -17
- package/src/Motion/useListMotion.test.tsx +21 -15
- package/src/Motion/usePresence.test.tsx +76 -24
- package/src/Motion/useValueChangeMotion.test.tsx +12 -9
- package/src/Overlay/overlayReturnFocus.test.tsx +18 -20
- package/src/PortraitTiles/PortraitAvatar.tsx +10 -5
- package/src/PortraitTiles/PortraitTiles.test.tsx +219 -17
- package/src/markdownEditorCodeMirror/MarkdownView.test.tsx +32 -11
- package/src/markdownEditorCodeMirror/finishParsing.testHelpers.ts +47 -0
- package/src/motion.testHelpers.ts +46 -0
- package/src/useImageFailure.ts +93 -0
- package/src/waitForImages.testHelpers.ts +61 -0
package/src/Avatar/Avatar.tsx
CHANGED
|
@@ -4,11 +4,11 @@ import type {
|
|
|
4
4
|
ComponentPropsWithRef,
|
|
5
5
|
ReactNode,
|
|
6
6
|
} from "react"
|
|
7
|
-
import { useState } from "react"
|
|
8
7
|
|
|
9
8
|
import { CATEGORICAL_APPEARANCE_CLASS } from "../categoricalStyles.ts"
|
|
10
9
|
import type { IntentAppearance } from "../intentStyles.ts"
|
|
11
10
|
import { toClassName } from "../toClassName.ts"
|
|
11
|
+
import { useImageFailure } from "../useImageFailure.ts"
|
|
12
12
|
|
|
13
13
|
export type AvatarSize = keyof typeof AVATAR_SIZE_CLASS
|
|
14
14
|
|
|
@@ -203,22 +203,12 @@ export const Avatar = ({
|
|
|
203
203
|
...spanProps
|
|
204
204
|
}: AvatarProps): ReactNode => {
|
|
205
205
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* effect syncing a prop into state — the shape this library
|
|
210
|
-
* refuses everywhere else
|
|
211
|
-
* ([decision](../../../docs/decisions/2026-07-29-logic-hooks-are-uncontrolled.md)).
|
|
212
|
-
* Storing the URL makes the comparison below derive the answer, so
|
|
213
|
-
* a second photo gets its own attempt and a re-render never
|
|
214
|
-
* resurrects a dead one.
|
|
206
|
+
* Keyed by the URL that failed, so a second photo gets its own
|
|
207
|
+
* attempt, and it also notices a photo that failed before a
|
|
208
|
+
* server render hydrated — see `useImageFailure`.
|
|
215
209
|
*/
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
>(undefined)
|
|
219
|
-
|
|
220
|
-
const hasImageError =
|
|
221
|
-
imageUrl !== undefined && failedImageUrl === imageUrl
|
|
210
|
+
const { hasFailed: hasImageError, imageProps } =
|
|
211
|
+
useImageFailure(imageUrl)
|
|
222
212
|
|
|
223
213
|
const trimmedName = name?.trim()
|
|
224
214
|
|
|
@@ -253,11 +243,9 @@ export const Avatar = ({
|
|
|
253
243
|
// accessible name, and a second copy on the image is how an
|
|
254
244
|
// avatar gets announced twice.
|
|
255
245
|
<img
|
|
246
|
+
{...imageProps}
|
|
256
247
|
alt=""
|
|
257
248
|
className="size-full object-cover"
|
|
258
|
-
onError={() => {
|
|
259
|
-
setFailedImageUrl(imageUrl)
|
|
260
|
-
}}
|
|
261
249
|
src={imageUrl}
|
|
262
250
|
/>
|
|
263
251
|
) : (
|
|
@@ -14,6 +14,10 @@ import { test } from "vitest"
|
|
|
14
14
|
import { userEvent as browserUserEvent } from "vitest/browser"
|
|
15
15
|
|
|
16
16
|
import { expectNoAxeViolations } from "../expectNoAxeViolations.testHelpers.ts"
|
|
17
|
+
import {
|
|
18
|
+
finishMotion,
|
|
19
|
+
HELD_MOTION,
|
|
20
|
+
} from "../motion.testHelpers.ts"
|
|
17
21
|
import { mountStory } from "../mountStory.testHelpers.ts"
|
|
18
22
|
import { expectAgentDrivable } from "../testing/index.ts"
|
|
19
23
|
import meta, * as stories from "./GroupedList.stories.tsx"
|
|
@@ -851,9 +855,10 @@ test("a group an action creates enters, and a group it empties leaves with its l
|
|
|
851
855
|
|
|
852
856
|
const host = document.createElement("div")
|
|
853
857
|
|
|
854
|
-
//
|
|
855
|
-
|
|
856
|
-
host.style.setProperty("--duration-
|
|
858
|
+
// Held, so the exit cannot finish first however busy the host is;
|
|
859
|
+
// see `HELD_MOTION`.
|
|
860
|
+
host.style.setProperty("--duration-fast", HELD_MOTION)
|
|
861
|
+
host.style.setProperty("--duration-normal", HELD_MOTION)
|
|
857
862
|
|
|
858
863
|
document.body.append(host)
|
|
859
864
|
|
|
@@ -912,12 +917,11 @@ test("a group an action creates enters, and a group it empties leaves with its l
|
|
|
912
917
|
expect(leaving?.textContent).toContain("Book")
|
|
913
918
|
|
|
914
919
|
// …and gone once it has.
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
)
|
|
920
|
+
finishMotion(leaving as HTMLElement)
|
|
921
|
+
|
|
922
|
+
await waitFor(() => {
|
|
923
|
+
expect(groupOf("Reading")).toBeUndefined()
|
|
924
|
+
})
|
|
921
925
|
} finally {
|
|
922
926
|
root.unmount()
|
|
923
927
|
|
|
@@ -938,8 +942,8 @@ const mountUnfrozen = () => {
|
|
|
938
942
|
|
|
939
943
|
const host = document.createElement("div")
|
|
940
944
|
|
|
941
|
-
host.style.setProperty("--duration-fast",
|
|
942
|
-
host.style.setProperty("--duration-normal",
|
|
945
|
+
host.style.setProperty("--duration-fast", HELD_MOTION)
|
|
946
|
+
host.style.setProperty("--duration-normal", HELD_MOTION)
|
|
943
947
|
|
|
944
948
|
document.body.append(host)
|
|
945
949
|
|
|
@@ -1049,12 +1053,13 @@ test("a group below one whose row has finished leaving slides up instead of jump
|
|
|
1049
1053
|
// The leaving row still holds its space, so nothing has moved yet.
|
|
1050
1054
|
expect(group.style.transition).toBe("")
|
|
1051
1055
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1056
|
+
// Only the leaving row's motion ends; the slide it starts is held,
|
|
1057
|
+
// so it is still in flight when the next line reads it.
|
|
1058
|
+
finishMotion(leaving)
|
|
1059
|
+
|
|
1060
|
+
await waitFor(() => {
|
|
1061
|
+
expect(leaving.isConnected).toBe(false)
|
|
1062
|
+
})
|
|
1058
1063
|
|
|
1059
1064
|
// Its gap closed, and the group below is sliding up into it.
|
|
1060
1065
|
expect(group.style.transition).toContain("translate")
|
|
@@ -5,6 +5,10 @@ import { createRoot } from "react-dom/client"
|
|
|
5
5
|
import { expect, userEvent, waitFor } from "storybook/test"
|
|
6
6
|
import { afterEach, beforeEach, test } from "vitest"
|
|
7
7
|
|
|
8
|
+
import {
|
|
9
|
+
finishMotion,
|
|
10
|
+
HELD_MOTION,
|
|
11
|
+
} from "../motion.testHelpers.ts"
|
|
8
12
|
import { useListMotion } from "./useListMotion.ts"
|
|
9
13
|
|
|
10
14
|
/**
|
|
@@ -33,15 +37,6 @@ afterEach(() => {
|
|
|
33
37
|
}
|
|
34
38
|
})
|
|
35
39
|
|
|
36
|
-
/**
|
|
37
|
-
* Long enough that a loaded test host cannot finish an exit or a
|
|
38
|
-
* slide between two lines of a test. The tokens are inherited, so
|
|
39
|
-
* setting them on the host slows every motion inside it.
|
|
40
|
-
*/
|
|
41
|
-
const SLOW_MOTION = "600ms"
|
|
42
|
-
|
|
43
|
-
const MOTION_TIMEOUT = { timeout: 5_000 }
|
|
44
|
-
|
|
45
40
|
const unfreeze = () => {
|
|
46
41
|
frozenStyle?.remove()
|
|
47
42
|
}
|
|
@@ -181,7 +176,10 @@ const mount = (node: ReactNode) => {
|
|
|
181
176
|
"--duration-normal",
|
|
182
177
|
"--duration-slow",
|
|
183
178
|
]) {
|
|
184
|
-
|
|
179
|
+
// Held, so no motion can end between two lines of a test however
|
|
180
|
+
// long a click takes; see `HELD_MOTION`. The tokens are inherited,
|
|
181
|
+
// so setting them on the host holds every motion inside it.
|
|
182
|
+
host.style.setProperty(token, HELD_MOTION)
|
|
185
183
|
}
|
|
186
184
|
|
|
187
185
|
document.body.append(host)
|
|
@@ -247,9 +245,11 @@ test("a removed item stays, inert, at its index until its exit ends", async () =
|
|
|
247
245
|
expect(alpha).toHaveAttribute("aria-hidden", "true")
|
|
248
246
|
expect(host.querySelector("li")).toBe(alpha)
|
|
249
247
|
|
|
248
|
+
finishMotion(host)
|
|
249
|
+
|
|
250
250
|
await waitFor(() => {
|
|
251
251
|
expect(alpha.isConnected).toBe(false)
|
|
252
|
-
}
|
|
252
|
+
})
|
|
253
253
|
})
|
|
254
254
|
|
|
255
255
|
test("with motion frozen, a removed item is gone in the same commit", async () => {
|
|
@@ -285,9 +285,11 @@ test("a reorder slides each moved item from where it was", async () => {
|
|
|
285
285
|
// element sits away from its laid-out place.
|
|
286
286
|
expect(alpha.style.transition).toContain("translate")
|
|
287
287
|
|
|
288
|
+
finishMotion(host)
|
|
289
|
+
|
|
288
290
|
await waitFor(() => {
|
|
289
291
|
expect(alpha.style.transition).toBe("")
|
|
290
|
-
}
|
|
292
|
+
})
|
|
291
293
|
})
|
|
292
294
|
|
|
293
295
|
test("an added item loses its enter class when it has entered, so showing the list again does not replay it", async () => {
|
|
@@ -311,9 +313,11 @@ test("an added item loses its enter class when it has entered, so showing the li
|
|
|
311
313
|
return found as HTMLElement
|
|
312
314
|
})
|
|
313
315
|
|
|
316
|
+
finishMotion(host)
|
|
317
|
+
|
|
314
318
|
await waitFor(() => {
|
|
315
319
|
expect(delta).not.toHaveClass("charcuterie-item-enter")
|
|
316
|
-
}
|
|
320
|
+
})
|
|
317
321
|
|
|
318
322
|
// Hidden and shown again, with a style flush at each step, which is
|
|
319
323
|
// what restarts a CSS animation still named on the element.
|
|
@@ -444,9 +448,11 @@ test("two items removed one after the other keep their order while they leave",
|
|
|
444
448
|
"Delta",
|
|
445
449
|
])
|
|
446
450
|
|
|
451
|
+
finishMotion(host)
|
|
452
|
+
|
|
447
453
|
await waitFor(() => {
|
|
448
454
|
expect(shownOrder(host)).toEqual(["Alpha", "Delta"])
|
|
449
|
-
}
|
|
455
|
+
})
|
|
450
456
|
})
|
|
451
457
|
|
|
452
458
|
test("a leaving item that a reorder moves slides from where it was, instead of jumping", async () => {
|
|
@@ -503,7 +509,7 @@ test("an item that moves while it is still entering slides from where it is show
|
|
|
503
509
|
|
|
504
510
|
const topBefore = delta.getBoundingClientRect().top
|
|
505
511
|
|
|
506
|
-
// Still entering (the motion is
|
|
512
|
+
// Still entering (the motion is held here), and moved to the top.
|
|
507
513
|
await userEvent.click(getButton(host, "Reverse"))
|
|
508
514
|
|
|
509
515
|
expect(shownOrder(host)[0]).toBe("Delta")
|
|
@@ -5,6 +5,10 @@ import { afterEach, beforeEach, test } from "vitest"
|
|
|
5
5
|
import * as accordionStories from "../Accordion/Accordion.stories.tsx"
|
|
6
6
|
import * as menuStories from "../Menu/Menu.stories.tsx"
|
|
7
7
|
import * as modalStories from "../Modal/Modal.stories.tsx"
|
|
8
|
+
import {
|
|
9
|
+
finishMotion,
|
|
10
|
+
HELD_MOTION,
|
|
11
|
+
} from "../motion.testHelpers.ts"
|
|
8
12
|
import { mountStory } from "../mountStory.testHelpers.ts"
|
|
9
13
|
import { getAnimationLengthMs } from "./usePresence.ts"
|
|
10
14
|
|
|
@@ -23,26 +27,56 @@ const { Playground: AccordionPlayground } = composeStories(
|
|
|
23
27
|
* is what keeps every other overlay test synchronous. These tests are
|
|
24
28
|
* about the motion itself, so they lift the freeze for their own
|
|
25
29
|
* duration and put it back after.
|
|
30
|
+
*
|
|
31
|
+
* And they **hold** it: every duration token is an hour on `<body>`,
|
|
32
|
+
* which the canvas and the portalled overlays both inherit from, so
|
|
33
|
+
* no enter or exit can end between two lines of a test however long
|
|
34
|
+
* a click takes (see `HELD_MOTION`). A test that needs one over ends
|
|
35
|
+
* it with `finishMotion`.
|
|
26
36
|
*/
|
|
27
37
|
const FREEZE_ID = "charcuterie-freeze-motion"
|
|
28
38
|
|
|
39
|
+
const DURATION_TOKENS = [
|
|
40
|
+
"--duration-fast",
|
|
41
|
+
"--duration-normal",
|
|
42
|
+
"--duration-slow",
|
|
43
|
+
]
|
|
44
|
+
|
|
29
45
|
let frozenStyle: HTMLElement | null = null
|
|
30
46
|
|
|
31
47
|
beforeEach(() => {
|
|
32
48
|
frozenStyle = document.getElementById(FREEZE_ID)
|
|
33
49
|
|
|
34
50
|
frozenStyle?.remove()
|
|
51
|
+
|
|
52
|
+
for (const token of DURATION_TOKENS) {
|
|
53
|
+
document.body.style.setProperty(token, HELD_MOTION)
|
|
54
|
+
}
|
|
35
55
|
})
|
|
36
56
|
|
|
37
57
|
afterEach(() => {
|
|
58
|
+
for (const token of DURATION_TOKENS) {
|
|
59
|
+
document.body.style.removeProperty(token)
|
|
60
|
+
}
|
|
61
|
+
|
|
38
62
|
if (frozenStyle !== null) {
|
|
39
63
|
document.head.append(frozenStyle)
|
|
40
64
|
}
|
|
41
65
|
})
|
|
42
66
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Two animation frames: whatever the last event scheduled, React has
|
|
69
|
+
* committed. A barrier tied to the browser's own frames, as in
|
|
70
|
+
* `mountStory`, rather than a millisecond count.
|
|
71
|
+
*/
|
|
72
|
+
const settleFrames = () =>
|
|
73
|
+
new Promise<void>((resolve) => {
|
|
74
|
+
globalThis.requestAnimationFrame(() => {
|
|
75
|
+
globalThis.requestAnimationFrame(() => {
|
|
76
|
+
resolve()
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
})
|
|
46
80
|
|
|
47
81
|
test("the animation length is the longest delay plus duration, and zero with no animation", () => {
|
|
48
82
|
const element = document.createElement("div")
|
|
@@ -76,10 +110,6 @@ test("a closing modal stays in the page, closed to everything but the eye, until
|
|
|
76
110
|
|
|
77
111
|
expect(modal).toHaveClass("charcuterie-overlay-enter")
|
|
78
112
|
|
|
79
|
-
// Long enough that a loaded host cannot finish the exit between two
|
|
80
|
-
// lines of this test. The inline longhand beats the class's.
|
|
81
|
-
modal.style.animationDuration = SLOW_EXIT
|
|
82
|
-
|
|
83
113
|
await userEvent.keyboard("{Escape}")
|
|
84
114
|
|
|
85
115
|
// Already gone to a role query, the keyboard, and the pointer…
|
|
@@ -95,9 +125,11 @@ test("a closing modal stays in the page, closed to everything but the eye, until
|
|
|
95
125
|
// But still painted, until the exit animation finishes.
|
|
96
126
|
expect(modal.isConnected).toBe(true)
|
|
97
127
|
|
|
128
|
+
finishMotion(modal)
|
|
129
|
+
|
|
98
130
|
await waitFor(() => {
|
|
99
131
|
expect(modal.isConnected).toBe(false)
|
|
100
|
-
}
|
|
132
|
+
})
|
|
101
133
|
})
|
|
102
134
|
|
|
103
135
|
test("a modal re-opened during its exit stays open", async () => {
|
|
@@ -111,8 +143,6 @@ test("a modal re-opened during its exit stays open", async () => {
|
|
|
111
143
|
|
|
112
144
|
const modal = body.getByRole("dialog")
|
|
113
145
|
|
|
114
|
-
modal.style.animationDuration = SLOW_EXIT
|
|
115
|
-
|
|
116
146
|
await userEvent.keyboard("{Escape}")
|
|
117
147
|
|
|
118
148
|
expect(modal).toHaveClass("charcuterie-overlay-exit")
|
|
@@ -127,21 +157,41 @@ test("a modal re-opened during its exit stays open", async () => {
|
|
|
127
157
|
|
|
128
158
|
expect(modal).toHaveClass("charcuterie-overlay-enter")
|
|
129
159
|
|
|
130
|
-
|
|
131
|
-
|
|
160
|
+
// The re-open's own enter ends, which is the `animationend` an
|
|
161
|
+
// abandoned exit listener would mistake for its own. The listener
|
|
162
|
+
// here is added after the hook's, so it runs after any handler the
|
|
163
|
+
// hook still has; two frames then let React commit what it did.
|
|
164
|
+
const enterEnded = new Promise((resolve) => {
|
|
165
|
+
modal.addEventListener("animationend", resolve, {
|
|
166
|
+
once: true,
|
|
167
|
+
})
|
|
132
168
|
})
|
|
133
169
|
|
|
134
|
-
|
|
170
|
+
finishMotion(modal)
|
|
171
|
+
|
|
172
|
+
await enterEnded
|
|
135
173
|
|
|
136
|
-
|
|
137
|
-
// page before the next test mounts into it.
|
|
138
|
-
modal.style.animationDuration = ""
|
|
174
|
+
await settleFrames()
|
|
139
175
|
|
|
176
|
+
expect(modal.isConnected).toBe(true)
|
|
177
|
+
|
|
178
|
+
// Closed again. This exit has to run in full: an abandoned exit
|
|
179
|
+
// listener that heard the enter end has already marked the modal
|
|
180
|
+
// done, and it would vanish here at once, with no exit at all.
|
|
181
|
+
// (`isMounted` is `isVisible || isShown`, so while it was open the
|
|
182
|
+
// assertion above could not see that.)
|
|
140
183
|
await userEvent.keyboard("{Escape}")
|
|
141
184
|
|
|
185
|
+
expect(modal.isConnected).toBe(true)
|
|
186
|
+
expect(modal).toHaveClass("charcuterie-overlay-exit")
|
|
187
|
+
|
|
188
|
+
// And gone, so its focus manager has let go of the page before the
|
|
189
|
+
// next test mounts into it.
|
|
190
|
+
finishMotion(modal)
|
|
191
|
+
|
|
142
192
|
await waitFor(() => {
|
|
143
193
|
expect(modal.isConnected).toBe(false)
|
|
144
|
-
}
|
|
194
|
+
})
|
|
145
195
|
})
|
|
146
196
|
|
|
147
197
|
test("an anchored menu grows out of its trigger and leaves with motion", async () => {
|
|
@@ -154,16 +204,16 @@ test("an anchored menu grows out of its trigger and leaves with motion", async (
|
|
|
154
204
|
expect(menu).toHaveClass("charcuterie-overlay-enter")
|
|
155
205
|
expect(menu.style.transformOrigin).not.toBe("")
|
|
156
206
|
|
|
157
|
-
menu.style.animationDuration = SLOW_EXIT
|
|
158
|
-
|
|
159
207
|
await userEvent.keyboard("{Escape}")
|
|
160
208
|
|
|
161
209
|
expect(body.queryByRole("menu")).toBeNull()
|
|
162
210
|
expect(menu).toHaveClass("charcuterie-overlay-exit")
|
|
163
211
|
|
|
212
|
+
finishMotion(menu)
|
|
213
|
+
|
|
164
214
|
await waitFor(() => {
|
|
165
215
|
expect(menu.isConnected).toBe(false)
|
|
166
|
-
}
|
|
216
|
+
})
|
|
167
217
|
})
|
|
168
218
|
|
|
169
219
|
test("an accordion section stays shown while it collapses, then hides", async () => {
|
|
@@ -182,8 +232,6 @@ test("an accordion section stays shown while it collapses, then hides", async ()
|
|
|
182
232
|
expect(panel).not.toBeNull()
|
|
183
233
|
expect(panel).not.toHaveAttribute("hidden")
|
|
184
234
|
|
|
185
|
-
panel?.style.setProperty("animation-duration", SLOW_EXIT)
|
|
186
|
-
|
|
187
235
|
await userEvent.click(firstHeader)
|
|
188
236
|
|
|
189
237
|
// `interpolate-size` is Chromium's, which is what this suite runs.
|
|
@@ -191,9 +239,11 @@ test("an accordion section stays shown while it collapses, then hides", async ()
|
|
|
191
239
|
expect(panel).not.toHaveAttribute("hidden")
|
|
192
240
|
expect(panel).toHaveAttribute("inert")
|
|
193
241
|
|
|
242
|
+
finishMotion(panel as HTMLElement)
|
|
243
|
+
|
|
194
244
|
await waitFor(() => {
|
|
195
245
|
expect(panel).toHaveAttribute("hidden")
|
|
196
|
-
}
|
|
246
|
+
})
|
|
197
247
|
})
|
|
198
248
|
|
|
199
249
|
test("an accordion section drops its open class when it has opened", async () => {
|
|
@@ -213,11 +263,13 @@ test("an accordion section drops its open class when it has opened", async () =>
|
|
|
213
263
|
|
|
214
264
|
// Off once it has opened, so showing an ancestor again does not
|
|
215
265
|
// replay it, and its `overflow: clip` no longer clips the content.
|
|
266
|
+
finishMotion(panel)
|
|
267
|
+
|
|
216
268
|
await waitFor(() => {
|
|
217
269
|
expect(panel).not.toHaveClass(
|
|
218
270
|
"charcuterie-disclosure-enter",
|
|
219
271
|
)
|
|
220
|
-
}
|
|
272
|
+
})
|
|
221
273
|
|
|
222
274
|
expect(panel).not.toHaveAttribute("hidden")
|
|
223
275
|
})
|
|
@@ -5,6 +5,10 @@ import { createRoot } from "react-dom/client"
|
|
|
5
5
|
import { expect, userEvent, waitFor } from "storybook/test"
|
|
6
6
|
import { afterEach, beforeEach, test } from "vitest"
|
|
7
7
|
|
|
8
|
+
import {
|
|
9
|
+
finishMotion,
|
|
10
|
+
HELD_MOTION,
|
|
11
|
+
} from "../motion.testHelpers.ts"
|
|
8
12
|
import { useValueChangeMotion } from "./useValueChangeMotion.ts"
|
|
9
13
|
|
|
10
14
|
/**
|
|
@@ -39,9 +43,9 @@ afterEach(() => {
|
|
|
39
43
|
const mount = (node: ReactNode) => {
|
|
40
44
|
const host = document.createElement("div")
|
|
41
45
|
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
host.style.setProperty("--duration-slow",
|
|
46
|
+
// Held, so no pop can end between two lines of a test however long
|
|
47
|
+
// a click takes; see `HELD_MOTION`.
|
|
48
|
+
host.style.setProperty("--duration-slow", HELD_MOTION)
|
|
45
49
|
|
|
46
50
|
document.body.append(host)
|
|
47
51
|
|
|
@@ -122,10 +126,9 @@ test("the pop class comes off when the pop ends", async () => {
|
|
|
122
126
|
|
|
123
127
|
expect(output).toHaveClass("charcuterie-value-changed")
|
|
124
128
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
)
|
|
129
|
+
finishMotion(output)
|
|
130
|
+
|
|
131
|
+
await waitFor(() => {
|
|
132
|
+
expect(output.className).toBe("")
|
|
133
|
+
})
|
|
131
134
|
})
|
|
@@ -3,7 +3,7 @@ import type { Root } from "react-dom/client"
|
|
|
3
3
|
import { createRoot } from "react-dom/client"
|
|
4
4
|
import { expect, userEvent, waitFor } from "storybook/test"
|
|
5
5
|
import { afterEach, beforeEach, test } from "vitest"
|
|
6
|
-
|
|
6
|
+
import { finishMotion } from "../motion.testHelpers.ts"
|
|
7
7
|
import {
|
|
8
8
|
DeleteRowWithConfirm,
|
|
9
9
|
MenuThenModal,
|
|
@@ -128,13 +128,13 @@ test("a modal opened from a menu item returns focus to the menu's trigger, once
|
|
|
128
128
|
})
|
|
129
129
|
|
|
130
130
|
// The menu has finished leaving, so the item that opened the modal
|
|
131
|
-
// is gone from the page.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
)
|
|
131
|
+
// is gone from the page. Ended here rather than waited for: the
|
|
132
|
+
// test is about focus after the exit, not about how long it takes.
|
|
133
|
+
finishMotion(document.body)
|
|
134
|
+
|
|
135
|
+
await waitFor(() => {
|
|
136
|
+
expect(item.isConnected).toBe(false)
|
|
137
|
+
})
|
|
138
138
|
|
|
139
139
|
await userEvent.keyboard("{Escape}")
|
|
140
140
|
|
|
@@ -165,12 +165,11 @@ test("a modal that replaced another returns focus to the first one's opener", as
|
|
|
165
165
|
})
|
|
166
166
|
|
|
167
167
|
// The first modal has finished leaving, and "Next" with it.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
)
|
|
168
|
+
finishMotion(document.body)
|
|
169
|
+
|
|
170
|
+
await waitFor(() => {
|
|
171
|
+
expect(next.isConnected).toBe(false)
|
|
172
|
+
})
|
|
174
173
|
|
|
175
174
|
await userEvent.keyboard("{Escape}")
|
|
176
175
|
|
|
@@ -208,12 +207,11 @@ test("a modal that opened while nothing had focus leaves focus where it was when
|
|
|
208
207
|
|
|
209
208
|
await userEvent.keyboard("{Escape}")
|
|
210
209
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
)
|
|
210
|
+
finishMotion(document.body)
|
|
211
|
+
|
|
212
|
+
await waitFor(() => {
|
|
213
|
+
expect(getButton("Inside timer")).toBeUndefined()
|
|
214
|
+
})
|
|
217
215
|
|
|
218
216
|
expect(search).not.toHaveFocus()
|
|
219
217
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react"
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { useImageFailure } from "../useImageFailure.ts"
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The face, and the one piece of this component that holds state.
|
|
@@ -11,6 +12,11 @@ import { useState } from "react"
|
|
|
11
12
|
* network stripped — so the fallback the caller already supplied for
|
|
12
13
|
* "no picture" covers "no picture *today*" as well.
|
|
13
14
|
*
|
|
15
|
+
* The failure is keyed by URL, so a tile whose photo failed tries
|
|
16
|
+
* again when the caller passes a new one, and a photo that failed
|
|
17
|
+
* before a server render hydrated is noticed too — see
|
|
18
|
+
* `useImageFailure`.
|
|
19
|
+
*
|
|
14
20
|
* Its own component because the state is per portrait. Hoisting it
|
|
15
21
|
* to a `Record<string, boolean>` in the set would re-render every
|
|
16
22
|
* tile whenever any one image failed.
|
|
@@ -24,7 +30,8 @@ export const PortraitAvatar = ({
|
|
|
24
30
|
imageSrc: string | undefined
|
|
25
31
|
initials: ReactNode
|
|
26
32
|
}): ReactNode => {
|
|
27
|
-
const
|
|
33
|
+
const { hasFailed: isImageBroken, imageProps } =
|
|
34
|
+
useImageFailure(imageSrc)
|
|
28
35
|
|
|
29
36
|
if (imageSrc === undefined || isImageBroken) {
|
|
30
37
|
return (
|
|
@@ -36,13 +43,11 @@ export const PortraitAvatar = ({
|
|
|
36
43
|
|
|
37
44
|
return (
|
|
38
45
|
<img
|
|
46
|
+
{...imageProps}
|
|
39
47
|
// The name is beside it, inside the same tile, so an alt here
|
|
40
48
|
// is the name announced twice.
|
|
41
49
|
alt=""
|
|
42
50
|
className={className}
|
|
43
|
-
onError={() => {
|
|
44
|
-
setIsImageBroken(true)
|
|
45
|
-
}}
|
|
46
51
|
src={imageSrc}
|
|
47
52
|
/>
|
|
48
53
|
)
|