|
| 1 | +// @vitest-environment jsdom |
| 2 | +import { cleanup, render, screen } from "@testing-library/react"; |
| 3 | +import { afterEach, describe, expect, it } from "vitest"; |
| 4 | +import { |
| 5 | + QualityDrilldownExamples, |
| 6 | + formatDrilldownMetric, |
| 7 | +} from "./QualityDrilldownExamples"; |
| 8 | + |
| 9 | +describe("formatDrilldownMetric", () => { |
| 10 | + it("formats each signal's metric string", () => { |
| 11 | + expect(formatDrilldownMetric("edit_ratio", 0.42)).toBe("42.0% edit ratio"); |
| 12 | + expect(formatDrilldownMetric("time_to_draft", 12000)).toBe( |
| 13 | + "12.0s to draft", |
| 14 | + ); |
| 15 | + expect(formatDrilldownMetric("copy_per_save", 99)).toBe( |
| 16 | + "Saved without copy", |
| 17 | + ); |
| 18 | + expect(formatDrilldownMetric("edited_save_rate", 0.8)).toBe( |
| 19 | + "80.0% edit ratio", |
| 20 | + ); |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +describe("QualityDrilldownExamples", () => { |
| 25 | + afterEach(() => cleanup()); |
| 26 | + |
| 27 | + it("renders null when there is no drilldown payload", () => { |
| 28 | + const { container } = render( |
| 29 | + <QualityDrilldownExamples signalId="edit_ratio" drilldown={null} />, |
| 30 | + ); |
| 31 | + expect(container.innerHTML).toBe(""); |
| 32 | + }); |
| 33 | + |
| 34 | + it("renders up to three draft examples for the given signal", () => { |
| 35 | + render( |
| 36 | + <QualityDrilldownExamples |
| 37 | + signalId="edit_ratio" |
| 38 | + drilldown={{ |
| 39 | + edit_ratio: [ |
| 40 | + { |
| 41 | + draft_id: "d1", |
| 42 | + created_at: "2026-04-01", |
| 43 | + metric_value: 0.5, |
| 44 | + draft_excerpt: "Drift example one", |
| 45 | + }, |
| 46 | + { |
| 47 | + draft_id: "d2", |
| 48 | + created_at: "2026-04-02", |
| 49 | + metric_value: 0.7, |
| 50 | + draft_excerpt: "Drift example two", |
| 51 | + }, |
| 52 | + ], |
| 53 | + time_to_draft: [], |
| 54 | + copy_per_save: [], |
| 55 | + edited_save_rate: [], |
| 56 | + }} |
| 57 | + />, |
| 58 | + ); |
| 59 | + expect(screen.getByText("d1")).toBeTruthy(); |
| 60 | + expect(screen.getByText("d2")).toBeTruthy(); |
| 61 | + expect(screen.getByText("Drift example one")).toBeTruthy(); |
| 62 | + }); |
| 63 | +}); |
0 commit comments