@@ -287,7 +287,7 @@ describe('Enketo: Geolocation Widget', () => {
287287 expect ( changeHandler . callCount ) . to . equal ( 1 ) ;
288288 } ) ;
289289
290- it ( 'should show retry and skip buttons when GPS acquisition fails' , async ( ) => {
290+ it ( 'should show retry button, acknowledgement checkbox, and skip button when GPS acquisition fails' , async ( ) => {
291291 const promise = Promise . resolve ( { code : - 2 , message : 'Geolocation timeout exceeded' } ) ;
292292 window . CHTCore . Geolocation = { currentPromise : promise } ;
293293 buildHtml ( ) ;
@@ -302,9 +302,78 @@ describe('Enketo: Geolocation Widget', () => {
302302 await promise ;
303303
304304 expect ( container . querySelector ( '.geolocation-retry-btn' ) ) . to . not . be . null ;
305+ expect ( container . querySelector ( '.geolocation-acknowledge-checkbox' ) ) . to . not . be . null ;
305306 expect ( container . querySelector ( '.geolocation-skip-btn' ) ) . to . not . be . null ;
306307 } ) ;
307308
309+ it ( 'should disable the "Continue without location" button immediately after GPS failure' , async ( ) => {
310+ const promise = Promise . resolve ( { code : - 2 , message : 'Geolocation timeout exceeded' } ) ;
311+ window . CHTCore . Geolocation = { currentPromise : promise } ;
312+ buildHtml ( ) ;
313+ const widget = createWidget ( ) ;
314+ widget . _isGeolocationAvailable = ( ) => true ;
315+ widget . _init ( ) ;
316+ selectHomeContext ( ) ;
317+
318+ const container = document . querySelector ( '#geolocation-widget-test .or-appearance-geolocation-capture' ) ! ;
319+ ( container . querySelector ( '.geolocation-capture-btn' ) as HTMLElement ) . click ( ) ;
320+
321+ await promise ;
322+
323+ const skipBtn = container . querySelector ( '.geolocation-skip-btn' ) as HTMLButtonElement ;
324+ expect ( skipBtn ) . to . not . be . null ;
325+ expect ( skipBtn . disabled ) . to . be . true ;
326+ } ) ;
327+
328+ it ( 'should enable the "Continue without location" button when the acknowledgement checkbox is checked' , async ( ) => {
329+ const promise = Promise . resolve ( { code : - 2 , message : 'Geolocation timeout exceeded' } ) ;
330+ window . CHTCore . Geolocation = { currentPromise : promise } ;
331+ buildHtml ( ) ;
332+ const widget = createWidget ( ) ;
333+ widget . _isGeolocationAvailable = ( ) => true ;
334+ widget . _init ( ) ;
335+ selectHomeContext ( ) ;
336+
337+ const container = document . querySelector ( '#geolocation-widget-test .or-appearance-geolocation-capture' ) ! ;
338+ ( container . querySelector ( '.geolocation-capture-btn' ) as HTMLElement ) . click ( ) ;
339+
340+ await promise ;
341+
342+ const checkbox = container . querySelector ( '.geolocation-acknowledge-checkbox' ) as HTMLInputElement ;
343+ const skipBtn = container . querySelector ( '.geolocation-skip-btn' ) as HTMLButtonElement ;
344+
345+ checkbox . checked = true ;
346+ $ ( checkbox ) . trigger ( 'change' ) ;
347+
348+ expect ( skipBtn . disabled ) . to . be . false ;
349+ } ) ;
350+
351+ it ( 'should re-disable the "Continue without location" button when the acknowledgement checkbox is unchecked' , async ( ) => {
352+ const promise = Promise . resolve ( { code : - 2 , message : 'Geolocation timeout exceeded' } ) ;
353+ window . CHTCore . Geolocation = { currentPromise : promise } ;
354+ buildHtml ( ) ;
355+ const widget = createWidget ( ) ;
356+ widget . _isGeolocationAvailable = ( ) => true ;
357+ widget . _init ( ) ;
358+ selectHomeContext ( ) ;
359+
360+ const container = document . querySelector ( '#geolocation-widget-test .or-appearance-geolocation-capture' ) ! ;
361+ ( container . querySelector ( '.geolocation-capture-btn' ) as HTMLElement ) . click ( ) ;
362+
363+ await promise ;
364+
365+ const checkbox = container . querySelector ( '.geolocation-acknowledge-checkbox' ) as HTMLInputElement ;
366+ const skipBtn = container . querySelector ( '.geolocation-skip-btn' ) as HTMLButtonElement ;
367+
368+ checkbox . checked = true ;
369+ $ ( checkbox ) . trigger ( 'change' ) ;
370+ expect ( skipBtn . disabled ) . to . be . false ;
371+
372+ checkbox . checked = false ;
373+ $ ( checkbox ) . trigger ( 'change' ) ;
374+ expect ( skipBtn . disabled ) . to . be . true ;
375+ } ) ;
376+
308377 it ( 'should include a map icon in the retry button' , async ( ) => {
309378 const promise = Promise . resolve ( { code : - 2 , message : 'Geolocation timeout exceeded' } ) ;
310379 window . CHTCore . Geolocation = { currentPromise : promise } ;
@@ -359,13 +428,17 @@ describe('Enketo: Geolocation Widget', () => {
359428 const changeHandler = sinon . stub ( ) ;
360429 $ ( widget . element ) . on ( 'change' , changeHandler ) ;
361430
431+ const checkbox = container . querySelector ( '.geolocation-acknowledge-checkbox' ) as HTMLInputElement ;
432+ checkbox . checked = true ;
433+ $ ( checkbox ) . trigger ( 'change' ) ;
434+
362435 ( container . querySelector ( '.geolocation-skip-btn' ) as HTMLElement ) . click ( ) ;
363436
364437 expect ( widget . element . value ) . to . equal ( 'skipped' ) ;
365438 expect ( changeHandler . callCount ) . to . equal ( 1 ) ;
366439 } ) ;
367440
368- it ( 'should remove retry and skip buttons and show a confirmation message when skip is clicked' , async ( ) => {
441+ it ( 'should remove retry, acknowledge, and skip elements and show confirmation when skip is clicked' , async ( ) => {
369442 const promise = Promise . resolve ( { code : - 2 , message : 'Geolocation timeout exceeded' } ) ;
370443 window . CHTCore . Geolocation = { currentPromise : promise } ;
371444 buildHtml ( ) ;
@@ -379,9 +452,14 @@ describe('Enketo: Geolocation Widget', () => {
379452
380453 await promise ;
381454
455+ const checkbox = container . querySelector ( '.geolocation-acknowledge-checkbox' ) as HTMLInputElement ;
456+ checkbox . checked = true ;
457+ $ ( checkbox ) . trigger ( 'change' ) ;
458+
382459 ( container . querySelector ( '.geolocation-skip-btn' ) as HTMLElement ) . click ( ) ;
383460
384461 expect ( container . querySelector ( '.geolocation-retry-btn' ) ) . to . be . null ;
462+ expect ( container . querySelector ( '.geolocation-acknowledge-label' ) ) . to . be . null ;
385463 expect ( container . querySelector ( '.geolocation-skip-btn' ) ) . to . be . null ;
386464 expect ( container . querySelector ( '.geolocation-skipped-msg' ) ) . to . not . be . null ;
387465 } ) ;
0 commit comments