11import { expect } from 'chai' ;
2+ import sinon from 'sinon' ;
23
34import {
45 customFormReplacer ,
@@ -13,6 +14,8 @@ import {
1314 isRemovingDependents ,
1415 isVisiblePicklistPage ,
1516 hasSelectedPicklistItems ,
17+ reformatDate ,
18+ onFormLoaded ,
1619} from '../../config/utilities/formHelpers' ;
1720
1821import { PICKLIST_DATA } from '../../config/constants' ;
@@ -373,3 +376,40 @@ describe('hasSelectedPicklistItems', () => {
373376 expect ( hasSelectedPicklistItems ( getData ( true , true ) ) ) . to . be . true ;
374377 } ) ;
375378} ) ;
379+
380+ describe ( 'reformatDate' , ( ) => {
381+ it ( 'should return empty string for invalid dates' , ( ) => {
382+ expect ( reformatDate ( ) ) . to . be . undefined ;
383+ expect ( reformatDate ( '' ) ) . to . equal ( '' ) ;
384+ expect ( reformatDate ( 'invalid-date' ) ) . to . equal ( 'invalid-date' ) ;
385+ } ) ;
386+
387+ it ( 'should handle double-digit months and days' , ( ) => {
388+ expect ( reformatDate ( '2026-04-05' ) ) . to . equal ( '2026-04-05' ) ;
389+ expect ( reformatDate ( '2026-11-10' ) ) . to . equal ( '2026-11-10' ) ;
390+ expect ( reformatDate ( '2026-12-11' ) ) . to . equal ( '2026-12-11' ) ;
391+ expect ( reformatDate ( '2026-10-31' ) ) . to . equal ( '2026-10-31' ) ;
392+ } ) ;
393+
394+ it ( 'should convert date and include leading zeros in yyyy-MM-dd format' , ( ) => {
395+ expect ( reformatDate ( '2026-1-3' ) ) . to . equal ( '2026-01-03' ) ;
396+ expect ( reformatDate ( '2026-11-4' ) ) . to . equal ( '2026-11-04' ) ;
397+ expect ( reformatDate ( '2026-4-11' ) ) . to . equal ( '2026-04-11' ) ;
398+ } ) ;
399+ } ) ;
400+
401+ describe ( 'onFormLoaded' , ( ) => {
402+ it ( 'should reformat endDate and push to returnUrl' , ( ) => {
403+ const router = { push : sinon . spy ( ) } ;
404+ const formData = {
405+ [ PICKLIST_DATA ] : [ { endDate : '2024-1-1' } , { endDate : '2024-2-2' } ] ,
406+ } ;
407+ const returnUrl = '/test-return-url' ;
408+
409+ onFormLoaded ( { returnUrl, router, formData } ) ;
410+
411+ expect ( formData [ PICKLIST_DATA ] [ 0 ] . endDate ) . to . equal ( '2024-01-01' ) ;
412+ expect ( formData [ PICKLIST_DATA ] [ 1 ] . endDate ) . to . equal ( '2024-02-02' ) ;
413+ expect ( router . push . calledWith ( returnUrl ) ) . to . be . true ;
414+ } ) ;
415+ } ) ;
0 commit comments