@@ -145,8 +145,9 @@ describe('NewsletterForm class works', () => {
145145 newsletter . bindEvents ( )
146146 const elements = getFormElements ( )
147147
148- // Enter valid email and submit
148+ // Enter valid email, check consent, and submit
149149 elements . emailInput . value = 'test@example.com'
150+ elements . consentCheckbox . checked = true
150151 const submitEvent = new Event ( 'submit' )
151152 await elements . form . dispatchEvent ( submitEvent )
152153
@@ -158,7 +159,7 @@ describe('NewsletterForm class works', () => {
158159 headers : {
159160 'Content-Type' : 'application/json' ,
160161 } ,
161- body : JSON . stringify ( { email : 'test@example.com' } ) ,
162+ body : JSON . stringify ( { email : 'test@example.com' , consentGiven : true } ) ,
162163 } )
163164 } )
164165
@@ -175,8 +176,9 @@ describe('NewsletterForm class works', () => {
175176 newsletter . bindEvents ( )
176177 const elements = getFormElements ( )
177178
178- // Enter valid email and submit
179+ // Enter valid email, check consent, and submit
179180 elements . emailInput . value = 'test@example.com'
181+ elements . consentCheckbox . checked = true
180182 const submitEvent = new Event ( 'submit' )
181183 await elements . form . dispatchEvent ( submitEvent )
182184
@@ -196,8 +198,9 @@ describe('NewsletterForm class works', () => {
196198 newsletter . bindEvents ( )
197199 const elements = getFormElements ( )
198200
199- // Enter valid email and submit
201+ // Enter valid email, check consent, and submit
200202 elements . emailInput . value = 'test@example.com'
203+ elements . consentCheckbox . checked = true
201204 const submitEvent = new Event ( 'submit' )
202205 await elements . form . dispatchEvent ( submitEvent )
203206
@@ -226,7 +229,7 @@ describe('NewsletterForm class works', () => {
226229 elements . emailInput . value = 'test@example.com'
227230 elements . emailInput . dispatchEvent ( blurEvent )
228231
229- expect ( elements . message . textContent ) . toBe ( 'We respect your privacy. Unsubscribe at any time.' )
232+ expect ( elements . message . textContent ) . toBe ( "You'll receive a confirmation email. Click the link to complete your subscription." )
230233 expect ( elements . message . classList . contains ( 'text-[var(--color-text-offset)]' ) ) . toBe ( true )
231234 } )
232235
@@ -275,18 +278,19 @@ describe('NewsletterForm LoadableScript implementation', () => {
275278} )
276279
277280describe ( 'Edge cases and error handling' , ( ) => {
278- test ( 'handles missing DOM elements gracefully ' , ( ) => {
281+ test ( 'throws error for missing DOM elements' , ( ) => {
279282 // Set up DOM without required elements
280283 document . body . innerHTML = '<div>No newsletter form</div>'
281284
282- expect ( ( ) => NewsletterForm . init ( ) ) . not . toThrow ( )
283- expect ( ( ) => new NewsletterForm ( ) ) . not . toThrow ( )
285+ // Newsletter is a critical component (Phase 1), should throw when instantiated
286+ expect ( ( ) => new NewsletterForm ( ) ) . toThrow ( 'NewsletterForm: Required DOM elements not found' )
284287 } )
285288
286- test ( 'handles form submission without required elements' , async ( ) => {
289+ test ( 'throws error for partially missing elements' , async ( ) => {
290+ // Form exists but missing required input
287291 document . body . innerHTML = '<form id="newsletter-form"></form>'
288292
289- const newsletter = new NewsletterForm ( )
290- expect ( ( ) => newsletter . bindEvents ( ) ) . not . toThrow ( )
293+ // Missing email input and other required elements should throw
294+ expect ( ( ) => new NewsletterForm ( ) ) . toThrow ( 'NewsletterForm: Required DOM elements not found' )
291295 } )
292296} )
0 commit comments