@consenti/ui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,109 @@
1
+ type ConsentStatus = 'granted' | 'denied' | 'objected';
2
+ type ConsentValue = Record<string, ConsentStatus>;
3
+
4
+ /**
5
+ * Test utilities for `@consenti/ui`.
6
+ *
7
+ * Import via the `/testing` subpath export so these helpers are never bundled
8
+ * into production code:
9
+ *
10
+ * ```ts
11
+ * import {
12
+ * createMockConsenti,
13
+ * mockConsent,
14
+ * simulateConsentSubmitted,
15
+ * } from '@consenti/ui/testing'
16
+ * ```
17
+ *
18
+ * The helpers work in any JavaScript environment that provides a DOM
19
+ * (browsers, jsdom, happy-dom). They carry no runtime dependencies and
20
+ * do not import any Consenti internals — safe to use in unit tests without
21
+ * initialising the full widget.
22
+ */
23
+
24
+ /**
25
+ * Builds a `ConsentValue` map from explicit grant/deny lists.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const consent = mockConsent(
30
+ * ['analytics_storage'], // granted
31
+ * ['ad_storage', 'ad_user_data'], // denied
32
+ * )
33
+ * // → { analytics_storage: 'granted', ad_storage: 'denied', ad_user_data: 'denied' }
34
+ * ```
35
+ */
36
+ declare function mockConsent(granted?: string[], denied?: string[]): ConsentValue;
37
+ /**
38
+ * Returns a `ConsentValue` with every listed cookie set to `'granted'`.
39
+ * Shorthand for the common "user accepted everything" test scenario.
40
+ */
41
+ declare function mockAllGranted(cookieIds: string[]): ConsentValue;
42
+ /**
43
+ * Returns a `ConsentValue` with every listed cookie set to `'denied'`.
44
+ * Shorthand for the common "user rejected everything" test scenario.
45
+ */
46
+ declare function mockAllDenied(cookieIds: string[]): ConsentValue;
47
+ /**
48
+ * Dispatches `consenti:consentSubmitted` on `window` with the supplied consent
49
+ * map. Use this to trigger code paths that listen to consent changes without
50
+ * going through the full widget initialisation flow.
51
+ */
52
+ declare function simulateConsentSubmitted(consent: ConsentValue): void;
53
+ /**
54
+ * Dispatches `consenti:bannerInitialized` on `window`.
55
+ * Use this to simulate widget initialisation in tests that gate on the event.
56
+ */
57
+ declare function simulateBannerInitialized(hasExistingConsent?: boolean): void;
58
+ /**
59
+ * Dispatches `consenti:consentBeingSubmitted` on `window` before a simulated
60
+ * consent submission. Use in tests that capture both events.
61
+ */
62
+ declare function simulateConsentBeingSubmitted(consent: ConsentValue): void;
63
+ /**
64
+ * Shape returned by {@link createMockConsenti}.
65
+ * Mirrors the public API of `ConsentiSetup` for use in unit tests.
66
+ */
67
+ interface MockConsentiSetup {
68
+ hasConsent: () => boolean;
69
+ getConsent: () => ConsentValue | null;
70
+ getConsentDate: () => Date | false;
71
+ getGTMConsent: () => Record<string, string> | null;
72
+ submitConsent: (consent: Partial<ConsentValue>) => Promise<void>;
73
+ deleteConsent: () => Promise<void>;
74
+ showBanner: (useGpcVariant?: boolean) => void;
75
+ hideBanner: () => void;
76
+ showModal: () => void;
77
+ hideModal: () => void;
78
+ bannerVisibility: () => 'main' | 'gpc' | false;
79
+ modalVisibility: () => 'preference' | false;
80
+ onReady: (cb: () => void) => void;
81
+ readonly ready: Promise<void>;
82
+ destroy: () => void;
83
+ reConsent: () => Promise<void>;
84
+ }
85
+ /**
86
+ * Creates a minimal in-memory mock of `ConsentiSetup` for use in unit tests.
87
+ *
88
+ * All methods are no-ops or return sensible defaults. Pass an initial `consent`
89
+ * map to simulate a returning visitor who has already given consent.
90
+ *
91
+ * The mock's `submitConsent` updates internal state and fires
92
+ * `simulateConsentSubmitted` so event listeners in the component under test
93
+ * are triggered exactly as in production.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * const widget = createMockConsenti(
98
+ * mockConsent(['analytics_storage'], ['ad_storage'])
99
+ * )
100
+ * expect(widget.hasConsent()).toBe(true)
101
+ * expect(widget.getConsent()?.analytics_storage).toBe('granted')
102
+ *
103
+ * await widget.submitConsent({ ad_storage: 'granted' })
104
+ * expect(widget.getConsent()?.ad_storage).toBe('granted')
105
+ * ```
106
+ */
107
+ declare function createMockConsenti(consent?: ConsentValue | null): MockConsentiSetup;
108
+
109
+ export { type MockConsentiSetup, createMockConsenti, mockAllDenied, mockAllGranted, mockConsent, simulateBannerInitialized, simulateConsentBeingSubmitted, simulateConsentSubmitted };
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/testing.ts
21
+ var testing_exports = {};
22
+ __export(testing_exports, {
23
+ createMockConsenti: () => createMockConsenti,
24
+ mockAllDenied: () => mockAllDenied,
25
+ mockAllGranted: () => mockAllGranted,
26
+ mockConsent: () => mockConsent,
27
+ simulateBannerInitialized: () => simulateBannerInitialized,
28
+ simulateConsentBeingSubmitted: () => simulateConsentBeingSubmitted,
29
+ simulateConsentSubmitted: () => simulateConsentSubmitted
30
+ });
31
+ module.exports = __toCommonJS(testing_exports);
32
+ function mockConsent(granted = [], denied = []) {
33
+ const result = {};
34
+ for (const id of granted) result[id] = "granted";
35
+ for (const id of denied) result[id] = "denied";
36
+ return result;
37
+ }
38
+ function mockAllGranted(cookieIds) {
39
+ return mockConsent(cookieIds, []);
40
+ }
41
+ function mockAllDenied(cookieIds) {
42
+ return mockConsent([], cookieIds);
43
+ }
44
+ function simulateConsentSubmitted(consent) {
45
+ window.dispatchEvent(
46
+ new CustomEvent("consenti:consentSubmitted", { detail: { consent }, bubbles: true })
47
+ );
48
+ }
49
+ function simulateBannerInitialized(hasExistingConsent = false) {
50
+ window.dispatchEvent(
51
+ new CustomEvent("consenti:bannerInitialized", {
52
+ detail: { hasExistingConsent },
53
+ bubbles: true
54
+ })
55
+ );
56
+ }
57
+ function simulateConsentBeingSubmitted(consent) {
58
+ window.dispatchEvent(
59
+ new CustomEvent("consenti:consentBeingSubmitted", { detail: { consent }, bubbles: true })
60
+ );
61
+ }
62
+ function createMockConsenti(consent = null) {
63
+ let currentConsent = consent;
64
+ return {
65
+ hasConsent: () => currentConsent !== null,
66
+ getConsent: () => currentConsent,
67
+ getConsentDate: () => currentConsent !== null ? /* @__PURE__ */ new Date() : false,
68
+ getGTMConsent: () => null,
69
+ submitConsent: async (partial) => {
70
+ currentConsent = { ...currentConsent ?? {}, ...partial };
71
+ simulateConsentSubmitted(currentConsent);
72
+ },
73
+ deleteConsent: async () => {
74
+ currentConsent = null;
75
+ },
76
+ showBanner: () => {
77
+ },
78
+ hideBanner: () => {
79
+ },
80
+ showModal: () => {
81
+ },
82
+ hideModal: () => {
83
+ },
84
+ bannerVisibility: () => false,
85
+ modalVisibility: () => false,
86
+ onReady: (cb) => cb(),
87
+ ready: Promise.resolve(),
88
+ destroy: () => {
89
+ },
90
+ reConsent: async () => {
91
+ currentConsent = null;
92
+ }
93
+ };
94
+ }
95
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/testing.ts"],"sourcesContent":["/**\n * Test utilities for `@consenti/ui`.\n *\n * Import via the `/testing` subpath export so these helpers are never bundled\n * into production code:\n *\n * ```ts\n * import {\n * createMockConsenti,\n * mockConsent,\n * simulateConsentSubmitted,\n * } from '@consenti/ui/testing'\n * ```\n *\n * The helpers work in any JavaScript environment that provides a DOM\n * (browsers, jsdom, happy-dom). They carry no runtime dependencies and\n * do not import any Consenti internals — safe to use in unit tests without\n * initialising the full widget.\n */\n\nimport type { ConsentValue } from './types'\n\n// ─── Consent builders ─────────────────────────────────────────────────────────\n\n/**\n * Builds a `ConsentValue` map from explicit grant/deny lists.\n *\n * @example\n * ```ts\n * const consent = mockConsent(\n * ['analytics_storage'], // granted\n * ['ad_storage', 'ad_user_data'], // denied\n * )\n * // → { analytics_storage: 'granted', ad_storage: 'denied', ad_user_data: 'denied' }\n * ```\n */\nexport function mockConsent(granted: string[] = [], denied: string[] = []): ConsentValue {\n const result: ConsentValue = {}\n for (const id of granted) result[id] = 'granted'\n for (const id of denied) result[id] = 'denied'\n return result\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'granted'`.\n * Shorthand for the common \"user accepted everything\" test scenario.\n */\nexport function mockAllGranted(cookieIds: string[]): ConsentValue {\n return mockConsent(cookieIds, [])\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'denied'`.\n * Shorthand for the common \"user rejected everything\" test scenario.\n */\nexport function mockAllDenied(cookieIds: string[]): ConsentValue {\n return mockConsent([], cookieIds)\n}\n\n// ─── Event simulators ─────────────────────────────────────────────────────────\n\n/**\n * Dispatches `consenti:consentSubmitted` on `window` with the supplied consent\n * map. Use this to trigger code paths that listen to consent changes without\n * going through the full widget initialisation flow.\n */\nexport function simulateConsentSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n/**\n * Dispatches `consenti:bannerInitialized` on `window`.\n * Use this to simulate widget initialisation in tests that gate on the event.\n */\nexport function simulateBannerInitialized(hasExistingConsent = false): void {\n window.dispatchEvent(\n new CustomEvent('consenti:bannerInitialized', {\n detail: { hasExistingConsent },\n bubbles: true,\n }),\n )\n}\n\n/**\n * Dispatches `consenti:consentBeingSubmitted` on `window` before a simulated\n * consent submission. Use in tests that capture both events.\n */\nexport function simulateConsentBeingSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentBeingSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n// ─── Mock widget ──────────────────────────────────────────────────────────────\n\n/**\n * Shape returned by {@link createMockConsenti}.\n * Mirrors the public API of `ConsentiSetup` for use in unit tests.\n */\nexport interface MockConsentiSetup {\n hasConsent: () => boolean\n getConsent: () => ConsentValue | null\n getConsentDate: () => Date | false\n getGTMConsent: () => Record<string, string> | null\n submitConsent: (consent: Partial<ConsentValue>) => Promise<void>\n deleteConsent: () => Promise<void>\n showBanner: (useGpcVariant?: boolean) => void\n hideBanner: () => void\n showModal: () => void\n hideModal: () => void\n bannerVisibility: () => 'main' | 'gpc' | false\n modalVisibility: () => 'preference' | false\n onReady: (cb: () => void) => void\n readonly ready: Promise<void>\n destroy: () => void\n reConsent: () => Promise<void>\n}\n\n/**\n * Creates a minimal in-memory mock of `ConsentiSetup` for use in unit tests.\n *\n * All methods are no-ops or return sensible defaults. Pass an initial `consent`\n * map to simulate a returning visitor who has already given consent.\n *\n * The mock's `submitConsent` updates internal state and fires\n * `simulateConsentSubmitted` so event listeners in the component under test\n * are triggered exactly as in production.\n *\n * @example\n * ```ts\n * const widget = createMockConsenti(\n * mockConsent(['analytics_storage'], ['ad_storage'])\n * )\n * expect(widget.hasConsent()).toBe(true)\n * expect(widget.getConsent()?.analytics_storage).toBe('granted')\n *\n * await widget.submitConsent({ ad_storage: 'granted' })\n * expect(widget.getConsent()?.ad_storage).toBe('granted')\n * ```\n */\nexport function createMockConsenti(consent: ConsentValue | null = null): MockConsentiSetup {\n let currentConsent = consent\n\n return {\n hasConsent: () => currentConsent !== null,\n getConsent: () => currentConsent,\n getConsentDate: () => (currentConsent !== null ? new Date() : false),\n getGTMConsent: () => null,\n\n submitConsent: async (partial: Partial<ConsentValue>) => {\n currentConsent = { ...(currentConsent ?? {}), ...partial } as ConsentValue\n simulateConsentSubmitted(currentConsent)\n },\n\n deleteConsent: async () => {\n currentConsent = null\n },\n\n showBanner: () => {},\n hideBanner: () => {},\n showModal: () => {},\n hideModal: () => {},\n bannerVisibility: () => false as const,\n modalVisibility: () => false as const,\n\n onReady: (cb: () => void) => cb(),\n ready: Promise.resolve(),\n\n destroy: () => {},\n\n reConsent: async () => {\n currentConsent = null\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoCO,SAAS,YAAY,UAAoB,CAAC,GAAG,SAAmB,CAAC,GAAiB;AACvF,QAAM,SAAuB,CAAC;AAC9B,aAAW,MAAM,QAAS,QAAO,EAAE,IAAI;AACvC,aAAW,MAAM,OAAQ,QAAO,EAAE,IAAI;AACtC,SAAO;AACT;AAMO,SAAS,eAAe,WAAmC;AAChE,SAAO,YAAY,WAAW,CAAC,CAAC;AAClC;AAMO,SAAS,cAAc,WAAmC;AAC/D,SAAO,YAAY,CAAC,GAAG,SAAS;AAClC;AASO,SAAS,yBAAyB,SAA6B;AACpE,SAAO;AAAA,IACL,IAAI,YAAY,6BAA6B,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,KAAK,CAAC;AAAA,EACrF;AACF;AAMO,SAAS,0BAA0B,qBAAqB,OAAa;AAC1E,SAAO;AAAA,IACL,IAAI,YAAY,8BAA8B;AAAA,MAC5C,QAAQ,EAAE,mBAAmB;AAAA,MAC7B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAMO,SAAS,8BAA8B,SAA6B;AACzE,SAAO;AAAA,IACL,IAAI,YAAY,kCAAkC,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,KAAK,CAAC;AAAA,EAC1F;AACF;AAiDO,SAAS,mBAAmB,UAA+B,MAAyB;AACzF,MAAI,iBAAiB;AAErB,SAAO;AAAA,IACL,YAAY,MAAM,mBAAmB;AAAA,IACrC,YAAY,MAAM;AAAA,IAClB,gBAAgB,MAAO,mBAAmB,OAAO,oBAAI,KAAK,IAAI;AAAA,IAC9D,eAAe,MAAM;AAAA,IAErB,eAAe,OAAO,YAAmC;AACvD,uBAAiB,EAAE,GAAI,kBAAkB,CAAC,GAAI,GAAG,QAAQ;AACzD,+BAAyB,cAAc;AAAA,IACzC;AAAA,IAEA,eAAe,YAAY;AACzB,uBAAiB;AAAA,IACnB;AAAA,IAEA,YAAY,MAAM;AAAA,IAAC;AAAA,IACnB,YAAY,MAAM;AAAA,IAAC;AAAA,IACnB,WAAW,MAAM;AAAA,IAAC;AAAA,IAClB,WAAW,MAAM;AAAA,IAAC;AAAA,IAClB,kBAAkB,MAAM;AAAA,IACxB,iBAAiB,MAAM;AAAA,IAEvB,SAAS,CAAC,OAAmB,GAAG;AAAA,IAChC,OAAO,QAAQ,QAAQ;AAAA,IAEvB,SAAS,MAAM;AAAA,IAAC;AAAA,IAEhB,WAAW,YAAY;AACrB,uBAAiB;AAAA,IACnB;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,74 @@
1
+ // src/testing.ts
2
+ function mockConsent(granted = [], denied = []) {
3
+ const result = {};
4
+ for (const id of granted) result[id] = "granted";
5
+ for (const id of denied) result[id] = "denied";
6
+ return result;
7
+ }
8
+ function mockAllGranted(cookieIds) {
9
+ return mockConsent(cookieIds, []);
10
+ }
11
+ function mockAllDenied(cookieIds) {
12
+ return mockConsent([], cookieIds);
13
+ }
14
+ function simulateConsentSubmitted(consent) {
15
+ window.dispatchEvent(
16
+ new CustomEvent("consenti:consentSubmitted", { detail: { consent }, bubbles: true })
17
+ );
18
+ }
19
+ function simulateBannerInitialized(hasExistingConsent = false) {
20
+ window.dispatchEvent(
21
+ new CustomEvent("consenti:bannerInitialized", {
22
+ detail: { hasExistingConsent },
23
+ bubbles: true
24
+ })
25
+ );
26
+ }
27
+ function simulateConsentBeingSubmitted(consent) {
28
+ window.dispatchEvent(
29
+ new CustomEvent("consenti:consentBeingSubmitted", { detail: { consent }, bubbles: true })
30
+ );
31
+ }
32
+ function createMockConsenti(consent = null) {
33
+ let currentConsent = consent;
34
+ return {
35
+ hasConsent: () => currentConsent !== null,
36
+ getConsent: () => currentConsent,
37
+ getConsentDate: () => currentConsent !== null ? /* @__PURE__ */ new Date() : false,
38
+ getGTMConsent: () => null,
39
+ submitConsent: async (partial) => {
40
+ currentConsent = { ...currentConsent ?? {}, ...partial };
41
+ simulateConsentSubmitted(currentConsent);
42
+ },
43
+ deleteConsent: async () => {
44
+ currentConsent = null;
45
+ },
46
+ showBanner: () => {
47
+ },
48
+ hideBanner: () => {
49
+ },
50
+ showModal: () => {
51
+ },
52
+ hideModal: () => {
53
+ },
54
+ bannerVisibility: () => false,
55
+ modalVisibility: () => false,
56
+ onReady: (cb) => cb(),
57
+ ready: Promise.resolve(),
58
+ destroy: () => {
59
+ },
60
+ reConsent: async () => {
61
+ currentConsent = null;
62
+ }
63
+ };
64
+ }
65
+ export {
66
+ createMockConsenti,
67
+ mockAllDenied,
68
+ mockAllGranted,
69
+ mockConsent,
70
+ simulateBannerInitialized,
71
+ simulateConsentBeingSubmitted,
72
+ simulateConsentSubmitted
73
+ };
74
+ //# sourceMappingURL=testing.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/testing.ts"],"sourcesContent":["/**\n * Test utilities for `@consenti/ui`.\n *\n * Import via the `/testing` subpath export so these helpers are never bundled\n * into production code:\n *\n * ```ts\n * import {\n * createMockConsenti,\n * mockConsent,\n * simulateConsentSubmitted,\n * } from '@consenti/ui/testing'\n * ```\n *\n * The helpers work in any JavaScript environment that provides a DOM\n * (browsers, jsdom, happy-dom). They carry no runtime dependencies and\n * do not import any Consenti internals — safe to use in unit tests without\n * initialising the full widget.\n */\n\nimport type { ConsentValue } from './types'\n\n// ─── Consent builders ─────────────────────────────────────────────────────────\n\n/**\n * Builds a `ConsentValue` map from explicit grant/deny lists.\n *\n * @example\n * ```ts\n * const consent = mockConsent(\n * ['analytics_storage'], // granted\n * ['ad_storage', 'ad_user_data'], // denied\n * )\n * // → { analytics_storage: 'granted', ad_storage: 'denied', ad_user_data: 'denied' }\n * ```\n */\nexport function mockConsent(granted: string[] = [], denied: string[] = []): ConsentValue {\n const result: ConsentValue = {}\n for (const id of granted) result[id] = 'granted'\n for (const id of denied) result[id] = 'denied'\n return result\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'granted'`.\n * Shorthand for the common \"user accepted everything\" test scenario.\n */\nexport function mockAllGranted(cookieIds: string[]): ConsentValue {\n return mockConsent(cookieIds, [])\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'denied'`.\n * Shorthand for the common \"user rejected everything\" test scenario.\n */\nexport function mockAllDenied(cookieIds: string[]): ConsentValue {\n return mockConsent([], cookieIds)\n}\n\n// ─── Event simulators ─────────────────────────────────────────────────────────\n\n/**\n * Dispatches `consenti:consentSubmitted` on `window` with the supplied consent\n * map. Use this to trigger code paths that listen to consent changes without\n * going through the full widget initialisation flow.\n */\nexport function simulateConsentSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n/**\n * Dispatches `consenti:bannerInitialized` on `window`.\n * Use this to simulate widget initialisation in tests that gate on the event.\n */\nexport function simulateBannerInitialized(hasExistingConsent = false): void {\n window.dispatchEvent(\n new CustomEvent('consenti:bannerInitialized', {\n detail: { hasExistingConsent },\n bubbles: true,\n }),\n )\n}\n\n/**\n * Dispatches `consenti:consentBeingSubmitted` on `window` before a simulated\n * consent submission. Use in tests that capture both events.\n */\nexport function simulateConsentBeingSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentBeingSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n// ─── Mock widget ──────────────────────────────────────────────────────────────\n\n/**\n * Shape returned by {@link createMockConsenti}.\n * Mirrors the public API of `ConsentiSetup` for use in unit tests.\n */\nexport interface MockConsentiSetup {\n hasConsent: () => boolean\n getConsent: () => ConsentValue | null\n getConsentDate: () => Date | false\n getGTMConsent: () => Record<string, string> | null\n submitConsent: (consent: Partial<ConsentValue>) => Promise<void>\n deleteConsent: () => Promise<void>\n showBanner: (useGpcVariant?: boolean) => void\n hideBanner: () => void\n showModal: () => void\n hideModal: () => void\n bannerVisibility: () => 'main' | 'gpc' | false\n modalVisibility: () => 'preference' | false\n onReady: (cb: () => void) => void\n readonly ready: Promise<void>\n destroy: () => void\n reConsent: () => Promise<void>\n}\n\n/**\n * Creates a minimal in-memory mock of `ConsentiSetup` for use in unit tests.\n *\n * All methods are no-ops or return sensible defaults. Pass an initial `consent`\n * map to simulate a returning visitor who has already given consent.\n *\n * The mock's `submitConsent` updates internal state and fires\n * `simulateConsentSubmitted` so event listeners in the component under test\n * are triggered exactly as in production.\n *\n * @example\n * ```ts\n * const widget = createMockConsenti(\n * mockConsent(['analytics_storage'], ['ad_storage'])\n * )\n * expect(widget.hasConsent()).toBe(true)\n * expect(widget.getConsent()?.analytics_storage).toBe('granted')\n *\n * await widget.submitConsent({ ad_storage: 'granted' })\n * expect(widget.getConsent()?.ad_storage).toBe('granted')\n * ```\n */\nexport function createMockConsenti(consent: ConsentValue | null = null): MockConsentiSetup {\n let currentConsent = consent\n\n return {\n hasConsent: () => currentConsent !== null,\n getConsent: () => currentConsent,\n getConsentDate: () => (currentConsent !== null ? new Date() : false),\n getGTMConsent: () => null,\n\n submitConsent: async (partial: Partial<ConsentValue>) => {\n currentConsent = { ...(currentConsent ?? {}), ...partial } as ConsentValue\n simulateConsentSubmitted(currentConsent)\n },\n\n deleteConsent: async () => {\n currentConsent = null\n },\n\n showBanner: () => {},\n hideBanner: () => {},\n showModal: () => {},\n hideModal: () => {},\n bannerVisibility: () => false as const,\n modalVisibility: () => false as const,\n\n onReady: (cb: () => void) => cb(),\n ready: Promise.resolve(),\n\n destroy: () => {},\n\n reConsent: async () => {\n currentConsent = null\n },\n }\n}\n"],"mappings":";AAoCO,SAAS,YAAY,UAAoB,CAAC,GAAG,SAAmB,CAAC,GAAiB;AACvF,QAAM,SAAuB,CAAC;AAC9B,aAAW,MAAM,QAAS,QAAO,EAAE,IAAI;AACvC,aAAW,MAAM,OAAQ,QAAO,EAAE,IAAI;AACtC,SAAO;AACT;AAMO,SAAS,eAAe,WAAmC;AAChE,SAAO,YAAY,WAAW,CAAC,CAAC;AAClC;AAMO,SAAS,cAAc,WAAmC;AAC/D,SAAO,YAAY,CAAC,GAAG,SAAS;AAClC;AASO,SAAS,yBAAyB,SAA6B;AACpE,SAAO;AAAA,IACL,IAAI,YAAY,6BAA6B,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,KAAK,CAAC;AAAA,EACrF;AACF;AAMO,SAAS,0BAA0B,qBAAqB,OAAa;AAC1E,SAAO;AAAA,IACL,IAAI,YAAY,8BAA8B;AAAA,MAC5C,QAAQ,EAAE,mBAAmB;AAAA,MAC7B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAMO,SAAS,8BAA8B,SAA6B;AACzE,SAAO;AAAA,IACL,IAAI,YAAY,kCAAkC,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,KAAK,CAAC;AAAA,EAC1F;AACF;AAiDO,SAAS,mBAAmB,UAA+B,MAAyB;AACzF,MAAI,iBAAiB;AAErB,SAAO;AAAA,IACL,YAAY,MAAM,mBAAmB;AAAA,IACrC,YAAY,MAAM;AAAA,IAClB,gBAAgB,MAAO,mBAAmB,OAAO,oBAAI,KAAK,IAAI;AAAA,IAC9D,eAAe,MAAM;AAAA,IAErB,eAAe,OAAO,YAAmC;AACvD,uBAAiB,EAAE,GAAI,kBAAkB,CAAC,GAAI,GAAG,QAAQ;AACzD,+BAAyB,cAAc;AAAA,IACzC;AAAA,IAEA,eAAe,YAAY;AACzB,uBAAiB;AAAA,IACnB;AAAA,IAEA,YAAY,MAAM;AAAA,IAAC;AAAA,IACnB,YAAY,MAAM;AAAA,IAAC;AAAA,IACnB,WAAW,MAAM;AAAA,IAAC;AAAA,IAClB,WAAW,MAAM;AAAA,IAAC;AAAA,IAClB,kBAAkB,MAAM;AAAA,IACxB,iBAAiB,MAAM;AAAA,IAEvB,SAAS,CAAC,OAAmB,GAAG;AAAA,IAChC,OAAO,QAAQ,QAAQ;AAAA,IAEvB,SAAS,MAAM;AAAA,IAAC;AAAA,IAEhB,WAAW,YAAY;AACrB,uBAAiB;AAAA,IACnB;AAAA,EACF;AACF;","names":[]}