1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import { act, render, screen } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
phraseIntervalMs,
WorkingIndicator,
workingPhrases,
} from "./WorkingIndicator";
describe("WorkingIndicator", () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
it("shows the first working phrase with a spinner", () => {
const { container } = render(<WorkingIndicator />);
expect(screen.getByText(workingPhrases[0])).toBeDefined();
expect(container.querySelector(".spinner")).not.toBeNull();
});
it("rotates to the next phrase after the interval", () => {
render(<WorkingIndicator />);
act(() => {
vi.advanceTimersByTime(phraseIntervalMs);
});
expect(screen.getByText(workingPhrases[1])).toBeDefined();
});
it("wraps around to the first phrase after the full cycle", () => {
render(<WorkingIndicator />);
act(() => {
vi.advanceTimersByTime(phraseIntervalMs * workingPhrases.length);
});
expect(screen.getByText(workingPhrases[0])).toBeDefined();
});
});
|