@@ -76,10 +76,40 @@ describe('AttributesTypesForm', () => {
7676 expect ( result . getByText ( 'Invalid number' ) ) . toBeDefined ( ) ;
7777 } ) ;
7878
79- it ( 'switch to boolean attribute' , async ( ) => {
79+ it ( 'switch to number attribute from string containing a numeric value (number is preserved) ' , async ( ) => {
8080 const result = render ( AttributesTypesForm ) ;
8181 await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter' } ) ) ;
8282 await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
83+ await fireEvent . input ( result . getByPlaceholderText ( 'Value' ) , { target : { value : '42' } } ) ;
84+ await fireEvent . change ( result . getByLabelText ( 'Type' ) , { target : { value : 'number' } } ) ;
85+ expect ( result . getByPlaceholderText ( 'Value' ) . value ) . eq ( '42' ) ;
86+ expect ( result . component . validateFields ( ) ) . true ;
87+ } ) ;
88+
89+ it ( 'switch to number attribute from string containing text (number is reset)' , async ( ) => {
90+ const result = render ( AttributesTypesForm ) ;
91+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter' } ) ) ;
92+ await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
93+ await fireEvent . input ( result . getByPlaceholderText ( 'Value' ) , { target : { value : 'foo' } } ) ;
94+ await fireEvent . change ( result . getByLabelText ( 'Type' ) , { target : { value : 'number' } } ) ;
95+ expect ( result . getByPlaceholderText ( 'Value' ) . value ) . eq ( '' ) ;
96+ expect ( result . component . validateFields ( ) ) . false ;
97+ } ) ;
98+
99+ it ( 'switch to boolean attribute, default to false' , async ( ) => {
100+ const result = render ( AttributesTypesForm ) ;
101+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter' } ) ) ;
102+ await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
103+ await fireEvent . change ( result . getByLabelText ( 'Type' ) , { target : { value : 'boolean' } } ) ;
104+ expect ( result . getByLabelText ( 'Value' ) . value ) . eq ( 'false' ) ;
105+ expect ( result . component . validateFields ( ) ) . true ;
106+ } ) ;
107+
108+ it ( 'switch to boolean attribute from string equals to "true", true is set' , async ( ) => {
109+ const result = render ( AttributesTypesForm ) ;
110+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter' } ) ) ;
111+ await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
112+ await fireEvent . input ( result . getByPlaceholderText ( 'Value' ) , { target : { value : 'true' } } ) ;
83113 await fireEvent . change ( result . getByLabelText ( 'Type' ) , { target : { value : 'boolean' } } ) ;
84114 expect ( result . getByLabelText ( 'Value' ) . value ) . eq ( 'true' ) ;
85115 expect ( result . component . validateFields ( ) ) . true ;
0 commit comments