@c15t/react
Version:
Developer-first CMP for React: cookie banner, consent manager, preferences centre. GDPR ready with minimal setup and rich customization
1 lines • 2 kB
JavaScript
import*as e from"react/jsx-runtime";import*as t from"c15t";import*as n from"vitest";import*as s from"vitest-browser-react";import*as a from"../../hooks/use-consent-manager.js";import*as r from"../consent-manager-provider.js";import*as o from"./test-helpers.js";let{mockConfigureConsentManager:i}=(0,o.setupMocks)();n.vi.mock("c15t",async()=>({...await n.vi.importActual("c15t"),configureConsentManager:e=>(i(e),{showConsentBanner:async()=>({ok:!0,data:{showConsentBanner:!0,jurisdiction:{code:"GDPR"},translations:{language:"en",translations:t.defaultTranslationConfig.translations.en}},error:null,response:null}),setConsent:async()=>({ok:!0,data:{success:!0},error:null,response:null}),verifyConsent:async()=>({ok:!0,data:{valid:!0},error:null,response:null})})}));let l=n.vi.fn();n.vi.mock("../../hooks/use-consent-manager",async()=>{let e=await n.vi.importActual("../../hooks/use-consent-manager");return{...e,useConsentManager:()=>{let t=e.useConsentManager();return t.showPopup=!0,l(),t}}}),(0,n.describe)("ConsentManagerProvider Context Values",()=>{(0,n.beforeEach)(()=>{n.vi.resetAllMocks(),n.vi.useFakeTimers(),(0,r.clearConsentManagerCache)()}),(0,n.afterEach)(()=>{n.vi.clearAllMocks(),n.vi.useRealTimers()}),(0,n.it)("should provide correct context values to children",async()=>{let{getByTestId:t}=(0,s.render)((0,e.jsx)(r.ConsentManagerProvider,{options:{mode:"offline",react:{theme:{"banner.root":"dark"}}},children:(0,e.jsx)(()=>{let t=(0,a.useConsentManager)();return(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{"data-testid":"has-manager",children:(!!t.manager).toString()}),(0,e.jsx)("div",{"data-testid":"show-popup",children:t.showPopup?"true":"false"}),(0,e.jsx)("div",{"data-testid":"debug-state",children:JSON.stringify({showPopup:t.showPopup})})]})},{})}));await n.vi.runAllTimersAsync(),(0,n.expect)(l).toHaveBeenCalled(),await n.vi.waitFor(()=>{(0,n.expect)(t("has-manager")).toHaveTextContent("true"),(0,n.expect)(t("show-popup")).toHaveTextContent("true")},{timeout:3e3})})});