Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+60
@@ -0,0 +1,60 @@
|
||||
// @vitest-environment jsdom
|
||||
import { cleanup, render, waitFor } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import ScriptCrisp from "./ScriptCrisp";
|
||||
|
||||
const { hasConsent, isAppOrAdminSurface } = vi.hoisted(() => ({
|
||||
hasConsent: vi.fn(() => false),
|
||||
isAppOrAdminSurface: vi.fn(() => false),
|
||||
}));
|
||||
|
||||
vi.mock("react-router", () => ({
|
||||
useLocation: () => ({ pathname: "/" }),
|
||||
}));
|
||||
vi.mock("~/utils/data/useRootData", () => ({
|
||||
useRootData: () => ({ chatWebsiteId: "site-id", userSession: { cookies: [] } }),
|
||||
}));
|
||||
vi.mock("~/utils/helpers/CookieHelper", () => ({
|
||||
default: { hasConsent },
|
||||
}));
|
||||
vi.mock("~/utils/app/HostAwareSurface", () => ({
|
||||
isAppOrAdminSurface,
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
document.querySelectorAll('script[src="https://client.crisp.chat/l.js"]').forEach((node) => node.remove());
|
||||
delete window.$crisp;
|
||||
delete window.CRISP_WEBSITE_ID;
|
||||
hasConsent.mockReset();
|
||||
hasConsent.mockReturnValue(false);
|
||||
isAppOrAdminSurface.mockReset();
|
||||
isAppOrAdminSurface.mockReturnValue(false);
|
||||
});
|
||||
|
||||
describe("ScriptCrisp privacy gate", () => {
|
||||
it("does not contact Crisp without functional-cookie consent", () => {
|
||||
render(<ScriptCrisp nonce="aBcDeFgHiJkLmNoPqRsTuVwX" />);
|
||||
|
||||
expect(document.querySelector('script[src="https://client.crisp.chat/l.js"]')).toBeNull();
|
||||
});
|
||||
|
||||
it("loads Crisp on a public surface after consent and carries the CSP nonce", async () => {
|
||||
hasConsent.mockReturnValue(true);
|
||||
render(<ScriptCrisp nonce="aBcDeFgHiJkLmNoPqRsTuVwX" />);
|
||||
|
||||
await waitFor(() => {
|
||||
const script = document.querySelector<HTMLScriptElement>('script[src="https://client.crisp.chat/l.js"]');
|
||||
expect(script?.nonce).toBe("aBcDeFgHiJkLmNoPqRsTuVwX");
|
||||
});
|
||||
});
|
||||
|
||||
it("never loads the public chat script on app or admin surfaces", () => {
|
||||
hasConsent.mockReturnValue(true);
|
||||
isAppOrAdminSurface.mockReturnValue(true);
|
||||
render(<ScriptCrisp nonce="aBcDeFgHiJkLmNoPqRsTuVwX" />);
|
||||
|
||||
expect(document.querySelector('script[src="https://client.crisp.chat/l.js"]')).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user