@@ -40,6 +40,26 @@ const aggregates = {
|
40 | 40 | daily: [], |
41 | 41 | } as unknown as UsageAggregates; |
42 | 42 | |
| 43 | +function directText(element: Element | null | undefined): string | undefined { |
| 44 | +return Array.from(element?.childNodes ?? []) |
| 45 | +.filter((node) => node.nodeType === Node.TEXT_NODE) |
| 46 | +.map((node) => node.textContent ?? "") |
| 47 | +.join("") |
| 48 | +.trim(); |
| 49 | +} |
| 50 | + |
| 51 | +function getSummaryCards(container: HTMLElement): Array<{ |
| 52 | +title: string | undefined; |
| 53 | +value: string | undefined; |
| 54 | +sub: string | undefined; |
| 55 | +}> { |
| 56 | +return Array.from(container.querySelectorAll(".usage-summary-card")).map((card) => ({ |
| 57 | +title: directText(card.querySelector(".usage-summary-title")), |
| 58 | +value: card.querySelector(".usage-summary-value")?.textContent?.trim(), |
| 59 | +sub: card.querySelector(".usage-summary-sub")?.textContent?.trim(), |
| 60 | +})); |
| 61 | +} |
| 62 | + |
43 | 63 | describe("renderUsageInsights", () => { |
44 | 64 | it("includes cache writes in cache-hit-rate denominator", () => { |
45 | 65 | const container = document.createElement("div"); |
@@ -62,9 +82,11 @@ describe("renderUsageInsights", () => {
|
62 | 82 | container, |
63 | 83 | ); |
64 | 84 | |
65 | | -expect(container.textContent).toContain("30.0%"); |
66 | | -expect(container.textContent).toContain("300 cached"); |
67 | | -expect(container.textContent).toContain("1.0K prompt"); |
| 85 | +expect(getSummaryCards(container)).toContainEqual({ |
| 86 | +title: "Cache Hit Rate", |
| 87 | +value: "30.0%", |
| 88 | +sub: "300 cached · 1.0K prompt", |
| 89 | +}); |
68 | 90 | }); |
69 | 91 | }); |
70 | 92 | |
|