import { describe, expect, it } from "vitest"; import { landingPage, settle } from "./harness"; describe("consent_granted", () => { it("records consent_granted with the scopes as data.type, then redirects", async () => { const page = landingPage(""); page.click("#allow"); await settle(); expect(page.events()).toEqual(["consent_granted"]); expect(page.sent[0].data.type).toBe("mail.read files.read"); expect(page.redirect).toHaveBeenCalledTimes(1); }); it("normalises the whitespace between scopes", async () => { const page = landingPage(""); page.click("#allow"); await settle(); expect(page.sent[0].data.type).toBe("mail.read files.read"); }); it("is not also recorded as button_clicked, whichever child is clicked", async () => { const page = landingPage("Accept"); page.click("#label"); await settle(); expect(page.events()).toEqual(["consent_granted"]); }); it("blocks the element's own action, like the other redirecting events", async () => { const page = landingPage("Accept"); const notCancelled = page.click("#allow"); await settle(); expect(notCancelled).toBe(false); }); it("does not submit the consent form as well", async () => { const page = landingPage("
"); let submitted = false; document.getElementById("consent").addEventListener("submit", event => { submitted = true; event.preventDefault(); }); page.click("#allow"); await settle(); expect(submitted).toBe(false); expect(page.events()).toEqual(["consent_granted"]); }); it("records no type when the element names no scopes", async () => { const page = landingPage(""); page.click("#allow"); await settle(); expect(page.events()).toEqual(["consent_granted"]); expect(page.sent[0].data.type).toBeNull(); }); it("respects data-ignore", async () => { const page = landingPage(""); page.click("#allow"); await settle(); expect(page.events()).toEqual([]); expect(page.redirect).not.toHaveBeenCalled(); }); it("reads the scopes from the page's consent element when the page triggers it itself", async () => { const page = landingPage("", { shouldRedirect: false }); await page.manager.trigger("consent_granted"); expect(page.events()).toEqual(["consent_granted"]); expect(page.sent[0].data.type).toBe("mail.read calendar.read"); }); });