Files
OmniRoute/tests/unit/ui/compressionAnnotation.test.tsx
Diego Rodrigues de Sa e Souza 7c23dab64d Release v3.8.40
v3.8.40 cycle integration → main. All test gates green (Unit/Integration/Coverage/Node-compat/Quality-Ratchet). The only red check, 'PR Test Policy', is the test-masking heuristic firing on the cumulative ~57-commit release diff (legitimate assert consolidations already reviewed per-PR — Gemini CLI removal #5246, retired GPT models #5280, provider catalog refreshes); overridden with --admin per the documented release-PR convention. CodeQL/SonarQube advisory scans non-blocking; #5278's code already passed CodeQL on main. Homologated on VPS 192.168.0.15 (v3.8.40 healthy).
2026-06-29 08:40:06 -03:00

68 lines
2.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// @vitest-environment jsdom
import React from "react";
import { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { CompressionAnnotation } from "@/app/(dashboard)/dashboard/compression/studio/CompressionAnnotation";
import type { CompressionStats } from "@omniroute/open-sse/services/compression/types";
let container: HTMLDivElement;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
});
afterEach(() => {
document.body.removeChild(container);
});
function render(ui: React.ReactElement) {
act(() => {
createRoot(container).render(ui);
});
}
function makeStats(overrides: Partial<CompressionStats> = {}): CompressionStats {
return {
originalTokens: 847,
compressedTokens: 312,
savingsPercent: 63.16,
techniquesUsed: ["caveman"],
mode: "standard",
timestamp: 0,
...overrides,
};
}
describe("CompressionAnnotation", () => {
it("renders token range badge", () => {
const stats = makeStats({
rulesApplied: ["filler", "filler", "dedup"],
});
render(<CompressionAnnotation stats={stats} />);
expect(container.textContent).toContain("847→312");
});
it("renders rule pills", () => {
const stats = makeStats({
rulesApplied: ["filler", "filler", "dedup"],
});
render(<CompressionAnnotation stats={stats} />);
expect(container.textContent).toContain("filler×2");
expect(container.textContent).toContain("dedup×1");
});
it("returns null when no rules applied", () => {
const stats = makeStats({ rulesApplied: [], techniquesUsed: [] });
render(<CompressionAnnotation stats={stats} />);
expect(container.innerHTML).toBe("");
});
it("returns null when rulesApplied is absent", () => {
const stats = makeStats({ rulesApplied: undefined, techniquesUsed: [] });
render(<CompressionAnnotation stats={stats} />);
expect(container.innerHTML).toBe("");
});
});