|
1 | 1 | import { ProjectId, type PullRequestSummary, type VcsStatusResult } from "@t3tools/contracts"; |
2 | 2 | import { describe, expect, it } from "@effect/vitest"; |
| 3 | +import type { AnimationEvent } from "react"; |
3 | 4 |
|
4 | 5 | import { |
5 | 6 | ChangeRequestStatusIcon, |
6 | 7 | prStatusIndicator, |
7 | 8 | resolveThreadPullRequestBadgePresentation, |
| 9 | + synchronizeTerminalPulse, |
8 | 10 | } from "./ThreadStatusIndicators"; |
9 | 11 | import { newestPullRequestSummary } from "../state/pullRequests"; |
10 | 12 | import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons"; |
11 | 13 |
|
| 14 | +describe("synchronizeTerminalPulse", () => { |
| 15 | + function animationStartEvent(animations: Animation[], animationName = "status-pulse") { |
| 16 | + return { |
| 17 | + animationName, |
| 18 | + currentTarget: { getAnimations: () => animations }, |
| 19 | + } as AnimationEvent<SVGSVGElement>; |
| 20 | + } |
| 21 | + |
| 22 | + it("aligns terminal pulses started at different times to the same document clock", () => { |
| 23 | + const first = { animationName: "status-pulse", startTime: 125 } as CSSAnimation; |
| 24 | + const later = { animationName: "status-pulse", startTime: 975 } as CSSAnimation; |
| 25 | + |
| 26 | + synchronizeTerminalPulse(animationStartEvent([first])); |
| 27 | + synchronizeTerminalPulse(animationStartEvent([later])); |
| 28 | + |
| 29 | + expect([first.startTime, later.startTime]).toEqual([0, 0]); |
| 30 | + }); |
| 31 | + |
| 32 | + it("does not change other CSS or Web Animations on the icon", () => { |
| 33 | + const pulse = { animationName: "status-pulse", startTime: 975 } as CSSAnimation; |
| 34 | + const otherCss = { animationName: "other-animation", startTime: 125 } as CSSAnimation; |
| 35 | + const otherAnimation = { startTime: 250 } as Animation; |
| 36 | + |
| 37 | + synchronizeTerminalPulse(animationStartEvent([pulse, otherCss, otherAnimation])); |
| 38 | + |
| 39 | + expect(pulse.startTime).toBe(0); |
| 40 | + expect(otherCss.startTime).toBe(125); |
| 41 | + expect(otherAnimation.startTime).toBe(250); |
| 42 | + }); |
| 43 | + |
| 44 | + it("ignores the start of another animation", () => { |
| 45 | + const pulse = { animationName: "status-pulse", startTime: 975 } as CSSAnimation; |
| 46 | + |
| 47 | + synchronizeTerminalPulse(animationStartEvent([pulse], "other-animation")); |
| 48 | + |
| 49 | + expect(pulse.startTime).toBe(975); |
| 50 | + }); |
| 51 | +}); |
| 52 | + |
12 | 53 | describe("ChangeRequestStatusIcon", () => { |
13 | 54 | it.each([ |
14 | 55 | ["open", "open", false, PullRequestGlyph.pullRequest], |
|
0 commit comments