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