88 validateConsent ,
99 isConsentValid
1010} from '@components/GDPR/Consent/client'
11- import { $formConsent , clearFormConsent , type ConsentPurpose } from '@components/GDPR/Consent/state'
11+ import { $formConsent , clearFormConsent } from '@components/GDPR/Consent/state'
1212import { isInputElement , isDivElement } from '@components/scripts/assertions/elements'
1313import { TestError } from '@test/errors'
1414
@@ -58,37 +58,35 @@ describe('initGDPRConsent', () => {
5858
5959 test ( 'initializes checkbox change handler' , ( ) => {
6060 setupConsentForm ( )
61- const purposes : ConsentPurpose [ ] = [ 'contact' ]
61+ const purpose = 'contact'
6262
63- initGDPRConsent ( 'gdpr-consent' , purposes )
63+ initGDPRConsent ( 'gdpr-consent' , purpose )
6464
6565 const { checkbox } = getConsentElements ( )
6666 checkbox . checked = true
6767 checkbox . dispatchEvent ( new Event ( 'change' ) )
6868
6969 const consent = $formConsent . get ( )
70- expect ( consent ?. purposes ) . toEqual ( [ 'contact' ] )
70+ expect ( consent ?. purpose ) . toBe ( 'contact' )
7171 expect ( consent ?. validated ) . toBe ( true )
7272 } )
7373
7474 test ( 'records consent when checkbox is checked' , ( ) => {
7575 setupConsentForm ( )
76- const purposes : ConsentPurpose [ ] = [ 'contact' , 'marketing' ]
77-
78- initGDPRConsent ( 'gdpr-consent' , purposes )
76+ initGDPRConsent ( 'gdpr-consent' , 'contact' )
7977
8078 const { checkbox } = getConsentElements ( )
8179 checkbox . checked = true
8280 checkbox . dispatchEvent ( new Event ( 'change' ) )
8381
8482 const consent = $formConsent . get ( )
85- expect ( consent ?. purposes ) . toEqual ( [ 'contact' , 'marketing' ] )
83+ expect ( consent ?. purpose ) . toBe ( 'contact' )
8684 } )
8785
8886 test ( 'clears consent when checkbox is unchecked' , ( ) => {
8987 setupConsentForm ( )
9088
91- initGDPRConsent ( 'gdpr-consent' , [ 'contact' ] )
89+ initGDPRConsent ( 'gdpr-consent' , 'contact' )
9290
9391 const { checkbox } = getConsentElements ( )
9492
@@ -105,7 +103,7 @@ describe('initGDPRConsent', () => {
105103 test ( 'clears error message when checkbox is checked' , ( ) => {
106104 setupConsentForm ( )
107105
108- initGDPRConsent ( 'gdpr-consent' , [ 'contact' ] )
106+ initGDPRConsent ( 'gdpr-consent' , 'contact' )
109107
110108 const { checkbox, errorElement } = getConsentElements ( )
111109
@@ -124,7 +122,7 @@ describe('initGDPRConsent', () => {
124122 test ( 'includes formId when provided' , ( ) => {
125123 setupConsentForm ( )
126124
127- initGDPRConsent ( 'gdpr-consent' , [ 'contact' ] , 'contact-form' )
125+ initGDPRConsent ( 'gdpr-consent' , 'contact' , 'contact-form' )
128126
129127 const { checkbox } = getConsentElements ( 'gdpr-consent' )
130128 checkbox . checked = true
@@ -137,20 +135,20 @@ describe('initGDPRConsent', () => {
137135 test ( 'works with custom checkbox ID' , ( ) => {
138136 setupConsentForm ( 'custom-consent' )
139137
140- initGDPRConsent ( 'custom-consent' , [ 'marketing' ] )
138+ initGDPRConsent ( 'custom-consent' , 'marketing' )
141139
142140 const { checkbox } = getConsentElements ( 'custom-consent' )
143141 checkbox . checked = true
144142 checkbox . dispatchEvent ( new Event ( 'change' ) )
145143
146144 const consent = $formConsent . get ( )
147- expect ( consent ?. purposes ) . toEqual ( [ 'marketing' ] )
145+ expect ( consent ?. purpose ) . toBe ( 'marketing' )
148146 } )
149147
150148 test ( 'prevents form submission when unchecked' , ( ) => {
151149 const form = setupConsentForm ( )
152150
153- initGDPRConsent ( 'gdpr-consent' , [ 'contact' ] )
151+ initGDPRConsent ( 'gdpr-consent' , 'contact' )
154152
155153 const submitEvent = new Event ( 'submit' , { cancelable : true } )
156154 const preventDefaultSpy = vi . spyOn ( submitEvent , 'preventDefault' )
@@ -163,7 +161,7 @@ describe('initGDPRConsent', () => {
163161 test ( 'allows form submission when checked' , ( ) => {
164162 const form = setupConsentForm ( )
165163
166- initGDPRConsent ( 'gdpr-consent' , [ 'contact' ] )
164+ initGDPRConsent ( 'gdpr-consent' , 'contact' )
167165
168166 const { checkbox } = getConsentElements ( 'gdpr-consent' )
169167 checkbox . checked = true
@@ -179,7 +177,7 @@ describe('initGDPRConsent', () => {
179177 test ( 'focuses checkbox when form submission fails' , ( ) => {
180178 const form = setupConsentForm ( )
181179
182- initGDPRConsent ( 'gdpr-consent' , [ 'contact' ] )
180+ initGDPRConsent ( 'gdpr-consent' , 'contact' )
183181
184182 const { checkbox } = getConsentElements ( 'gdpr-consent' )
185183 const focusSpy = vi . spyOn ( checkbox , 'focus' )
@@ -193,7 +191,7 @@ describe('initGDPRConsent', () => {
193191 document . body . innerHTML = '<div></div>'
194192
195193 // GDPR is a critical component (Phase 1), should throw
196- expect ( ( ) => initGDPRConsent ( 'missing' , [ 'contact' ] ) ) . toThrow ( 'GDPR consent checkbox not found' )
194+ expect ( ( ) => initGDPRConsent ( 'missing' , 'contact' ) ) . toThrow ( / G D P R C o n s e n t : F a i l e d t o f i n d r e q u i r e d e l e m e n t s / )
197195 } )
198196
199197 test ( 'works without form element' , ( ) => {
@@ -205,14 +203,14 @@ describe('initGDPRConsent', () => {
205203 </div>
206204 `
207205
208- initGDPRConsent ( 'gdpr-consent' , [ 'contact' ] )
206+ initGDPRConsent ( 'gdpr-consent' , 'contact' )
209207
210208 const { checkbox } = getConsentElements ( 'gdpr-consent' )
211209 checkbox . checked = true
212210 checkbox . dispatchEvent ( new Event ( 'change' ) )
213211
214212 const consent = $formConsent . get ( )
215- expect ( consent ?. purposes ) . toEqual ( [ 'contact' ] )
213+ expect ( consent ?. purpose ) . toBe ( 'contact' )
216214 } )
217215} )
218216
@@ -339,15 +337,15 @@ describe('integration tests', () => {
339337 test ( 'complete consent flow: check, submit, validate' , ( ) => {
340338 const form = setupConsentForm ( )
341339
342- initGDPRConsent ( 'gdpr-consent' , [ 'contact' ] , 'contact-form' )
340+ initGDPRConsent ( 'gdpr-consent' , 'contact' , 'contact-form' )
343341
344342 // Step 1: Check checkbox
345343 const { checkbox } = getConsentElements ( 'gdpr-consent' )
346344 checkbox . checked = true
347345 checkbox . dispatchEvent ( new Event ( 'change' ) )
348346
349347 // Verify consent recorded
350- expect ( $formConsent . get ( ) ?. purposes ) . toEqual ( [ 'contact' ] )
348+ expect ( $formConsent . get ( ) ?. purpose ) . toBe ( 'contact' )
351349
352350 // Step 2: Submit form
353351 const submitEvent = new Event ( 'submit' , { cancelable : true } )
@@ -364,7 +362,7 @@ describe('integration tests', () => {
364362 test ( 'complete flow: uncheck after check, submit blocked' , ( ) => {
365363 const form = setupConsentForm ( )
366364
367- initGDPRConsent ( 'gdpr-consent' , [ 'contact' ] )
365+ initGDPRConsent ( 'gdpr-consent' , 'contact' )
368366
369367 const { checkbox } = getConsentElements ( 'gdpr-consent' )
370368
@@ -385,19 +383,4 @@ describe('integration tests', () => {
385383 expect ( preventDefaultSpy ) . toHaveBeenCalled ( )
386384 } )
387385
388- test ( 'multiple purposes flow' , ( ) => {
389- setupConsentForm ( )
390-
391- const purposes : ConsentPurpose [ ] = [ 'contact' , 'marketing' , 'analytics' ]
392- initGDPRConsent ( 'gdpr-consent' , purposes , 'multi-form' )
393-
394- const { checkbox } = getConsentElements ( 'gdpr-consent' )
395- checkbox . checked = true
396- checkbox . dispatchEvent ( new Event ( 'change' ) )
397-
398- const consent = $formConsent . get ( )
399- expect ( consent ?. purposes ) . toEqual ( [ 'contact' , 'marketing' , 'analytics' ] )
400- expect ( consent ?. formId ) . toBe ( 'multi-form' )
401- expect ( consent ?. validated ) . toBe ( true )
402- } )
403386} )
0 commit comments