// @vitest-environment jsdom // // Addendum 2 — TOTP auto-copy toast (T-M11–T-M13), proposed feature. // // Today, when Peach auto-copies a TOTP code it shows the generic "2FA code // copied" toast (showToast in index.ts). The addendum asks for a dedicated // showTotpCopyToast(secondsUntilClear) that renders a passkey-family toast // ("2FA code copied / clears in 30s") and auto-dismisses after 3s, resetting its // timer if a second copy lands while it is visible. // // showTotpCopyToast does not exist yet. This file imports the REAL inject.ts and // activates the spec the moment the export appears — so it is an executable // contract, not a stub that always passes. See INTEGRATION-CONTRACT.md. import "./_setup"; // installs the chrome mock inject.ts touches at import time import { describe, expect, it, vi } from "vitest"; import * as inject from "./inject"; const showTotpCopyToast = (inject as unknown as { showTotpCopyToast?: (secondsUntilClear: number) => void; }).showTotpCopyToast; describe.skipIf(typeof showTotpCopyToast !== "function")( "Addendum 2 — proposed showTotpCopyToast (requires inject.ts change)", () => { const toast = showTotpCopyToast!; it("T-M11: renders a toast showing the configured clear time", () => { document.body.innerHTML = ""; expect(() => toast(30)).not.toThrow(); expect(document.body.textContent ?? "").toMatch(/clears in 30/i); }); it("T-M12: a second copy while showing resets, leaving a single toast", () => { document.body.innerHTML = ""; toast(30); toast(30); const toasts = document.querySelectorAll('[data-peach-toast], .peach-totp-toast'); expect(toasts.length).toBeLessThanOrEqual(1); }); it("T-M13: auto-dismisses after ~3s", () => { document.body.innerHTML = ""; vi.useFakeTimers(); toast(30); vi.advanceTimersByTime(3500); vi.useRealTimers(); expect(document.body.textContent ?? "").not.toMatch(/2FA code copied/i); }); } ); // Addendum 2 is now implemented: the export exists and the T-M11–T-M13 spec // above runs. This pins that the feature shipped (and that the skipIf block is // no longer being silently skipped). describe("Addendum 2 status", () => { it("exposes showTotpCopyToast now that the addendum is implemented", () => { expect(typeof showTotpCopyToast).toBe("function"); }); });