Skip to content

Commit a04aae5

Browse files
loganjLarry
andauthored
test(browser): hold motion when it commits, not on its start event (#459)
Signed-off-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
1 parent 6de1ab4 commit a04aae5

2 files changed

Lines changed: 47 additions & 17 deletions

File tree

‎tests/browser/mentions.spec.mjs‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -641,15 +641,34 @@ test("namesake recipient qualifiers remain visible on touch after live name chan
641641
const labels = keys.map((key) => `@Honey · ${npubEncode(key).slice(-4)}`);
642642
await expect(chips).toHaveText(["@Honey", "@Other Honey"]);
643643
await page.emulateMedia({ reducedMotion: "no-preference" });
644+
// Hold each reveal when its qualifier renders, before any frame. WebKit can
645+
// dispatch animationstart after the 220ms reveal has already finished.
644646
await page.evaluate(() => {
645647
window.qualifierReveals = [];
646-
document.addEventListener("animationstart", (event) => {
647-
if (event.animationName !== "inline-chip-qualifier-reveal") return;
648-
window.qualifierReveals.push(event.target);
649-
for (const animation of event.target.getAnimations()) {
650-
animation.pause();
651-
animation.currentTime = 0;
648+
new MutationObserver(() => {
649+
for (const element of document.querySelectorAll(
650+
".inline-chip-qualifier[data-reveal]",
651+
)) {
652+
if (window.qualifierReveals.includes(element)) continue;
653+
// getAnimations() flushes style, so the reveal animation exists.
654+
const reveals = element
655+
.getAnimations()
656+
.filter(
657+
(animation) =>
658+
animation.animationName === "inline-chip-qualifier-reveal",
659+
);
660+
if (!reveals.length) continue;
661+
window.qualifierReveals.push(element);
662+
for (const animation of reveals) {
663+
animation.pause();
664+
animation.currentTime = 0;
665+
}
652666
}
667+
}).observe(document.body, {
668+
attributes: true,
669+
attributeFilter: ["data-reveal"],
670+
childList: true,
671+
subtree: true,
653672
});
654673
});
655674
await page.evaluate(() => window.mentionFixture.collide(true));

‎tests/browser/sidenav-polish.spec.mjs‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -415,27 +415,38 @@ test("shell toggle restores the shared sidebar for Channels and Agents", async (
415415
});
416416
expect(openGap).toBe(gutterWidth);
417417
// Seek a paused real transition so runner speed cannot hide an immediate jump.
418+
// Pause it when the toggle commits, before any frame: transitionrun arrives in
419+
// a later frame, and a stalled WebKit frame can finish the 220ms transition
420+
// first. Descendant transitions (the resize help) also bubble transitionrun.
418421
for (const label of ["Hide Channel sidebar", "Show Channel sidebar"]) {
419422
const samples = await page.evaluate(async (label) => {
420423
const nav = document.querySelector("#shell-navigation");
421424
const button = document.querySelector(`button[aria-label="${label}"]`);
422-
const started = new Promise((resolve) => {
423-
nav.addEventListener("transitionrun", resolve, { once: true });
425+
const committed = new Promise((resolve) => {
426+
const observer = new MutationObserver(() => {
427+
observer.disconnect();
428+
// getAnimations() flushes style, so the toggle's transitions exist.
429+
const transitions = nav.getAnimations();
430+
for (const transition of transitions) transition.pause();
431+
resolve(transitions);
432+
});
433+
observer.observe(nav, {
434+
attributes: true,
435+
attributeFilter: ["aria-hidden"],
436+
});
424437
});
425438
button.click();
426-
await started;
427-
const animation = nav
428-
.getAnimations()
429-
.find((animation) => animation.transitionProperty === "max-width");
439+
const transitions = await committed;
440+
const animation = transitions.find(
441+
(animation) => animation.transitionProperty === "max-width",
442+
);
430443
if (!animation) throw new Error("Missing sidebar transition");
431-
animation.pause();
432444
try {
433445
const duration = animation.effect.getTiming().duration;
434-
const clipping = nav
435-
.getAnimations()
436-
.find((animation) => animation.transitionProperty === "clip-path");
446+
const clipping = transitions.find(
447+
(animation) => animation.transitionProperty === "clip-path",
448+
);
437449
if (!clipping) throw new Error("Missing containment transition");
438-
clipping.pause();
439450
try {
440451
return [0, 0.25, 0.5, 0.75, 1].map((progress) => {
441452
animation.currentTime = duration * progress;

0 commit comments

Comments
 (0)