@@ -174,6 +174,136 @@ describe("Form", () => {
174174 } ) ;
175175 } ) ;
176176
177+ describe ( "NumberField" , ( ) => {
178+ describe ( "TextWidget" , ( ) => {
179+ it ( "should render a string field" , ( ) => {
180+ const { node} = createComponent ( { schema : {
181+ type : "number"
182+ } } ) ;
183+
184+ expect ( node . querySelectorAll ( ".field input[type=text]" ) )
185+ . to . have . length . of ( 1 ) ;
186+ } ) ;
187+
188+ it ( "should render a string field with a label" , ( ) => {
189+ const { node} = createComponent ( { schema : {
190+ type : "number" ,
191+ title : "foo"
192+ } } ) ;
193+
194+ expect ( node . querySelector ( ".field label > span" ) . textContent )
195+ . eql ( "foo" ) ;
196+ } ) ;
197+
198+ it ( "should render a string field with a placeholder" , ( ) => {
199+ const { node} = createComponent ( { schema : {
200+ type : "number" ,
201+ description : "bar" ,
202+ } } ) ;
203+
204+ expect ( node . querySelector ( ".field input" ) . getAttribute ( "placeholder" ) )
205+ . eql ( "bar" ) ;
206+ } ) ;
207+
208+ it ( "should assign a default value" , ( ) => {
209+ const { node} = createComponent ( { schema : {
210+ type : "number" ,
211+ default : 2 ,
212+ } } ) ;
213+
214+ expect ( node . querySelector ( ".field input" ) . getAttribute ( "value" ) )
215+ . eql ( "2" ) ;
216+ } ) ;
217+
218+ it ( "should handle a change event" , ( ) => {
219+ const { comp, node} = createComponent ( { schema : {
220+ type : "number" ,
221+ } } ) ;
222+
223+ Simulate . change ( node . querySelector ( "input" ) , {
224+ target : { value : "2" }
225+ } ) ;
226+
227+ expect ( comp . state . formData ) . eql ( 2 ) ;
228+ } ) ;
229+
230+ it ( "should fill field with data" , ( ) => {
231+ const { node} = createComponent ( { schema : {
232+ type : "number" ,
233+ } , formData : 2 } ) ;
234+
235+ expect ( node . querySelector ( ".field input" ) . getAttribute ( "value" ) )
236+ . eql ( "2" ) ;
237+ } ) ;
238+ } ) ;
239+
240+ describe ( "SelectWidget" , ( ) => {
241+ it ( "should render a number field" , ( ) => {
242+ const { node} = createComponent ( { schema : {
243+ type : "number" ,
244+ enum : [ 1 , 2 ]
245+ } } ) ;
246+
247+ expect ( node . querySelectorAll ( ".field select" ) )
248+ . to . have . length . of ( 1 ) ;
249+ } ) ;
250+
251+ it ( "should render a string field with a label" , ( ) => {
252+ const { node} = createComponent ( { schema : {
253+ type : "number" ,
254+ enum : [ 1 , 2 ] ,
255+ title : "foo" ,
256+ } } ) ;
257+
258+ expect ( node . querySelector ( ".field label > span" ) . textContent )
259+ . eql ( "foo" ) ;
260+ } ) ;
261+
262+ it ( "should render a select field with a tooltip" , ( ) => {
263+ const { node} = createComponent ( { schema : {
264+ type : "number" ,
265+ enum : [ 1 , 2 ] ,
266+ description : "baz" ,
267+ } } ) ;
268+
269+ expect ( node . querySelector ( ".field select" ) . getAttribute ( "title" ) )
270+ . eql ( "baz" ) ;
271+ } ) ;
272+
273+ it ( "should assign a default value" , ( ) => {
274+ const { comp} = createComponent ( { schema : {
275+ type : "number" ,
276+ enum : [ 1 , 2 ] ,
277+ default : 1 ,
278+ } } ) ;
279+
280+ expect ( comp . state . formData ) . eql ( 1 ) ;
281+ } ) ;
282+
283+ it ( "should handle a change event" , ( ) => {
284+ const { comp, node} = createComponent ( { schema : {
285+ type : "number" ,
286+ enum : [ 1 , 2 ] ,
287+ } } ) ;
288+
289+ Simulate . change ( node . querySelector ( "select" ) , {
290+ target : { value : "2" }
291+ } ) ;
292+
293+ expect ( comp . state . formData ) . eql ( 2 ) ;
294+ } ) ;
295+
296+ it ( "should fill field with data" , ( ) => {
297+ const { comp} = createComponent ( { schema : {
298+ type : "number" ,
299+ enum : [ 1 , 2 ] ,
300+ } , formData : 2 } ) ;
301+
302+ expect ( comp . state . formData ) . eql ( 2 ) ;
303+ } ) ;
304+ } ) ;
305+ } ) ;
306+
177307 describe ( "BooleanField" , ( ) => {
178308 it ( "should render a boolean field" , ( ) => {
179309 const { node} = createComponent ( { schema : {
0 commit comments