content.totp-toast.addendum.test.ts

2.3 KB · raw

1// @vitest-environment jsdom2//3// Addendum 2 — TOTP auto-copy toast (T-M11–T-M13), proposed feature.4//5// Today, when Peach auto-copies a TOTP code it shows the generic "2FA code6// copied" toast (showToast in index.ts). The addendum asks for a dedicated7// showTotpCopyToast(secondsUntilClear) that renders a passkey-family toast8// ("2FA code copied / clears in 30s") and auto-dismisses after 3s, resetting its9// timer if a second copy lands while it is visible.10//11// showTotpCopyToast does not exist yet. This file imports the REAL inject.ts and12// activates the spec the moment the export appears — so it is an executable13// contract, not a stub that always passes. See INTEGRATION-CONTRACT.md.1415import "./_setup"; // installs the chrome mock inject.ts touches at import time16import { describe, expect, it, vi } from "vitest";17import * as inject from "./inject";1819const showTotpCopyToast = (inject as unknown as {20  showTotpCopyToast?: (secondsUntilClear: number) => void;21}).showTotpCopyToast;2223describe.skipIf(typeof showTotpCopyToast !== "function")(24  "Addendum 2 — proposed showTotpCopyToast (requires inject.ts change)",25  () => {26    const toast = showTotpCopyToast!;2728    it("T-M11: renders a toast showing the configured clear time", () => {29      document.body.innerHTML = "";30      expect(() => toast(30)).not.toThrow();31      expect(document.body.textContent ?? "").toMatch(/clears in 30/i);32    });3334    it("T-M12: a second copy while showing resets, leaving a single toast", () => {35      document.body.innerHTML = "";36      toast(30);37      toast(30);38      const toasts = document.querySelectorAll('[data-peach-toast], .peach-totp-toast');39      expect(toasts.length).toBeLessThanOrEqual(1);40    });4142    it("T-M13: auto-dismisses after ~3s", () => {43      document.body.innerHTML = "";44      vi.useFakeTimers();45      toast(30);46      vi.advanceTimersByTime(3500);47      vi.useRealTimers();48      expect(document.body.textContent ?? "").not.toMatch(/2FA code copied/i);49    });50  }51);5253// Addendum 2 is now implemented: the export exists and the T-M11–T-M13 spec54// above runs. This pins that the feature shipped (and that the skipIf block is55// no longer being silently skipped).56describe("Addendum 2 status", () => {57  it("exposes showTotpCopyToast now that the addendum is implemented", () => {58    expect(typeof showTotpCopyToast).toBe("function");59  });60});