@@ -3,7 +3,7 @@ import { enter, fixtureSync, nextFrame, nextRender } from '@vaadin/testing-helpe
33import sinon from 'sinon' ;
44import '../src/vaadin-time-picker.js' ;
55import { isTouch } from '@vaadin/component-base/src/browser-utils.js' ;
6- import { setInputValue , strictAmPmI18n } from './helpers.js' ;
6+ import { setInputValue } from './helpers.js' ;
77
88describe ( 'time-picker' , ( ) => {
99 let timePicker , inputElement ;
@@ -350,99 +350,6 @@ describe('time-picker', () => {
350350 } ) ;
351351 } ) ;
352352
353- describe ( 'custom functions' , ( ) => {
354- it ( 'should use custom parser if that exists' , ( ) => {
355- timePicker . i18n = { parseTime : sinon . stub ( ) . returns ( { hours : 12 , minutes : 0 , seconds : 0 } ) } ;
356- timePicker . value = '12' ;
357- expect ( timePicker . i18n . parseTime . args [ 0 ] [ 0 ] ) . to . be . equal ( '12:00' ) ;
358- expect ( timePicker . value ) . to . be . equal ( '12:00' ) ;
359- } ) ;
360-
361- it ( 'should align values of dropdown and input when i18n was reassigned' , ( ) => {
362- timePicker . value = '12' ;
363- timePicker . i18n = {
364- formatTime : sinon . stub ( ) . withArgs ( { hours : 12 , minutes : 0 } ) . returns ( '12:00 AM' ) ,
365- parseTime : sinon . stub ( ) . returns ( { hours : 12 , minutes : 0 , seconds : 0 } ) ,
366- } ;
367- expect ( inputElement . value ) . to . be . equal ( '12:00 AM' ) ;
368- expect ( timePicker . value ) . to . be . equal ( '12:00' ) ;
369- } ) ;
370-
371- it ( 'should use custom formatter if that exists' , ( ) => {
372- timePicker . i18n = {
373- formatTime : sinon . stub ( ) . withArgs ( { hours : 12 , minutes : 0 } ) . returns ( '12:00 AM' ) ,
374- parseTime : sinon . stub ( ) . returns ( { hours : 12 , minutes : 0 , seconds : 0 } ) ,
375- } ;
376- timePicker . value = '12' ;
377- expect ( timePicker . value ) . to . be . equal ( '12:00' ) ;
378- expect ( inputElement . value ) . to . be . equal ( '12:00 AM' ) ;
379- } ) ;
380-
381- it ( 'should accept custom time formatter' , ( ) => {
382- timePicker . i18n = {
383- formatTime : sinon . stub ( ) . returns ( '1200' ) ,
384- parseTime : sinon . stub ( ) . withArgs ( '1200' ) . returns ( { hours : 12 , minutes : 0 } ) ,
385- } ;
386- timePicker . value = '12:00' ;
387- expect ( inputElement . value ) . to . equal ( '1200' ) ;
388- expect ( timePicker . value ) . to . equal ( '12:00' ) ;
389- } ) ;
390-
391- it ( 'should fallback to default functions if none are provided' , ( ) => {
392- timePicker . i18n = { } ;
393-
394- timePicker . value = '12:00' ;
395- expect ( inputElement . value ) . to . equal ( '12:00' ) ;
396- expect ( timePicker . value ) . to . equal ( '12:00' ) ;
397- } ) ;
398-
399- it ( 'should keep the value when a custom i18n is set after the value' , ( ) => {
400- timePicker . value = '08:00' ;
401- timePicker . i18n = strictAmPmI18n ;
402- expect ( timePicker . value ) . to . be . equal ( '08:00' ) ;
403- expect ( inputElement . value ) . to . be . equal ( '8:00 AM' ) ;
404- } ) ;
405-
406- [ 'min' , 'max' , 'step' ] . forEach ( ( property ) => {
407- const value = property === 'step' ? 1800 : property === 'min' ? '01:00' : '23:00' ;
408-
409- it ( `should keep the value on ${ property } change with a custom i18n` , ( ) => {
410- timePicker . i18n = strictAmPmI18n ;
411- timePicker . value = '08:00' ;
412- timePicker [ property ] = value ;
413- expect ( timePicker . value ) . to . be . equal ( '08:00' ) ;
414- expect ( inputElement . value ) . to . be . equal ( '8:00 AM' ) ;
415- } ) ;
416- } ) ;
417-
418- it ( 'should commit the value when the custom parser returns stripped seconds' , ( ) => {
419- // The step defaults to minute precision, so the seconds are stripped
420- // from the value, while the custom parser keeps returning them.
421- timePicker . i18n = { parseTime : ( ) => ( { hours : 12 , minutes : 0 , seconds : 0 } ) } ;
422- setInputValue ( timePicker , 'noon' ) ;
423- enter ( inputElement ) ;
424- expect ( timePicker . value ) . to . be . equal ( '12:00' ) ;
425- } ) ;
426-
427- it ( 'should not modify the object returned by the custom parser' , ( ) => {
428- const parsed = { hours : 8 , minutes : 0 , seconds : 0 , milliseconds : 0 } ;
429- timePicker . i18n = { formatTime : strictAmPmI18n . formatTime , parseTime : ( ) => parsed } ;
430- setInputValue ( timePicker , '8:00 AM' ) ;
431- enter ( inputElement ) ;
432- expect ( parsed ) . to . deep . equal ( { hours : 8 , minutes : 0 , seconds : 0 , milliseconds : 0 } ) ;
433- } ) ;
434-
435- it ( 'should not fail when the custom parser returns a frozen object' , ( ) => {
436- timePicker . i18n = {
437- formatTime : strictAmPmI18n . formatTime ,
438- parseTime : ( ) => Object . freeze ( { hours : 8 , minutes : 0 , seconds : 0 , milliseconds : 0 } ) ,
439- } ;
440- setInputValue ( timePicker , '8:00 AM' ) ;
441- enter ( inputElement ) ;
442- expect ( timePicker . value ) . to . be . equal ( '08:00' ) ;
443- } ) ;
444- } ) ;
445-
446353 describe ( 'helper text' , ( ) => {
447354 it ( 'should set helper text content using helperText property' , async ( ) => {
448355 timePicker . helperText = 'foo' ;
0 commit comments