@ht-sdks/consent-manager 0.0.1 → 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 +5 -19
- package/commonjs/__tests__/consent-manager/dialog.test.js +33 -0
- package/commonjs/__tests__/consent-manager-builder/analytics.test.js +53 -46
- package/commonjs/__tests__/consent-manager-builder/index.todo.js +52 -88
- package/commonjs/__tests__/consent-manager-builder/preferences.test.js +59 -71
- package/commonjs/__tests__/index.test.js +12 -12
- package/commonjs/consent-manager/banner.js +35 -19
- package/commonjs/consent-manager/buttons.js +5 -5
- package/commonjs/consent-manager/cancel-dialog.js +26 -10
- package/commonjs/consent-manager/categories.js +2 -2
- package/commonjs/consent-manager/container.js +2 -3
- package/commonjs/consent-manager/dialog.js +39 -23
- package/commonjs/consent-manager/font-styles.js +2 -2
- package/commonjs/consent-manager/index.js +41 -25
- package/commonjs/consent-manager/preference-dialog.js +36 -20
- package/commonjs/consent-manager-builder/analytics.js +3 -7
- package/commonjs/consent-manager-builder/index.js +30 -30
- package/commonjs/consent-manager-builder/preferences.js +28 -21
- package/commonjs/index.js +5 -4
- package/commonjs/standalone.js +25 -11
- package/esm/__tests__/consent-manager/dialog.test.js +28 -0
- package/esm/__tests__/consent-manager-builder/analytics.test.js +41 -34
- package/esm/__tests__/consent-manager-builder/index.todo.js +38 -74
- package/esm/__tests__/consent-manager-builder/preferences.test.js +55 -67
- package/esm/consent-manager/banner.js +5 -3
- package/esm/consent-manager/buttons.js +4 -4
- package/esm/consent-manager/cancel-dialog.js +4 -2
- package/esm/consent-manager/categories.js +2 -2
- package/esm/consent-manager/container.js +1 -1
- package/esm/consent-manager/dialog.js +7 -5
- package/esm/consent-manager/font-styles.js +2 -2
- package/esm/consent-manager/index.js +19 -17
- package/esm/consent-manager/preference-dialog.js +7 -5
- package/esm/consent-manager-builder/analytics.js +2 -6
- package/esm/consent-manager-builder/index.js +26 -26
- package/esm/consent-manager-builder/preferences.js +23 -16
- package/esm/index.js +4 -3
- package/esm/standalone.js +3 -3
- package/esm/types.js +1 -0
- package/package.json +62 -68
- package/src/__tests__/consent-manager/dialog.test.tsx +42 -0
- package/src/__tests__/consent-manager-builder/analytics.test.ts +40 -33
- package/src/__tests__/consent-manager-builder/index.todo.js +56 -96
- package/src/__tests__/consent-manager-builder/preferences.test.ts +64 -75
- package/src/consent-manager/banner.tsx +11 -11
- package/src/consent-manager/buttons.tsx +26 -10
- package/src/consent-manager/cancel-dialog.tsx +1 -1
- package/src/consent-manager/categories.ts +2 -2
- package/src/consent-manager/container.tsx +14 -17
- package/src/consent-manager/dialog.tsx +4 -4
- package/src/consent-manager/font-styles.tsx +12 -2
- package/src/consent-manager/index.tsx +27 -29
- package/src/consent-manager/preference-dialog.tsx +13 -11
- package/src/consent-manager-builder/analytics.ts +8 -5
- package/src/consent-manager-builder/index.tsx +28 -28
- package/src/consent-manager-builder/preferences.ts +31 -21
- package/src/index.ts +8 -4
- package/src/standalone.tsx +1 -1
- package/src/types.ts +8 -3
- package/standalone/consent-manager.js +5 -10
- package/standalone/consent-manager.js.map +1 -1
- package/types/consent-manager/banner.d.ts +1 -1
- package/types/consent-manager/buttons.d.ts +6 -7
- package/types/consent-manager/cancel-dialog.d.ts +1 -1
- package/types/consent-manager/index.d.ts +3 -3
- package/types/consent-manager/preference-dialog.d.ts +1 -1
- package/types/consent-manager-builder/analytics.d.ts +1 -1
- package/types/consent-manager-builder/index.d.ts +7 -8
- package/types/consent-manager-builder/preferences.d.ts +4 -6
- package/types/index.d.ts +1 -1
- package/types/types.d.ts +14 -11
- package/commonjs/__tests__/consent-manager-builder/fetch-destinations.test.js +0 -155
- package/commonjs/consent-manager-builder/fetch-destinations.js +0 -104
- package/esm/__tests__/consent-manager-builder/fetch-destinations.test.js +0 -150
- package/esm/consent-manager-builder/fetch-destinations.js +0 -98
- package/src/__tests__/consent-manager-builder/fetch-destinations.test.ts +0 -89
- package/src/consent-manager-builder/fetch-destinations.ts +0 -50
- package/types/consent-manager-builder/fetch-destinations.d.ts +0 -2
- package/types/src/__tests__/consent-manager-builder/analytics.test.d.ts +0 -1
- package/types/src/__tests__/consent-manager-builder/fetch-destinations.test.d.ts +0 -1
- package/types/src/__tests__/consent-manager-builder/preferences.test.d.ts +0 -1
- package/types/src/__tests__/index.test.d.ts +0 -1
- package/types/src/consent-manager/banner.d.ts +0 -21
- package/types/src/consent-manager/buttons.d.ts +0 -13
- package/types/src/consent-manager/cancel-dialog.d.ts +0 -19
- package/types/src/consent-manager/categories.d.ts +0 -3
- package/types/src/consent-manager/container.d.ts +0 -35
- package/types/src/consent-manager/dialog.d.ts +0 -29
- package/types/src/consent-manager/font-styles.d.ts +0 -2
- package/types/src/consent-manager/index.d.ts +0 -35
- package/types/src/consent-manager/preference-dialog.d.ts +0 -32
- package/types/src/consent-manager-builder/analytics.d.ts +0 -14
- package/types/src/consent-manager-builder/fetch-destinations.d.ts +0 -2
- package/types/src/consent-manager-builder/index.d.ts +0 -126
- package/types/src/consent-manager-builder/preferences.d.ts +0 -26
- package/types/src/index.d.ts +0 -7
- package/types/src/standalone.d.ts +0 -5
- package/types/src/types.d.ts +0 -131
- /package/types/__tests__/{consent-manager-builder/fetch-destinations.test.d.ts → consent-manager/dialog.test.d.ts} +0 -0
|
@@ -13,25 +13,25 @@ describe('ConsentManagerBuilder', () => {
|
|
|
13
13
|
|
|
14
14
|
test.todo('doesn՚t load events.js when consent is required')
|
|
15
15
|
|
|
16
|
-
test.skip('provides a list of enabled destinations', done => {
|
|
16
|
+
test.skip('provides a list of enabled destinations', (done) => {
|
|
17
17
|
nock('https://cdn.hightouch-events.com')
|
|
18
18
|
.get('/v1/projects/123/integrations')
|
|
19
19
|
.reply(200, [
|
|
20
20
|
{
|
|
21
21
|
name: 'Google Analytics',
|
|
22
|
-
creationName: 'Google Analytics'
|
|
22
|
+
creationName: 'Google Analytics',
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
name: 'Amplitude',
|
|
26
|
-
creationName: 'Amplitude'
|
|
27
|
-
}
|
|
26
|
+
creationName: 'Amplitude',
|
|
27
|
+
},
|
|
28
28
|
])
|
|
29
29
|
.get('/v1/projects/abc/integrations')
|
|
30
30
|
.reply(200, [
|
|
31
31
|
{
|
|
32
32
|
name: 'FullStory',
|
|
33
|
-
creationName: 'FullStory'
|
|
34
|
-
}
|
|
33
|
+
creationName: 'FullStory',
|
|
34
|
+
},
|
|
35
35
|
])
|
|
36
36
|
|
|
37
37
|
shallow(
|
|
@@ -40,24 +40,24 @@ describe('ConsentManagerBuilder', () => {
|
|
|
40
40
|
expect(destinations).toMatchObject([
|
|
41
41
|
{
|
|
42
42
|
id: 'Amplitude',
|
|
43
|
-
name: 'Amplitude'
|
|
43
|
+
name: 'Amplitude',
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
id: 'FullStory',
|
|
47
|
-
name: 'FullStory'
|
|
47
|
+
name: 'FullStory',
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
id: 'Google Analytics',
|
|
51
|
-
name: 'Google Analytics'
|
|
52
|
-
}
|
|
51
|
+
name: 'Google Analytics',
|
|
52
|
+
},
|
|
53
53
|
])
|
|
54
54
|
done()
|
|
55
55
|
}}
|
|
56
|
-
</ConsentManagerBuilder
|
|
56
|
+
</ConsentManagerBuilder>,
|
|
57
57
|
)
|
|
58
58
|
})
|
|
59
59
|
|
|
60
|
-
test.skip('provides a list of newly added destinations', done => {
|
|
60
|
+
test.skip('provides a list of newly added destinations', (done) => {
|
|
61
61
|
document.cookie =
|
|
62
62
|
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}}'
|
|
63
63
|
window.htevents = { load() {}, track() {}, addSourceMiddleware() {} }
|
|
@@ -67,12 +67,12 @@ describe('ConsentManagerBuilder', () => {
|
|
|
67
67
|
.reply(200, [
|
|
68
68
|
{
|
|
69
69
|
name: 'Google Analytics',
|
|
70
|
-
creationName: 'Google Analytics'
|
|
70
|
+
creationName: 'Google Analytics',
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
73
|
name: 'Amplitude',
|
|
74
|
-
creationName: 'Amplitude'
|
|
75
|
-
}
|
|
74
|
+
creationName: 'Amplitude',
|
|
75
|
+
},
|
|
76
76
|
])
|
|
77
77
|
|
|
78
78
|
shallow(
|
|
@@ -81,16 +81,16 @@ describe('ConsentManagerBuilder', () => {
|
|
|
81
81
|
expect(newDestinations).toMatchObject([
|
|
82
82
|
{
|
|
83
83
|
name: 'Google Analytics',
|
|
84
|
-
id: 'Google Analytics'
|
|
85
|
-
}
|
|
84
|
+
id: 'Google Analytics',
|
|
85
|
+
},
|
|
86
86
|
])
|
|
87
87
|
done()
|
|
88
88
|
}}
|
|
89
|
-
</ConsentManagerBuilder
|
|
89
|
+
</ConsentManagerBuilder>,
|
|
90
90
|
)
|
|
91
91
|
})
|
|
92
92
|
|
|
93
|
-
test.skip('loads events.js with the user՚s preferences', done => {
|
|
93
|
+
test.skip('loads events.js with the user՚s preferences', (done) => {
|
|
94
94
|
const hteventsLoad = sinon.spy()
|
|
95
95
|
document.cookie =
|
|
96
96
|
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}}'
|
|
@@ -102,8 +102,8 @@ describe('ConsentManagerBuilder', () => {
|
|
|
102
102
|
.reply(200, [
|
|
103
103
|
{
|
|
104
104
|
name: 'Amplitude',
|
|
105
|
-
creationName: 'Amplitude'
|
|
106
|
-
}
|
|
105
|
+
creationName: 'Amplitude',
|
|
106
|
+
},
|
|
107
107
|
])
|
|
108
108
|
|
|
109
109
|
shallow(
|
|
@@ -114,16 +114,16 @@ describe('ConsentManagerBuilder', () => {
|
|
|
114
114
|
expect(hteventsLoad.args[0][1]).toMatchObject({
|
|
115
115
|
integrations: {
|
|
116
116
|
All: false,
|
|
117
|
-
Amplitude: true
|
|
118
|
-
}
|
|
117
|
+
Amplitude: true,
|
|
118
|
+
},
|
|
119
119
|
})
|
|
120
120
|
done()
|
|
121
121
|
}}
|
|
122
|
-
</ConsentManagerBuilder
|
|
122
|
+
</ConsentManagerBuilder>,
|
|
123
123
|
)
|
|
124
124
|
})
|
|
125
125
|
|
|
126
|
-
test.skip('provides an object containing the WIP preferences', done => {
|
|
126
|
+
test.skip('provides an object containing the WIP preferences', (done) => {
|
|
127
127
|
document.cookie =
|
|
128
128
|
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}}'
|
|
129
129
|
window.htevents = { load() {}, track() {}, addSourceMiddleware() {} }
|
|
@@ -133,30 +133,30 @@ describe('ConsentManagerBuilder', () => {
|
|
|
133
133
|
.reply(200, [
|
|
134
134
|
{
|
|
135
135
|
name: 'Amplitude',
|
|
136
|
-
creationName: 'Amplitude'
|
|
137
|
-
}
|
|
136
|
+
creationName: 'Amplitude',
|
|
137
|
+
},
|
|
138
138
|
])
|
|
139
139
|
|
|
140
140
|
shallow(
|
|
141
141
|
<ConsentManagerBuilder writeKey="123">
|
|
142
142
|
{({ preferences }) => {
|
|
143
143
|
expect(preferences).toMatchObject({
|
|
144
|
-
Amplitude: true
|
|
144
|
+
Amplitude: true,
|
|
145
145
|
})
|
|
146
146
|
done()
|
|
147
147
|
}}
|
|
148
|
-
</ConsentManagerBuilder
|
|
148
|
+
</ConsentManagerBuilder>,
|
|
149
149
|
)
|
|
150
150
|
})
|
|
151
151
|
|
|
152
|
-
test.skip('does not imply consent on interacation', done => {
|
|
152
|
+
test.skip('does not imply consent on interacation', (done) => {
|
|
153
153
|
nock('https://cdn.hightouch-events.com')
|
|
154
154
|
.get('/v1/projects/123/integrations')
|
|
155
155
|
.reply(200, [
|
|
156
156
|
{
|
|
157
157
|
name: 'Amplitude',
|
|
158
|
-
creationName: 'Amplitude'
|
|
159
|
-
}
|
|
158
|
+
creationName: 'Amplitude',
|
|
159
|
+
},
|
|
160
160
|
])
|
|
161
161
|
|
|
162
162
|
shallow(
|
|
@@ -165,26 +165,30 @@ describe('ConsentManagerBuilder', () => {
|
|
|
165
165
|
expect(preferences).toMatchObject({})
|
|
166
166
|
done()
|
|
167
167
|
}}
|
|
168
|
-
</ConsentManagerBuilder
|
|
168
|
+
</ConsentManagerBuilder>,
|
|
169
169
|
)
|
|
170
170
|
})
|
|
171
171
|
|
|
172
|
-
test.skip('if defaultDestinationBehavior is set to imply and category is set to true, loads new destination', done => {
|
|
172
|
+
test.skip('if defaultDestinationBehavior is set to imply and category is set to true, loads new destination', (done) => {
|
|
173
173
|
document.cookie =
|
|
174
174
|
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}%2C%22custom%22:{%22advertising%22:false%2C%22marketingAndAnalytics%22:true%2C%22functional%22:true}}'
|
|
175
|
-
window.htevents = {
|
|
175
|
+
window.htevents = {
|
|
176
|
+
load() {},
|
|
177
|
+
track() {},
|
|
178
|
+
addSourceMiddleware() {},
|
|
179
|
+
}
|
|
176
180
|
|
|
177
181
|
nock('https://cdn.hightouch-events.com')
|
|
178
182
|
.get('/v1/projects/123/integrations')
|
|
179
183
|
.reply(200, [
|
|
180
184
|
{
|
|
181
185
|
name: 'Google Analytics',
|
|
182
|
-
creationName: 'Google Analytics'
|
|
186
|
+
creationName: 'Google Analytics',
|
|
183
187
|
},
|
|
184
188
|
{
|
|
185
189
|
name: 'Amplitude',
|
|
186
|
-
creationName: 'Amplitude'
|
|
187
|
-
}
|
|
190
|
+
creationName: 'Amplitude',
|
|
191
|
+
},
|
|
188
192
|
])
|
|
189
193
|
|
|
190
194
|
shallow(
|
|
@@ -209,7 +213,7 @@ describe('ConsentManagerBuilder', () => {
|
|
|
209
213
|
for (const destination of destinations) {
|
|
210
214
|
// Mark advertising destinations
|
|
211
215
|
if (
|
|
212
|
-
ADVERTISING_CATEGORIES.find(c => c === destination.category) &&
|
|
216
|
+
ADVERTISING_CATEGORIES.find((c) => c === destination.category) &&
|
|
213
217
|
destinationPreferences[destination.id] !== false
|
|
214
218
|
) {
|
|
215
219
|
destinationPreferences[destination.id] = customPrefs.advertising
|
|
@@ -217,7 +221,7 @@ describe('ConsentManagerBuilder', () => {
|
|
|
217
221
|
|
|
218
222
|
// Mark function destinations
|
|
219
223
|
if (
|
|
220
|
-
FUNCTIONAL_CATEGORIES.find(c => c === destination.category) &&
|
|
224
|
+
FUNCTIONAL_CATEGORIES.find((c) => c === destination.category) &&
|
|
221
225
|
destinationPreferences[destination.id] !== false
|
|
222
226
|
) {
|
|
223
227
|
destinationPreferences[destination.id] = customPrefs.functional
|
|
@@ -235,22 +239,21 @@ describe('ConsentManagerBuilder', () => {
|
|
|
235
239
|
{({ destinationPreferences }) => {
|
|
236
240
|
expect(destinationPreferences).toMatchObject({
|
|
237
241
|
Amplitude: true,
|
|
238
|
-
'Google Analytics': true
|
|
242
|
+
'Google Analytics': true,
|
|
239
243
|
})
|
|
240
244
|
done()
|
|
241
245
|
}}
|
|
242
|
-
</ConsentManagerBuilder
|
|
246
|
+
</ConsentManagerBuilder>,
|
|
243
247
|
)
|
|
244
248
|
})
|
|
245
249
|
|
|
246
|
-
test.skip('if defaultDestinationBehavior is set to imply and category is set to false, does not load new destination', done => {
|
|
250
|
+
test.skip('if defaultDestinationBehavior is set to imply and category is set to false, does not load new destination', (done) => {
|
|
247
251
|
document.cookie =
|
|
248
252
|
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}%2C%22custom%22:{%22advertising%22:false%2C%22marketingAndAnalytics%22:false%2C%22functional%22:true}}'
|
|
249
253
|
window.htevents = {
|
|
250
254
|
load() {},
|
|
251
|
-
identify() {},
|
|
252
255
|
track() {},
|
|
253
|
-
addSourceMiddleware() {}
|
|
256
|
+
addSourceMiddleware() {},
|
|
254
257
|
}
|
|
255
258
|
|
|
256
259
|
nock('https://cdn.hightouch-events.com')
|
|
@@ -258,12 +261,12 @@ describe('ConsentManagerBuilder', () => {
|
|
|
258
261
|
.reply(200, [
|
|
259
262
|
{
|
|
260
263
|
name: 'Google Analytics',
|
|
261
|
-
creationName: 'Google Analytics'
|
|
264
|
+
creationName: 'Google Analytics',
|
|
262
265
|
},
|
|
263
266
|
{
|
|
264
267
|
name: 'Amplitude',
|
|
265
|
-
creationName: 'Amplitude'
|
|
266
|
-
}
|
|
268
|
+
creationName: 'Amplitude',
|
|
269
|
+
},
|
|
267
270
|
])
|
|
268
271
|
|
|
269
272
|
shallow(
|
|
@@ -289,7 +292,7 @@ describe('ConsentManagerBuilder', () => {
|
|
|
289
292
|
for (const destination of destinations) {
|
|
290
293
|
// Mark advertising destinations
|
|
291
294
|
if (
|
|
292
|
-
ADVERTISING_CATEGORIES.find(c => c === destination.category) &&
|
|
295
|
+
ADVERTISING_CATEGORIES.find((c) => c === destination.category) &&
|
|
293
296
|
destinationPreferences[destination.id] !== false
|
|
294
297
|
) {
|
|
295
298
|
destinationPreferences[destination.id] = customPrefs.advertising
|
|
@@ -297,7 +300,7 @@ describe('ConsentManagerBuilder', () => {
|
|
|
297
300
|
|
|
298
301
|
// Mark function destinations
|
|
299
302
|
if (
|
|
300
|
-
FUNCTIONAL_CATEGORIES.find(c => c === destination.category) &&
|
|
303
|
+
FUNCTIONAL_CATEGORIES.find((c) => c === destination.category) &&
|
|
301
304
|
destinationPreferences[destination.id] !== false
|
|
302
305
|
) {
|
|
303
306
|
destinationPreferences[destination.id] = customPrefs.functional
|
|
@@ -315,64 +318,21 @@ describe('ConsentManagerBuilder', () => {
|
|
|
315
318
|
{({ destinationPreferences }) => {
|
|
316
319
|
expect(destinationPreferences).toMatchObject({
|
|
317
320
|
Amplitude: false,
|
|
318
|
-
'Google Analytics': false
|
|
321
|
+
'Google Analytics': false,
|
|
319
322
|
})
|
|
320
323
|
done()
|
|
321
324
|
}}
|
|
322
|
-
</ConsentManagerBuilder
|
|
325
|
+
</ConsentManagerBuilder>,
|
|
323
326
|
)
|
|
324
327
|
})
|
|
325
328
|
|
|
326
|
-
test.skip('a different cdn is used when cdnHost is set', done => {
|
|
327
|
-
nock('https://foo.bar.com')
|
|
328
|
-
.get('/v1/projects/123/integrations')
|
|
329
|
-
.reply(200, [
|
|
330
|
-
{
|
|
331
|
-
name: 'Google Analytics',
|
|
332
|
-
creationName: 'Google Analytics'
|
|
333
|
-
},
|
|
334
|
-
{
|
|
335
|
-
name: 'Amplitude',
|
|
336
|
-
creationName: 'Amplitude'
|
|
337
|
-
}
|
|
338
|
-
])
|
|
339
|
-
.get('/v1/projects/abc/integrations')
|
|
340
|
-
.reply(200, [
|
|
341
|
-
{
|
|
342
|
-
name: 'FullStory',
|
|
343
|
-
creationName: 'FullStory'
|
|
344
|
-
}
|
|
345
|
-
])
|
|
346
|
-
|
|
347
|
-
shallow(
|
|
348
|
-
<ConsentManagerBuilder writeKey="123" cdnHost="foo.bar.com">
|
|
349
|
-
{({ destinations }) => {
|
|
350
|
-
expect(destinations).toMatchObject([
|
|
351
|
-
{
|
|
352
|
-
id: 'Amplitude',
|
|
353
|
-
name: 'Amplitude'
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
id: 'FullStory',
|
|
357
|
-
name: 'FullStory'
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
id: 'Google Analytics',
|
|
361
|
-
name: 'Google Analytics'
|
|
362
|
-
}
|
|
363
|
-
])
|
|
364
|
-
done()
|
|
365
|
-
}}
|
|
366
|
-
</ConsentManagerBuilder>
|
|
367
|
-
)
|
|
368
|
-
})
|
|
369
329
|
test.todo('loads events.js normally when consent isn՚t required')
|
|
370
330
|
test.todo('still applies preferences when consent isn՚t required')
|
|
371
331
|
test.todo('provides a setPreferences() function for setting the preferences')
|
|
372
332
|
test.todo('setPreferences() function can be passed a boolean to set all preferences')
|
|
373
333
|
test.todo('provides a resetPreferences() function for resetting the preferences')
|
|
374
334
|
test.todo(
|
|
375
|
-
'provides a saveConsent() function for persisting the preferences and loading events.js'
|
|
335
|
+
'provides a saveConsent() function for persisting the preferences and loading events.js',
|
|
376
336
|
)
|
|
377
337
|
test.todo('saveConsent() can be passed additional preferences to persist')
|
|
378
338
|
test.todo('saveConsent() can be passed a boolean to set all preferences')
|
|
@@ -3,15 +3,33 @@ import sinon from 'sinon'
|
|
|
3
3
|
import {
|
|
4
4
|
loadPreferences,
|
|
5
5
|
savePreferences,
|
|
6
|
-
DEFAULT_COOKIE_NAME
|
|
6
|
+
DEFAULT_COOKIE_NAME,
|
|
7
7
|
} from '../../consent-manager-builder/preferences'
|
|
8
|
+
import { HtEventsBrowser } from '../../types'
|
|
8
9
|
|
|
9
10
|
describe('preferences', () => {
|
|
11
|
+
let htevents: sinon.SinonStubbedInstance<Pick<HtEventsBrowser, 'track'>>
|
|
12
|
+
|
|
13
|
+
function expectConsentUpdatedEvent({ destinationPreferences, customPreferences }) {
|
|
14
|
+
expect(htevents.track.calledOnce).toBe(true)
|
|
15
|
+
expect(htevents.track.args[0][0]).toBe('Consent Updated')
|
|
16
|
+
expect(htevents.track.args[0][1]).toMatchObject({
|
|
17
|
+
destinationPreferences: destinationPreferences,
|
|
18
|
+
categoryPreferences: customPreferences,
|
|
19
|
+
})
|
|
20
|
+
expect(htevents.track.args[0][2]).toMatchObject({
|
|
21
|
+
consent: {
|
|
22
|
+
destinationPreferences: destinationPreferences,
|
|
23
|
+
categoryPreferences: customPreferences,
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
10
28
|
beforeEach(() => {
|
|
11
29
|
window = {
|
|
12
30
|
location: {
|
|
13
|
-
href: 'http://localhost/'
|
|
14
|
-
}
|
|
31
|
+
href: 'http://localhost/',
|
|
32
|
+
},
|
|
15
33
|
} as Window & typeof globalThis
|
|
16
34
|
|
|
17
35
|
document = {
|
|
@@ -21,8 +39,22 @@ describe('preferences', () => {
|
|
|
21
39
|
}
|
|
22
40
|
|
|
23
41
|
return
|
|
24
|
-
}
|
|
42
|
+
},
|
|
25
43
|
} as Document
|
|
44
|
+
document.cookie = ''
|
|
45
|
+
|
|
46
|
+
htevents = sinon.stub({ track() {} })
|
|
47
|
+
;(window as any).htevents = htevents
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('loadPreferences() returns empty preferences when cookie is missing', () => {
|
|
51
|
+
expect(loadPreferences()).toEqual({})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('loadPreferences() returns empty preferences when cookie is invalid JSON', () => {
|
|
55
|
+
document.cookie = `${DEFAULT_COOKIE_NAME}=not-json`
|
|
56
|
+
|
|
57
|
+
expect(loadPreferences()).toEqual({})
|
|
26
58
|
})
|
|
27
59
|
|
|
28
60
|
test('loadPreferences() returns preferences when cookie exists', () => {
|
|
@@ -30,11 +62,11 @@ describe('preferences', () => {
|
|
|
30
62
|
|
|
31
63
|
expect(loadPreferences()).toMatchObject({
|
|
32
64
|
destinationPreferences: {
|
|
33
|
-
Amplitude: true
|
|
65
|
+
Amplitude: true,
|
|
34
66
|
},
|
|
35
67
|
customPreferences: {
|
|
36
|
-
functional: true
|
|
37
|
-
}
|
|
68
|
+
functional: true,
|
|
69
|
+
},
|
|
38
70
|
})
|
|
39
71
|
})
|
|
40
72
|
|
|
@@ -44,113 +76,70 @@ describe('preferences', () => {
|
|
|
44
76
|
|
|
45
77
|
expect(loadPreferences('custom-tracking-preferences')).toMatchObject({
|
|
46
78
|
destinationPreferences: {
|
|
47
|
-
Amplitude: true
|
|
79
|
+
Amplitude: true,
|
|
48
80
|
},
|
|
49
81
|
customPreferences: {
|
|
50
|
-
functional: true
|
|
51
|
-
}
|
|
82
|
+
functional: true,
|
|
83
|
+
},
|
|
52
84
|
})
|
|
53
85
|
})
|
|
54
86
|
|
|
55
87
|
test('savePreferences() saves the preferences', () => {
|
|
56
|
-
const htevents = { identify: sinon.spy(), track: sinon.spy() }
|
|
57
|
-
;(window as any).htevents = htevents
|
|
58
|
-
document.cookie = ''
|
|
59
|
-
|
|
60
88
|
const destinationPreferences = {
|
|
61
|
-
Amplitude: true
|
|
89
|
+
Amplitude: true,
|
|
62
90
|
}
|
|
91
|
+
|
|
63
92
|
const customPreferences = {
|
|
64
|
-
functional: true
|
|
93
|
+
functional: true,
|
|
65
94
|
}
|
|
66
95
|
|
|
67
96
|
savePreferences({
|
|
68
97
|
destinationPreferences,
|
|
69
98
|
customPreferences,
|
|
70
|
-
cookieDomain: undefined
|
|
99
|
+
cookieDomain: undefined,
|
|
71
100
|
})
|
|
72
101
|
|
|
73
|
-
|
|
74
|
-
expect(htevents.identify.args[0][0]).toMatchObject({
|
|
75
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
76
|
-
categoryTrackingPreferences: customPreferences
|
|
77
|
-
})
|
|
102
|
+
expectConsentUpdatedEvent({ destinationPreferences, customPreferences })
|
|
78
103
|
|
|
79
|
-
expect(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
83
|
-
categoryTrackingPreferences: customPreferences
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
expect(
|
|
87
|
-
document.cookie.includes(
|
|
88
|
-
`${DEFAULT_COOKIE_NAME}={%22version%22:1%2C%22destination%22:{%22Amplitude%22:true}%2C%22custom%22:{%22functional%22:true}}`
|
|
89
|
-
)
|
|
90
|
-
).toBe(true)
|
|
104
|
+
expect(document.cookie).toContain(
|
|
105
|
+
`${DEFAULT_COOKIE_NAME}={%22version%22:1%2C%22destination%22:{%22Amplitude%22:true}%2C%22custom%22:{%22functional%22:true}}`,
|
|
106
|
+
)
|
|
91
107
|
})
|
|
92
108
|
|
|
93
109
|
test('savePreferences() sets the cookie domain', () => {
|
|
94
|
-
const htevents = { identify: sinon.spy(), track: sinon.spy() }
|
|
95
|
-
;(window as any).htevents = htevents
|
|
96
|
-
document.cookie = ''
|
|
97
|
-
|
|
98
110
|
const destinationPreferences = {
|
|
99
|
-
Amplitude: true
|
|
111
|
+
Amplitude: true,
|
|
100
112
|
}
|
|
101
113
|
|
|
114
|
+
const customPreferences = undefined
|
|
115
|
+
|
|
102
116
|
savePreferences({
|
|
103
117
|
destinationPreferences,
|
|
104
|
-
customPreferences
|
|
105
|
-
cookieDomain: 'example.com'
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
expect(htevents.identify.calledOnce).toBe(true)
|
|
109
|
-
expect(htevents.identify.args[0][0]).toMatchObject({
|
|
110
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
111
|
-
categoryTrackingPreferences: undefined
|
|
118
|
+
customPreferences,
|
|
119
|
+
cookieDomain: 'example.com',
|
|
112
120
|
})
|
|
113
121
|
|
|
114
|
-
|
|
115
|
-
expect(htevents.track.args[0][0]).toBe('Consent Updated')
|
|
116
|
-
expect(htevents.track.args[0][1]).toMatchObject({
|
|
117
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
118
|
-
categoryTrackingPreferences: undefined
|
|
119
|
-
})
|
|
122
|
+
expectConsentUpdatedEvent({ destinationPreferences, customPreferences })
|
|
120
123
|
|
|
121
|
-
//
|
|
122
|
-
// expect(document.cookie.includes('domain=example.com')).toBe(true)
|
|
124
|
+
// ToDo: verify cookie domain is set (would need to mock js-cookie since document.cookie doesn't have domain info)
|
|
123
125
|
})
|
|
124
126
|
|
|
125
127
|
test('savePreferences() sets the cookie with custom key', () => {
|
|
126
|
-
const htevents = { identify: sinon.spy(), track: sinon.spy() }
|
|
127
|
-
;(window as any).htevents = htevents
|
|
128
|
-
document.cookie = ''
|
|
129
|
-
|
|
130
128
|
const destinationPreferences = {
|
|
131
|
-
Amplitude: true
|
|
129
|
+
Amplitude: true,
|
|
132
130
|
}
|
|
133
131
|
|
|
132
|
+
const customPreferences = undefined
|
|
133
|
+
|
|
134
134
|
savePreferences({
|
|
135
135
|
destinationPreferences,
|
|
136
|
-
customPreferences
|
|
136
|
+
customPreferences,
|
|
137
137
|
cookieDomain: undefined,
|
|
138
|
-
cookieName: 'custom-tracking-preferences'
|
|
138
|
+
cookieName: 'custom-tracking-preferences',
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
expect(htevents.identify.args[0][0]).toMatchObject({
|
|
143
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
144
|
-
categoryTrackingPreferences: undefined
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
expect(htevents.track.calledOnce).toBe(true)
|
|
148
|
-
expect(htevents.track.args[0][0]).toBe('Consent Updated')
|
|
149
|
-
expect(htevents.track.args[0][1]).toMatchObject({
|
|
150
|
-
destinationTrackingPreferences: destinationPreferences,
|
|
151
|
-
categoryTrackingPreferences: undefined
|
|
152
|
-
})
|
|
141
|
+
expectConsentUpdatedEvent({ destinationPreferences, customPreferences })
|
|
153
142
|
|
|
154
|
-
expect(document.cookie.
|
|
143
|
+
expect(document.cookie).toContain('custom-tracking-preferences')
|
|
155
144
|
})
|
|
156
145
|
})
|
|
@@ -40,9 +40,9 @@ const RootCentered = styled('div')<RootProps>`
|
|
|
40
40
|
position: relative;
|
|
41
41
|
max-width: 500px;
|
|
42
42
|
padding: 18px;
|
|
43
|
-
padding-right: ${props => (props.hideCloseButton ? '18px' : '40px')};
|
|
44
|
-
background: ${props => props.backgroundColor};
|
|
45
|
-
color: ${props => props.textColor};
|
|
43
|
+
padding-right: ${(props) => (props.hideCloseButton ? '18px' : '40px')};
|
|
44
|
+
background: ${(props) => props.backgroundColor};
|
|
45
|
+
color: ${(props) => props.textColor};
|
|
46
46
|
text-align: center;
|
|
47
47
|
font-size: 14px;
|
|
48
48
|
line-height: 1.3;
|
|
@@ -52,9 +52,9 @@ const Root = styled('div')<RootProps>`
|
|
|
52
52
|
${fontStyles};
|
|
53
53
|
position: relative;
|
|
54
54
|
padding: 8px;
|
|
55
|
-
padding-right: ${props => (props.hideCloseButton ? '8px' : '40px')};
|
|
56
|
-
background: ${props => props.backgroundColor};
|
|
57
|
-
color: ${props => props.textColor};
|
|
55
|
+
padding-right: ${(props) => (props.hideCloseButton ? '8px' : '40px')};
|
|
56
|
+
background: ${(props) => props.backgroundColor};
|
|
57
|
+
color: ${(props) => props.textColor};
|
|
58
58
|
text-align: center;
|
|
59
59
|
font-size: 12px;
|
|
60
60
|
line-height: 1.3;
|
|
@@ -65,10 +65,10 @@ const Root = styled('div')<RootProps>`
|
|
|
65
65
|
`
|
|
66
66
|
|
|
67
67
|
const Content = styled('div')<ContentProps>`
|
|
68
|
-
margin-bottom: ${props => (props.asModal ? '20px' : '8px')};
|
|
68
|
+
margin-bottom: ${(props) => (props.asModal ? '20px' : '8px')};
|
|
69
69
|
@media (min-width: 768px) {
|
|
70
70
|
flex: auto;
|
|
71
|
-
margin-bottom: ${props => (props.asModal ? '20px' : '0')};
|
|
71
|
+
margin-bottom: ${(props) => (props.asModal ? '20px' : '0')};
|
|
72
72
|
}
|
|
73
73
|
a,
|
|
74
74
|
button {
|
|
@@ -109,7 +109,7 @@ interface CloseButtonProps {
|
|
|
109
109
|
const CloseButton = styled('button')<CloseButtonProps>`
|
|
110
110
|
position: absolute;
|
|
111
111
|
right: 8px;
|
|
112
|
-
top: ${props => (props.isTop ? '20px' : '50%')};
|
|
112
|
+
top: ${(props) => (props.isTop ? '20px' : '50%')};
|
|
113
113
|
transform: translateY(-50%);
|
|
114
114
|
padding: 8px;
|
|
115
115
|
border: none;
|
|
@@ -152,7 +152,7 @@ export default class Banner extends PureComponent<BannerProps> {
|
|
|
152
152
|
onAcceptAll,
|
|
153
153
|
onDenyAll,
|
|
154
154
|
hideCloseButton,
|
|
155
|
-
asModal
|
|
155
|
+
asModal,
|
|
156
156
|
} = this.props
|
|
157
157
|
|
|
158
158
|
const RootContent = (
|
|
@@ -169,7 +169,7 @@ export default class Banner extends PureComponent<BannerProps> {
|
|
|
169
169
|
actionsBlock({
|
|
170
170
|
acceptAll: onAcceptAll,
|
|
171
171
|
denyAll: onDenyAll,
|
|
172
|
-
changePreferences: onChangePreferences
|
|
172
|
+
changePreferences: onChangePreferences,
|
|
173
173
|
})}
|
|
174
174
|
{actionsBlock === true && (
|
|
175
175
|
<ActionsBlock id="hightouchio_actionBlock">
|