22
33import * as actionTypes from '../../store/actionCreators/actionTypes'
44import jobsReducer , { initialState } from '../../store/reducers/jobs'
5+ import { stopWatchDuration } from "../../helpers/time" ;
56
67const jobs = require ( '../../../docker/db/data/jobs.json' )
78
@@ -17,3 +18,45 @@ describe('jobs reducer', () => {
1718 expect ( jobsReducer ( initialState , action ) ) . toStrictEqual ( { isLoading : false , result : jobs , init : true } )
1819 } )
1920} )
21+
22+ describe ( 'stopWatchDuration' , ( ) => {
23+ const oneMinute = 60 * 1000 ;
24+ const oneHour = 60 * oneMinute ;
25+ const oneDay = 24 * oneHour ;
26+
27+ it ( 'more than one week' , ( ) => {
28+ const value = stopWatchDuration ( oneDay * 9 )
29+ expect ( "9d 0h 0m 0s" ) . toBe ( value ) ;
30+ } )
31+
32+ it ( 'more than one day' , ( ) => {
33+ const value = stopWatchDuration ( oneDay + oneHour )
34+ expect ( "1d 1h 0m 0s" ) . toBe ( value ) ;
35+ } )
36+
37+ it ( 'less than one day' , ( ) => {
38+ const value = stopWatchDuration ( oneDay - 1000 ) ;
39+ expect ( "23h 59m 59s" ) . toBe ( value ) ;
40+ } )
41+
42+ it ( 'less than one hour' , ( ) => {
43+ const value = stopWatchDuration ( oneHour - 1000 ) ;
44+ expect ( "59m 59s" ) . toBe ( value ) ;
45+ } )
46+
47+ it ( 'less than one minute' , ( ) => {
48+ const value = stopWatchDuration ( oneMinute - 1000 ) ;
49+ expect ( "0m 59s" ) . toBe ( value ) ;
50+ } )
51+
52+ it ( 'less than one second' , ( ) => {
53+ const value = stopWatchDuration ( 999 ) ;
54+ expect ( "999 ms" ) . toBe ( value ) ;
55+ } )
56+
57+ it ( 'no time' , ( ) => {
58+ const value = stopWatchDuration ( 0 ) ;
59+ expect ( "0" ) . toBe ( value ) ;
60+ } )
61+
62+ } )
0 commit comments