@@ -559,6 +559,179 @@ describe('Cron Component - Custom Headers', () => {
559559 expect ( screen . getByText ( 'Monthly' ) ) . toBeInTheDocument ( ) ;
560560 expect ( screen . getByText ( 'Custom' ) ) . toBeInTheDocument ( ) ;
561561 } ) ;
562+ } ) ;
563+
564+ describe ( 'Unix Format Initialization with Values' , ( ) => {
565+ it ( 'should initialize with Unix format value without console errors' , ( ) => {
566+ const onChange = vi . fn ( ) ;
567+ const consoleError = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
568+ const consoleWarn = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
569+
570+ render (
571+ < Cron
572+ value = "*/5 * * * *"
573+ onChange = { onChange }
574+ showResultText = { false }
575+ showResultCron = { true }
576+ isUnix = { true }
577+ /> ,
578+ ) ;
579+
580+ // Should display the Unix value
581+ expect ( screen . getByText ( '*/5 * * * *' ) ) . toBeInTheDocument ( ) ;
582+
583+ // Should not have any console errors
584+ expect ( consoleError ) . not . toHaveBeenCalled ( ) ;
585+ expect ( consoleWarn ) . not . toHaveBeenCalled ( ) ;
586+
587+ consoleError . mockRestore ( ) ;
588+ consoleWarn . mockRestore ( ) ;
589+ } ) ;
590+
591+ it ( 'should initialize with hourly Unix format value' , ( ) => {
592+ const onChange = vi . fn ( ) ;
593+ const consoleError = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
594+
595+ render (
596+ < Cron
597+ value = "0 * * * *"
598+ onChange = { onChange }
599+ showResultText = { false }
600+ showResultCron = { true }
601+ isUnix = { true }
602+ /> ,
603+ ) ;
604+
605+ expect ( screen . getByText ( '0 * * * *' ) ) . toBeInTheDocument ( ) ;
606+ expect ( consoleError ) . not . toHaveBeenCalled ( ) ;
607+
608+ consoleError . mockRestore ( ) ;
609+ } ) ;
610+
611+ it ( 'should initialize with daily Unix format value' , ( ) => {
612+ const onChange = vi . fn ( ) ;
613+ const consoleError = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
614+
615+ render (
616+ < Cron
617+ value = "0 0 * * *"
618+ onChange = { onChange }
619+ showResultText = { false }
620+ showResultCron = { true }
621+ isUnix = { true }
622+ /> ,
623+ ) ;
624+
625+ expect ( screen . getByText ( '0 0 * * *' ) ) . toBeInTheDocument ( ) ;
626+ expect ( consoleError ) . not . toHaveBeenCalled ( ) ;
627+
628+ consoleError . mockRestore ( ) ;
629+ } ) ;
630+
631+ it ( 'should initialize with weekly Unix format value' , ( ) => {
632+ const onChange = vi . fn ( ) ;
633+ const consoleError = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
634+
635+ render (
636+ < Cron
637+ value = "0 0 * * 1"
638+ onChange = { onChange }
639+ showResultText = { false }
640+ showResultCron = { true }
641+ isUnix = { true }
642+ /> ,
643+ ) ;
644+
645+ expect ( screen . getByText ( '0 0 * * 1' ) ) . toBeInTheDocument ( ) ;
646+ expect ( consoleError ) . not . toHaveBeenCalled ( ) ;
647+
648+ consoleError . mockRestore ( ) ;
649+ } ) ;
650+
651+ it ( 'should initialize with monthly Unix format value' , ( ) => {
652+ const onChange = vi . fn ( ) ;
653+ const consoleError = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
654+
655+ render (
656+ < Cron
657+ value = "0 0 1 * *"
658+ onChange = { onChange }
659+ showResultText = { false }
660+ showResultCron = { true }
661+ isUnix = { true }
662+ /> ,
663+ ) ;
664+
665+ expect ( screen . getByText ( '0 0 1 * *' ) ) . toBeInTheDocument ( ) ;
666+ expect ( consoleError ) . not . toHaveBeenCalled ( ) ;
667+
668+ consoleError . mockRestore ( ) ;
669+ } ) ;
670+
671+ it ( 'should handle complex Unix cron expressions' , ( ) => {
672+ const onChange = vi . fn ( ) ;
673+ const consoleError = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
674+
675+ render (
676+ < Cron
677+ value = "*/15 2-5 * * 1-5"
678+ onChange = { onChange }
679+ showResultText = { false }
680+ showResultCron = { true }
681+ isUnix = { true }
682+ /> ,
683+ ) ;
684+
685+ expect ( screen . getByText ( '*/15 2-5 * * 1-5' ) ) . toBeInTheDocument ( ) ;
686+ expect ( consoleError ) . not . toHaveBeenCalled ( ) ;
687+
688+ consoleError . mockRestore ( ) ;
689+ } ) ;
690+
691+ it ( 'should convert Unix to Quartz internally and back to Unix for display' , ( ) => {
692+ const onChange = vi . fn ( ) ;
693+
694+ render (
695+ < Cron
696+ value = "*/5 * * * *"
697+ onChange = { onChange }
698+ showResultText = { true }
699+ showResultCron = { true }
700+ isUnix = { true }
701+ /> ,
702+ ) ;
703+
704+ // Should display Unix format
705+ expect ( screen . getByText ( '*/5 * * * *' ) ) . toBeInTheDocument ( ) ;
706+ // Should have human-readable text
707+ expect ( screen . getByText ( / e v e r y 5 m i n u t e s / i) ) . toBeInTheDocument ( ) ;
708+ } ) ;
709+
710+ it ( 'should handle onChange callback with Unix format' , async ( ) => {
711+ const onChange = vi . fn ( ) ;
712+ const user = userEvent . setup ( ) ;
713+
714+ render (
715+ < Cron
716+ value = "*/5 * * * *"
717+ onChange = { onChange }
718+ showResultText = { false }
719+ showResultCron = { true }
720+ isUnix = { true }
721+ /> ,
722+ ) ;
723+
724+ // Switch to hourly tab
725+ const hourlyTab = screen . getByLabelText ( 'Select Hourly tab' ) ;
726+ await user . click ( hourlyTab ) ;
727+
728+ await waitFor ( ( ) => {
729+ expect ( onChange ) . toHaveBeenCalled ( ) ;
730+ // Should call with Unix format (5 fields)
731+ const lastCall = onChange . mock . calls [ onChange . mock . calls . length - 1 ] ;
732+ expect ( lastCall [ 0 ] . split ( ' ' ) . length ) . toBe ( 5 ) ;
733+ } ) ;
734+ } ) ;
562735
563736 it ( 'should work with custom headers and translations' , ( ) => {
564737 const onChange = vi . fn ( ) ;
0 commit comments