|
| 1 | +// @vitest-environment jsdom |
| 2 | +import { |
| 3 | + afterEach, |
| 4 | + beforeEach, |
| 5 | + describe, |
| 6 | + expect, |
| 7 | + it, |
| 8 | + vi, |
| 9 | +} from "vitest"; |
| 10 | +import { mount, tick, unmount } from "svelte"; |
| 11 | +import type { SessionTiming } from "../../api/types/timing.js"; |
| 12 | + |
| 13 | +const mocks = vi.hoisted(() => { |
| 14 | + const timing: SessionTiming = { |
| 15 | + session_id: "sess-1", |
| 16 | + total_duration_ms: 1200, |
| 17 | + tool_duration_ms: 0, |
| 18 | + turn_count: 1, |
| 19 | + tool_call_count: 0, |
| 20 | + subagent_count: 0, |
| 21 | + slowest_call: null, |
| 22 | + by_category: [], |
| 23 | + turns: [], |
| 24 | + running: false, |
| 25 | + }; |
| 26 | + |
| 27 | + return { |
| 28 | + fetchSessionTiming: vi.fn().mockResolvedValue(timing), |
| 29 | + }; |
| 30 | +}); |
| 31 | + |
| 32 | +vi.mock("../../api/timing.js", () => ({ |
| 33 | + fetchSessionTiming: mocks.fetchSessionTiming, |
| 34 | +})); |
| 35 | + |
| 36 | +import { ui } from "../../stores/ui.svelte.js"; |
| 37 | +import { sessionTiming } from "../../stores/sessionTiming.svelte.js"; |
| 38 | +// @ts-ignore |
| 39 | +import SessionVitals from "./SessionVitals.svelte"; |
| 40 | + |
| 41 | +describe("SessionVitals", () => { |
| 42 | + let component: ReturnType<typeof mount> | undefined; |
| 43 | + |
| 44 | + beforeEach(() => { |
| 45 | + sessionTiming.reset(); |
| 46 | + ui.vitalsOpen = true; |
| 47 | + }); |
| 48 | + |
| 49 | + afterEach(() => { |
| 50 | + if (component) { |
| 51 | + unmount(component); |
| 52 | + component = undefined; |
| 53 | + } |
| 54 | + sessionTiming.reset(); |
| 55 | + ui.vitalsOpen = false; |
| 56 | + document.body.innerHTML = ""; |
| 57 | + }); |
| 58 | + |
| 59 | + it("has an obvious close control inside the analysis pane", async () => { |
| 60 | + component = mount(SessionVitals, { |
| 61 | + target: document.body, |
| 62 | + props: { sessionId: "sess-1" }, |
| 63 | + }); |
| 64 | + await tick(); |
| 65 | + await tick(); |
| 66 | + |
| 67 | + const closeButton = document.querySelector<HTMLButtonElement>( |
| 68 | + 'button[aria-label="Close session analysis"]', |
| 69 | + ); |
| 70 | + |
| 71 | + expect(closeButton).not.toBeNull(); |
| 72 | + expect(closeButton?.title).toBe("Close session analysis"); |
| 73 | + |
| 74 | + closeButton!.click(); |
| 75 | + await tick(); |
| 76 | + |
| 77 | + expect(ui.vitalsOpen).toBe(false); |
| 78 | + }); |
| 79 | +}); |
0 commit comments