import { render, screen } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { TokenQrDialog } from "../../src/components/otp/TokenQrDialog"; import { parseOtpAuth } from "../../src/otp/profile"; describe("token QR display", () => { it("reports encoder limits without displaying an empty QR or allowing download", () => { const { profile } = parseOtpAuth( `otpauth://totp/${"a".repeat(500)}?secret=JBSWY3DPEHPK3PXP`, ); render(); expect(screen.getByRole("alert")).toHaveTextContent(/version 10/iu); expect(screen.queryByRole("img")).not.toBeInTheDocument(); expect(screen.getByRole("button", { name: "Download QR" })).toBeDisabled(); }); it("identifies nonportable time parameters without showing the plaintext seed", () => { const { profile } = parseOtpAuth( "otpauth://totp/Example:alice?secret=JBSWY3DPEHPK3PXP&issuer=Example&t0=100", ); render(); expect( screen.getByText(/Some authenticators ignore/iu), ).toBeInTheDocument(); expect(screen.getByRole("dialog").textContent).not.toContain( "JBSWY3DPEHPK3PXP", ); }); });