@@ -14,7 +14,13 @@ describe('component tests', () => {
14
14
onSubmit = { jest . fn ( ) }
15
15
FormTemplate = { ( props ) => < FormTemplate { ...props } /> }
16
16
schema = { schema }
17
- componentMapper = { componentMapper }
17
+ componentMapper = { {
18
+ ...componentMapper ,
19
+ 'text-field-number' : {
20
+ component : componentMapper [ componentTypes . TEXT_FIELD ] ,
21
+ type : 'number'
22
+ }
23
+ } }
18
24
{ ...props }
19
25
/>
20
26
) ;
@@ -47,7 +53,8 @@ describe('component tests', () => {
47
53
componentTypes . TIME_PICKER ,
48
54
componentTypes . SWITCH ,
49
55
componentTypes . SELECT ,
50
- componentTypes . SLIDER
56
+ componentTypes . SLIDER ,
57
+ 'text-field-number'
51
58
] . forEach ( ( component ) => {
52
59
describe ( `Component type: ${ component } ` , ( ) => {
53
60
beforeEach ( ( ) => {
@@ -70,6 +77,8 @@ describe('component tests', () => {
70
77
71
78
if ( component === componentTypes . RADIO ) {
72
79
expect ( wrapper . find ( '.bx--radio-button-wrapper' ) ) . toHaveLength ( options . length ) ;
80
+ } else if ( component === 'text-field-number' ) {
81
+ expect ( wrapper . find ( 'NumberInput' ) ) . toHaveLength ( 1 ) ;
73
82
} else {
74
83
expect ( wrapper . find ( componentMapper [ component ] ) ) . toHaveLength ( 1 ) ;
75
84
expect (
@@ -99,96 +108,99 @@ describe('component tests', () => {
99
108
}
100
109
} ) ;
101
110
102
- it ( 'renders with warning' , async ( ) => {
103
- const errorField = {
104
- ...field ,
105
- validate : [ { type : validatorTypes . REQUIRED , warning : true } ] ,
106
- useWarnings : true ,
107
- validateOnMount : true
108
- } ;
109
- let wrapper ;
111
+ if ( component !== 'text-field-number' ) {
112
+ it ( 'renders with warning' , async ( ) => {
113
+ const errorField = {
114
+ ...field ,
115
+ validate : [ { type : validatorTypes . REQUIRED , warning : true } ] ,
116
+ useWarnings : true ,
117
+ validateOnMount : true
118
+ } ;
119
+ let wrapper ;
120
+
121
+ await act ( async ( ) => {
122
+ wrapper = mount ( < RendererWrapper schema = { { fields : [ errorField ] } } /> ) ;
123
+ } ) ;
124
+ wrapper . update ( ) ;
125
+ wrapper . update ( ) ;
126
+
127
+ const helperText = wrapper . find ( '.bx--form__helper-text' ) ;
128
+
129
+ if ( helperText . length ) {
130
+ expect ( helperText . text ( ) ) . toEqual ( errorText ) ;
131
+ } else {
132
+ expect (
133
+ wrapper
134
+ . find ( '.bx--form-requirement' )
135
+ . last ( )
136
+ . text ( )
137
+ ) . toEqual ( errorText ) ;
138
+ }
139
+ } ) ;
140
+
141
+ it ( 'renders with helperText' , ( ) => {
142
+ const helpertextField = {
143
+ ...field ,
144
+ helperText
145
+ } ;
146
+ const wrapper = mount ( < RendererWrapper schema = { { fields : [ helpertextField ] } } /> ) ;
110
147
111
- await act ( async ( ) => {
112
- wrapper = mount ( < RendererWrapper schema = { { fields : [ errorField ] } } /> ) ;
148
+ expect (
149
+ wrapper
150
+ . find ( '.bx--form__helper-text' )
151
+ . last ( )
152
+ . text ( )
153
+ ) . toEqual ( helperText ) ;
113
154
} ) ;
114
- wrapper . update ( ) ;
115
155
116
- const helperText = wrapper . find ( '.bx--form__helper-text' ) ;
156
+ it ( 'renders with description and helperText' , ( ) => {
157
+ const descriptionField = {
158
+ ...field ,
159
+ description,
160
+ helperText
161
+ } ;
162
+ const wrapper = mount ( < RendererWrapper schema = { { fields : [ descriptionField ] } } /> ) ;
163
+
164
+ expect ( wrapper . find ( WithDescription ) ) . toHaveLength ( 1 ) ;
117
165
118
- if ( helperText . length ) {
119
- expect ( helperText . text ( ) ) . toEqual ( errorText ) ;
120
- } else {
121
166
expect (
122
167
wrapper
123
- . find ( '.bx--form-requirement ' )
168
+ . find ( '.bx--form__helper-text ' )
124
169
. last ( )
125
170
. text ( )
126
- ) . toEqual ( errorText ) ;
127
- }
128
- } ) ;
171
+ ) . toEqual ( helperText ) ;
172
+ } ) ;
129
173
130
- it ( 'renders with helperText' , ( ) => {
131
- const helpertextField = {
132
- ...field ,
133
- helperText
134
- } ;
135
- const wrapper = mount ( < RendererWrapper schema = { { fields : [ helpertextField ] } } /> ) ;
136
-
137
- expect (
138
- wrapper
139
- . find ( '.bx--form__helper-text' )
140
- . last ( )
141
- . text ( )
142
- ) . toEqual ( helperText ) ;
143
- } ) ;
174
+ it ( 'renders with error and helperText' , ( ) => {
175
+ const errorFields = {
176
+ ...field ,
177
+ helperText,
178
+ validate : [ { type : validatorTypes . REQUIRED } ]
179
+ } ;
180
+ const wrapper = mount ( < RendererWrapper schema = { { fields : [ errorFields ] } } /> ) ;
181
+ wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
144
182
145
- it ( 'renders with description' , ( ) => {
146
- const descriptionField = {
147
- ...field ,
148
- description
149
- } ;
150
- const wrapper = mount ( < RendererWrapper schema = { { fields : [ descriptionField ] } } /> ) ;
183
+ if ( wrapper . find ( '#field-name-error-msg' ) . length ) {
184
+ expect ( wrapper . find ( '#field-name-error-msg' ) . text ( ) ) . toEqual ( errorText ) ;
185
+ expect ( wrapper . find ( '[invalid=true]' ) . length ) . toBeGreaterThanOrEqual ( 1 ) ;
186
+ }
151
187
152
- expect ( wrapper . find ( WithDescription ) ) . toHaveLength ( 1 ) ;
153
- } ) ;
188
+ if ( wrapper . find ( '.ddorg__carbon-error-helper-text' ) . length ) {
189
+ expect ( wrapper . find ( '.ddorg__carbon-error-helper-text' ) . text ( ) ) . toEqual ( errorText ) ;
190
+ }
191
+
192
+ expect ( wrapper . find ( '.bx--form__helper-text' ) ) . toHaveLength ( 0 ) ;
193
+ } ) ;
194
+ }
154
195
155
- it ( 'renders with description and helperText ' , ( ) => {
196
+ it ( 'renders with description' , ( ) => {
156
197
const descriptionField = {
157
198
...field ,
158
- description,
159
- helperText
199
+ description
160
200
} ;
161
201
const wrapper = mount ( < RendererWrapper schema = { { fields : [ descriptionField ] } } /> ) ;
162
202
163
203
expect ( wrapper . find ( WithDescription ) ) . toHaveLength ( 1 ) ;
164
-
165
- expect (
166
- wrapper
167
- . find ( '.bx--form__helper-text' )
168
- . last ( )
169
- . text ( )
170
- ) . toEqual ( helperText ) ;
171
- } ) ;
172
-
173
- it ( 'renders with error and helperText' , ( ) => {
174
- const errorFields = {
175
- ...field ,
176
- helperText,
177
- validate : [ { type : validatorTypes . REQUIRED } ]
178
- } ;
179
- const wrapper = mount ( < RendererWrapper schema = { { fields : [ errorFields ] } } /> ) ;
180
- wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
181
-
182
- if ( wrapper . find ( '#field-name-error-msg' ) . length ) {
183
- expect ( wrapper . find ( '#field-name-error-msg' ) . text ( ) ) . toEqual ( errorText ) ;
184
- expect ( wrapper . find ( '[invalid=true]' ) . length ) . toBeGreaterThanOrEqual ( 1 ) ;
185
- }
186
-
187
- if ( wrapper . find ( '.ddorg__carbon-error-helper-text' ) . length ) {
188
- expect ( wrapper . find ( '.ddorg__carbon-error-helper-text' ) . text ( ) ) . toEqual ( errorText ) ;
189
- }
190
-
191
- expect ( wrapper . find ( '.bx--form__helper-text' ) ) . toHaveLength ( 0 ) ;
192
204
} ) ;
193
205
194
206
it ( 'renders isDisabled' , ( ) => {
0 commit comments