@@ -4,6 +4,8 @@ import FormRenderer from '../../form-renderer';
44import FormTemplate from '../../../../../__mocks__/mock-form-template' ;
55import componentTypes from '../../component-types' ;
66import useFieldApi from '../../use-field-api' ;
7+ import convertType from '../../use-field-api/convert-type' ;
8+ import dataTypes from '../../data-types' ;
79
810const DataTypeInput = ( props ) => {
911 const { input, type, label } = useFieldApi ( props ) ;
@@ -69,4 +71,28 @@ describe('data types', () => {
6971 expect . anything ( )
7072 ) ;
7173 } ) ;
74+
75+ describe ( 'converTypes' , ( ) => {
76+ describe ( 'integer' , ( ) => {
77+ it ( 'converts empty string' , ( ) => {
78+ expect ( convertType ( dataTypes . INTEGER , '' ) ) . toEqual ( '' ) ;
79+ } ) ;
80+
81+ it ( 'converts zero' , ( ) => {
82+ expect ( convertType ( dataTypes . INTEGER , '0' ) ) . toEqual ( 0 ) ;
83+ } ) ;
84+
85+ it ( 'converts an integer' , ( ) => {
86+ expect ( convertType ( dataTypes . INTEGER , '12132' ) ) . toEqual ( 12132 ) ;
87+ } ) ;
88+
89+ it ( 'converts a string' , ( ) => {
90+ expect ( convertType ( dataTypes . INTEGER , 'abcd' ) ) . toEqual ( 'abcd' ) ;
91+ } ) ;
92+
93+ it ( 'converts a negative integer' , ( ) => {
94+ expect ( convertType ( dataTypes . INTEGER , '-12132' ) ) . toEqual ( - 12132 ) ;
95+ } ) ;
96+ } ) ;
97+ } ) ;
7298} ) ;
0 commit comments