import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; import { App } from "../../src/App"; class StreamingTestBlob { readonly size: number; private readonly bytes: Uint8Array; constructor(parts: readonly unknown[] = []) { this.bytes = new TextEncoder().encode(parts.map(String).join("")); this.size = this.bytes.byteLength; } stream(): ReadableStream { const bytes = this.bytes; let done = false; return new ReadableStream({ pull(controller) { if (done) controller.close(); else { done = true; controller.enqueue(bytes); } }, }); } } describe("Log Tools", () => { it("streams the sample and exposes correlation and redaction views", async () => { vi.stubGlobal("Blob", StreamingTestBlob as unknown as typeof Blob); vi.stubGlobal( "fetch", vi.fn(async () => new Response("Not found", { status: 404 })), ); render(); expect( await screen.findByRole("heading", { name: "Log Tools" }), ).toBeVisible(); await screen.findByRole( "button", { name: "Scan pasted log" }, { timeout: 15_000 }, ); await userEvent.click( screen.getByRole("button", { name: "Scan pasted log" }), ); expect( await screen.findByText(/Completed 4 lines with JSON Lines/u, undefined, { timeout: 10_000, }), ).toBeVisible(); expect( screen.getByText("JSON Lines", { selector: ".metrics strong" }), ).toBeVisible(); await userEvent.click(screen.getByRole("tab", { name: "Redaction" })); expect(screen.getByText("Deterministic recipes")).toBeVisible(); expect(screen.getByLabelText("Redacted preview")).not.toHaveTextContent( "ada@example.test", ); }, 30_000); });