Skip to content

Commit 1293c67

Browse files
rrewllclaude
andcommitted
test(webview): keep infinite CSS animations running across theme switches
applyVisualTheme finishes only CSS transitions, because finish() throws on an infinite animation. Add an infinite animation to the visual theme test and check that it is still running after the theme switch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8e7487a commit 1293c67

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

‎webview-ui/src/components/ui/__tests__/VisualTheme.visual.tsx‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,41 @@ test("finishes theme color transitions before contrast checks read them", async
1515
})
1616
expect(transitionDuration).toBe("10s")
1717

18+
// finish() throws on an infinite animation, so the theme switch must leave CSS animations running.
19+
await page.evaluate(() => {
20+
const style = document.createElement("style")
21+
style.id = "visual-theme-infinite-animation"
22+
style.textContent =
23+
"@keyframes visual-theme-pulse { to { opacity: 0.5; } }" +
24+
"#visual-theme-infinite-animation-probe { animation: visual-theme-pulse 1s infinite; }"
25+
const probe = document.createElement("div")
26+
probe.id = "visual-theme-infinite-animation-probe"
27+
document.head.append(style)
28+
document.body.append(probe)
29+
})
30+
1831
// The gallery starts in the dark theme, so this switch starts the Button border-color transition.
1932
await applyVisualTheme(
2033
page,
2134
visualThemes.find((theme) => theme.name === "high-contrast-light")!,
2235
)
2336

24-
const runningTransitions = await page.evaluate(
25-
() =>
26-
document
27-
.getAnimations()
28-
.filter((animation) => animation instanceof CSSTransition && animation.playState === "running").length,
29-
)
37+
const { runningTransitions, runningAnimations } = await page.evaluate(() => {
38+
const running = document.getAnimations().filter((animation) => animation.playState === "running")
39+
return {
40+
runningTransitions: running.filter((animation) => animation instanceof CSSTransition).length,
41+
runningAnimations: running.filter(
42+
(animation) => animation instanceof CSSAnimation && animation.animationName === "visual-theme-pulse",
43+
).length,
44+
}
45+
})
3046
expect(runningTransitions).toBe(0)
47+
expect(runningAnimations).toBe(1)
3148
// Read once instead of toHaveCSS, which retries until the transition ends on its own.
3249
expect(await action.evaluate((element) => getComputedStyle(element).borderTopColor)).toBe("rgb(15, 74, 133)")
50+
51+
await page.evaluate(() => {
52+
document.getElementById("visual-theme-infinite-animation")?.remove()
53+
document.getElementById("visual-theme-infinite-animation-probe")?.remove()
54+
})
3355
})

0 commit comments

Comments
 (0)