@consenti/ui 0.1.0 → 0.2.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.
- package/README.md +325 -117
- package/dist/angular.d.cts +233 -34
- package/dist/angular.d.ts +233 -34
- package/dist/angular.js +1 -73
- package/dist/angular.js.map +1 -1
- package/dist/angular.mjs +1 -52
- package/dist/angular.mjs.map +1 -1
- package/dist/chunk-K2UN3O67.mjs +2 -0
- package/dist/{chunk-ARALKXMB.mjs.map → chunk-K2UN3O67.mjs.map} +1 -1
- package/dist/hmac-UKMRMKN6.mjs +2 -0
- package/dist/{hmac-N6H7F2K2.mjs.map → hmac-UKMRMKN6.mjs.map} +1 -1
- package/dist/http-UU2NIW6M.mjs +2 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +217 -25
- package/dist/index.mjs +1 -2220
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1 -2304
- package/dist/index.umd.js.map +1 -1
- package/dist/react.d.cts +233 -29
- package/dist/react.d.ts +233 -29
- package/dist/react.js +1 -60
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +1 -39
- package/dist/react.mjs.map +1 -1
- package/dist/testing.js +1 -94
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -73
- package/dist/testing.mjs.map +1 -1
- package/dist/vue.d.cts +244 -53
- package/dist/vue.d.ts +244 -53
- package/dist/vue.js +1 -72
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +1 -51
- package/dist/vue.mjs.map +1 -1
- package/package.json +13 -5
- package/dist/chunk-ARALKXMB.mjs +0 -20
- package/dist/hmac-N6H7F2K2.mjs +0 -26
- package/dist/http-VHOGZ6ZJ.mjs +0 -7
- /package/dist/{http-VHOGZ6ZJ.mjs.map → http-UU2NIW6M.mjs.map} +0 -0
package/dist/testing.js
CHANGED
|
@@ -1,95 +1,2 @@
|
|
|
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
|
-
}
|
|
1
|
+
"use strict";var i=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var c=(e,n)=>{for(var t in n)i(e,t,{get:n[t],enumerable:!0})},C=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of d(n))!u.call(e,s)&&s!==t&&i(e,s,{get:()=>n[s],enumerable:!(o=r(n,s))||o.enumerable});return e};var b=e=>C(i({},"__esModule",{value:!0}),e);var g={};c(g,{createMockConsenti:()=>V,mockAllDenied:()=>v,mockAllGranted:()=>m,mockConsent:()=>a,simulateBannerInitialized:()=>f,simulateConsentBeingSubmitted:()=>p,simulateConsentSubmitted:()=>l});module.exports=b(g);function a(e=[],n=[]){let t={};for(let o of e)t[o]="granted";for(let o of n)t[o]="denied";return t}function m(e){return a(e,[])}function v(e){return a([],e)}function l(e){window.dispatchEvent(new CustomEvent("consenti:consentSubmitted",{detail:{consent:e},bubbles:!0}))}function f(e=!1){window.dispatchEvent(new CustomEvent("consenti:bannerInitialized",{detail:{hasExistingConsent:e},bubbles:!0}))}function p(e){window.dispatchEvent(new CustomEvent("consenti:consentBeingSubmitted",{detail:{consent:e},bubbles:!0}))}function V(e=null){let n=e;return{hasConsent:()=>n!==null,getConsent:()=>n,getConsentDate:()=>n!==null?new Date:!1,getGTMConsent:()=>null,submitConsent:async t=>{n={...n??{},...t},l(n)},deleteConsent:async()=>{n=null},showBanner:()=>{},hideBanner:()=>{},showModal:()=>{},hideModal:()=>{},bannerVisibility:()=>!1,modalVisibility:()=>!1,onReady:t=>t(),ready:Promise.resolve(),destroy:()=>{},reConsent:async()=>{n=null}}}
|
|
95
2
|
//# sourceMappingURL=testing.js.map
|
package/dist/testing.js.map
CHANGED
|
@@ -1 +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":"
|
|
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":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,kBAAAC,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,8BAAAC,EAAA,kCAAAC,EAAA,6BAAAC,IAAA,eAAAC,EAAAT,GAoCO,SAASK,EAAYK,EAAoB,CAAC,EAAGC,EAAmB,CAAC,EAAiB,CACvF,IAAMC,EAAuB,CAAC,EAC9B,QAAWC,KAAMH,EAASE,EAAOC,CAAE,EAAI,UACvC,QAAWA,KAAMF,EAAQC,EAAOC,CAAE,EAAI,SACtC,OAAOD,CACT,CAMO,SAASR,EAAeU,EAAmC,CAChE,OAAOT,EAAYS,EAAW,CAAC,CAAC,CAClC,CAMO,SAASX,EAAcW,EAAmC,CAC/D,OAAOT,EAAY,CAAC,EAAGS,CAAS,CAClC,CASO,SAASN,EAAyBO,EAA6B,CACpE,OAAO,cACL,IAAI,YAAY,4BAA6B,CAAE,OAAQ,CAAE,QAAAA,CAAQ,EAAG,QAAS,EAAK,CAAC,CACrF,CACF,CAMO,SAAST,EAA0BU,EAAqB,GAAa,CAC1E,OAAO,cACL,IAAI,YAAY,6BAA8B,CAC5C,OAAQ,CAAE,mBAAAA,CAAmB,EAC7B,QAAS,EACX,CAAC,CACH,CACF,CAMO,SAAST,EAA8BQ,EAA6B,CACzE,OAAO,cACL,IAAI,YAAY,iCAAkC,CAAE,OAAQ,CAAE,QAAAA,CAAQ,EAAG,QAAS,EAAK,CAAC,CAC1F,CACF,CAiDO,SAASb,EAAmBa,EAA+B,KAAyB,CACzF,IAAIE,EAAiBF,EAErB,MAAO,CACL,WAAY,IAAME,IAAmB,KACrC,WAAY,IAAMA,EAClB,eAAgB,IAAOA,IAAmB,KAAO,IAAI,KAAS,GAC9D,cAAe,IAAM,KAErB,cAAe,MAAOC,GAAmC,CACvDD,EAAiB,CAAE,GAAIA,GAAkB,CAAC,EAAI,GAAGC,CAAQ,EACzDV,EAAyBS,CAAc,CACzC,EAEA,cAAe,SAAY,CACzBA,EAAiB,IACnB,EAEA,WAAY,IAAM,CAAC,EACnB,WAAY,IAAM,CAAC,EACnB,UAAW,IAAM,CAAC,EAClB,UAAW,IAAM,CAAC,EAClB,iBAAkB,IAAM,GACxB,gBAAiB,IAAM,GAEvB,QAAUE,GAAmBA,EAAG,EAChC,MAAO,QAAQ,QAAQ,EAEvB,QAAS,IAAM,CAAC,EAEhB,UAAW,SAAY,CACrBF,EAAiB,IACnB,CACF,CACF","names":["testing_exports","__export","createMockConsenti","mockAllDenied","mockAllGranted","mockConsent","simulateBannerInitialized","simulateConsentBeingSubmitted","simulateConsentSubmitted","__toCommonJS","granted","denied","result","id","cookieIds","consent","hasExistingConsent","currentConsent","partial","cb"]}
|
package/dist/testing.mjs
CHANGED
|
@@ -1,74 +1,2 @@
|
|
|
1
|
-
|
|
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
|
-
};
|
|
1
|
+
function s(e=[],n=[]){let t={};for(let o of e)t[o]="granted";for(let o of n)t[o]="denied";return t}function a(e){return s(e,[])}function l(e){return s([],e)}function i(e){window.dispatchEvent(new CustomEvent("consenti:consentSubmitted",{detail:{consent:e},bubbles:!0}))}function r(e=!1){window.dispatchEvent(new CustomEvent("consenti:bannerInitialized",{detail:{hasExistingConsent:e},bubbles:!0}))}function d(e){window.dispatchEvent(new CustomEvent("consenti:consentBeingSubmitted",{detail:{consent:e},bubbles:!0}))}function u(e=null){let n=e;return{hasConsent:()=>n!==null,getConsent:()=>n,getConsentDate:()=>n!==null?new Date:!1,getGTMConsent:()=>null,submitConsent:async t=>{n={...n??{},...t},i(n)},deleteConsent:async()=>{n=null},showBanner:()=>{},hideBanner:()=>{},showModal:()=>{},hideModal:()=>{},bannerVisibility:()=>!1,modalVisibility:()=>!1,onReady:t=>t(),ready:Promise.resolve(),destroy:()=>{},reConsent:async()=>{n=null}}}export{u as createMockConsenti,l as mockAllDenied,a as mockAllGranted,s as mockConsent,r as simulateBannerInitialized,d as simulateConsentBeingSubmitted,i as simulateConsentSubmitted};
|
|
74
2
|
//# sourceMappingURL=testing.mjs.map
|
package/dist/testing.mjs.map
CHANGED
|
@@ -1 +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":"
|
|
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,SAASA,EAAYC,EAAoB,CAAC,EAAGC,EAAmB,CAAC,EAAiB,CACvF,IAAMC,EAAuB,CAAC,EAC9B,QAAWC,KAAMH,EAASE,EAAOC,CAAE,EAAI,UACvC,QAAWA,KAAMF,EAAQC,EAAOC,CAAE,EAAI,SACtC,OAAOD,CACT,CAMO,SAASE,EAAeC,EAAmC,CAChE,OAAON,EAAYM,EAAW,CAAC,CAAC,CAClC,CAMO,SAASC,EAAcD,EAAmC,CAC/D,OAAON,EAAY,CAAC,EAAGM,CAAS,CAClC,CASO,SAASE,EAAyBC,EAA6B,CACpE,OAAO,cACL,IAAI,YAAY,4BAA6B,CAAE,OAAQ,CAAE,QAAAA,CAAQ,EAAG,QAAS,EAAK,CAAC,CACrF,CACF,CAMO,SAASC,EAA0BC,EAAqB,GAAa,CAC1E,OAAO,cACL,IAAI,YAAY,6BAA8B,CAC5C,OAAQ,CAAE,mBAAAA,CAAmB,EAC7B,QAAS,EACX,CAAC,CACH,CACF,CAMO,SAASC,EAA8BH,EAA6B,CACzE,OAAO,cACL,IAAI,YAAY,iCAAkC,CAAE,OAAQ,CAAE,QAAAA,CAAQ,EAAG,QAAS,EAAK,CAAC,CAC1F,CACF,CAiDO,SAASI,EAAmBJ,EAA+B,KAAyB,CACzF,IAAIK,EAAiBL,EAErB,MAAO,CACL,WAAY,IAAMK,IAAmB,KACrC,WAAY,IAAMA,EAClB,eAAgB,IAAOA,IAAmB,KAAO,IAAI,KAAS,GAC9D,cAAe,IAAM,KAErB,cAAe,MAAOC,GAAmC,CACvDD,EAAiB,CAAE,GAAIA,GAAkB,CAAC,EAAI,GAAGC,CAAQ,EACzDP,EAAyBM,CAAc,CACzC,EAEA,cAAe,SAAY,CACzBA,EAAiB,IACnB,EAEA,WAAY,IAAM,CAAC,EACnB,WAAY,IAAM,CAAC,EACnB,UAAW,IAAM,CAAC,EAClB,UAAW,IAAM,CAAC,EAClB,iBAAkB,IAAM,GACxB,gBAAiB,IAAM,GAEvB,QAAUE,GAAmBA,EAAG,EAChC,MAAO,QAAQ,QAAQ,EAEvB,QAAS,IAAM,CAAC,EAEhB,UAAW,SAAY,CACrBF,EAAiB,IACnB,CACF,CACF","names":["mockConsent","granted","denied","result","id","mockAllGranted","cookieIds","mockAllDenied","simulateConsentSubmitted","consent","simulateBannerInitialized","hasExistingConsent","simulateConsentBeingSubmitted","createMockConsenti","currentConsent","partial","cb"]}
|