@@ -676,10 +676,18 @@ describe("DynamicJsonForm Validation Functionality", () => {
676676 onClick = { ( ) => {
677677 const result = formRef . current ?. validateJson ( ) ;
678678 // Add data attributes to make validation result testable
679- const button = document . querySelector ( '[data-testid="validate-button"]' ) as HTMLElement ;
679+ const button = document . querySelector (
680+ '[data-testid="validate-button"]' ,
681+ ) as HTMLElement ;
680682 if ( button && result ) {
681- button . setAttribute ( 'data-validation-valid' , result . isValid . toString ( ) ) ;
682- button . setAttribute ( 'data-validation-error' , result . error || '' ) ;
683+ button . setAttribute (
684+ "data-validation-valid" ,
685+ result . isValid . toString ( ) ,
686+ ) ;
687+ button . setAttribute (
688+ "data-validation-error" ,
689+ result . error || "" ,
690+ ) ;
683691 }
684692 } }
685693 data-testid = "validate-button"
@@ -702,7 +710,7 @@ describe("DynamicJsonForm Validation Functionality", () => {
702710
703711 const TestComponent = ( ) => {
704712 const formRef = useRef < DynamicJsonFormRef > ( null ) ;
705-
713+
706714 return (
707715 < div >
708716 < DynamicJsonForm
@@ -714,10 +722,18 @@ describe("DynamicJsonForm Validation Functionality", () => {
714722 < button
715723 onClick = { ( ) => {
716724 const result = formRef . current ?. validateJson ( ) ;
717- const button = document . querySelector ( '[data-testid="validate-button"]' ) as HTMLElement ;
725+ const button = document . querySelector (
726+ '[data-testid="validate-button"]' ,
727+ ) as HTMLElement ;
718728 if ( button && result ) {
719- button . setAttribute ( 'data-validation-valid' , result . isValid . toString ( ) ) ;
720- button . setAttribute ( 'data-validation-error' , result . error || '' ) ;
729+ button . setAttribute (
730+ "data-validation-valid" ,
731+ result . isValid . toString ( ) ,
732+ ) ;
733+ button . setAttribute (
734+ "data-validation-error" ,
735+ result . error || "" ,
736+ ) ;
721737 }
722738 } }
723739 data-testid = "validate-button"
@@ -733,8 +749,8 @@ describe("DynamicJsonForm Validation Functionality", () => {
733749 const validateButton = screen . getByTestId ( "validate-button" ) ;
734750 fireEvent . click ( validateButton ) ;
735751
736- expect ( validateButton . getAttribute ( ' data-validation-valid' ) ) . toBe ( ' true' ) ;
737- expect ( validateButton . getAttribute ( ' data-validation-error' ) ) . toBe ( '' ) ;
752+ expect ( validateButton . getAttribute ( " data-validation-valid" ) ) . toBe ( " true" ) ;
753+ expect ( validateButton . getAttribute ( " data-validation-error" ) ) . toBe ( "" ) ;
738754 } ) ;
739755
740756 it ( "should return valid for valid JSON in JSON mode" , ( ) => {
@@ -743,8 +759,8 @@ describe("DynamicJsonForm Validation Functionality", () => {
743759 const validateButton = screen . getByTestId ( "validate-button" ) ;
744760 fireEvent . click ( validateButton ) ;
745761
746- expect ( validateButton . getAttribute ( ' data-validation-valid' ) ) . toBe ( ' true' ) ;
747- expect ( validateButton . getAttribute ( ' data-validation-error' ) ) . toBe ( '' ) ;
762+ expect ( validateButton . getAttribute ( " data-validation-valid" ) ) . toBe ( " true" ) ;
763+ expect ( validateButton . getAttribute ( " data-validation-error" ) ) . toBe ( "" ) ;
748764 } ) ;
749765
750766 it ( "should return invalid for malformed JSON in JSON mode" , async ( ) => {
@@ -759,8 +775,12 @@ describe("DynamicJsonForm Validation Functionality", () => {
759775 const validateButton = screen . getByTestId ( "validate-button" ) ;
760776 fireEvent . click ( validateButton ) ;
761777
762- expect ( validateButton . getAttribute ( 'data-validation-valid' ) ) . toBe ( 'false' ) ;
763- expect ( validateButton . getAttribute ( 'data-validation-error' ) ) . toContain ( 'JSON' ) ;
778+ expect ( validateButton . getAttribute ( "data-validation-valid" ) ) . toBe (
779+ "false" ,
780+ ) ;
781+ expect ( validateButton . getAttribute ( "data-validation-error" ) ) . toContain (
782+ "JSON" ,
783+ ) ;
764784 } ) ;
765785 } ) ;
766786
@@ -769,37 +789,43 @@ describe("DynamicJsonForm Validation Functionality", () => {
769789
770790 // Clear the textarea
771791 const textarea = screen . getByRole ( "textbox" ) ;
772- fireEvent . change ( textarea , { target : { value : '' } } ) ;
792+ fireEvent . change ( textarea , { target : { value : "" } } ) ;
773793
774794 const validateButton = screen . getByTestId ( "validate-button" ) ;
775795 fireEvent . click ( validateButton ) ;
776796
777- expect ( validateButton . getAttribute ( ' data-validation-valid' ) ) . toBe ( ' true' ) ;
778- expect ( validateButton . getAttribute ( ' data-validation-error' ) ) . toBe ( '' ) ;
797+ expect ( validateButton . getAttribute ( " data-validation-valid" ) ) . toBe ( " true" ) ;
798+ expect ( validateButton . getAttribute ( " data-validation-error" ) ) . toBe ( "" ) ;
779799 } ) ;
780800
781801 it ( "should set error state when validation fails" , async ( ) => {
782802 renderFormWithRef ( ) ;
783803
784804 // Enter invalid JSON
785805 const textarea = screen . getByRole ( "textbox" ) ;
786- fireEvent . change ( textarea , { target : { value : '{ "trailing": "comma", }' } } ) ;
806+ fireEvent . change ( textarea , {
807+ target : { value : '{ "trailing": "comma", }' } ,
808+ } ) ;
787809
788810 // Trigger validation
789811 const validateButton = screen . getByTestId ( "validate-button" ) ;
790812 fireEvent . click ( validateButton ) ;
791813
792814 // Check that validation result shows error
793- expect ( validateButton . getAttribute ( 'data-validation-valid' ) ) . toBe ( 'false' ) ;
794- expect ( validateButton . getAttribute ( 'data-validation-error' ) ) . toContain ( 'JSON' ) ;
815+ expect ( validateButton . getAttribute ( "data-validation-valid" ) ) . toBe (
816+ "false" ,
817+ ) ;
818+ expect ( validateButton . getAttribute ( "data-validation-error" ) ) . toContain (
819+ "JSON" ,
820+ ) ;
795821 } ) ;
796822 } ) ;
797823
798824 describe ( "forwardRef functionality" , ( ) => {
799825 it ( "should expose validateJson method through ref" , ( ) => {
800826 const TestComponent = ( ) => {
801827 const formRef = useRef < DynamicJsonFormRef > ( null ) ;
802-
828+
803829 return (
804830 < div >
805831 < DynamicJsonForm
@@ -815,10 +841,16 @@ describe("DynamicJsonForm Validation Functionality", () => {
815841 />
816842 < button
817843 onClick = { ( ) => {
818- const hasValidateMethod = typeof formRef . current ?. validateJson === 'function' ;
819- const button = document . querySelector ( '[data-testid="ref-test-button"]' ) as HTMLElement ;
844+ const hasValidateMethod =
845+ typeof formRef . current ?. validateJson === "function" ;
846+ const button = document . querySelector (
847+ '[data-testid="ref-test-button"]' ,
848+ ) as HTMLElement ;
820849 if ( button ) {
821- button . setAttribute ( 'data-has-validate-method' , hasValidateMethod . toString ( ) ) ;
850+ button . setAttribute (
851+ "data-has-validate-method" ,
852+ hasValidateMethod . toString ( ) ,
853+ ) ;
822854 }
823855 } }
824856 data-testid = "ref-test-button"
@@ -834,7 +866,7 @@ describe("DynamicJsonForm Validation Functionality", () => {
834866 const testButton = screen . getByTestId ( "ref-test-button" ) ;
835867 fireEvent . click ( testButton ) ;
836868
837- expect ( testButton . getAttribute ( ' data-has-validate-method' ) ) . toBe ( ' true' ) ;
869+ expect ( testButton . getAttribute ( " data-has-validate-method" ) ) . toBe ( " true" ) ;
838870 } ) ;
839871 } ) ;
840872} ) ;
0 commit comments