2
2
3
3
import { CourseSetting , DBCourseSetting , GlobalSetting , SettingType
4
4
} from 'src/common/models/settings' ;
5
+ import { convertTimeDuration , humanReadableTimeDuration } from 'src/common/models/parsers' ;
5
6
6
7
describe ( 'Testing Course Settings' , ( ) => {
7
8
const global_setting = {
@@ -804,7 +805,7 @@ describe('Testing Course Settings', () => {
804
805
805
806
course_setting . set ( {
806
807
setting_name : 'time_duration' ,
807
- default_value : '10 days' ,
808
+ default_value : 1234 ,
808
809
description : 'I am an time interval' ,
809
810
doc : 'Extended help' ,
810
811
type : 'time_duration' ,
@@ -816,6 +817,9 @@ describe('Testing Course Settings', () => {
816
817
course_setting . set ( { value : 3.14 } ) ;
817
818
expect ( course_setting . isValid ( ) ) . toBe ( false ) ;
818
819
820
+ course_setting . set ( { value : '3 days' } ) ;
821
+ expect ( course_setting . isValid ( ) ) . toBe ( false ) ;
822
+
819
823
course_setting . set ( { value : 'hi' } ) ;
820
824
expect ( course_setting . isValid ( ) ) . toBe ( false ) ;
821
825
@@ -824,4 +828,71 @@ describe('Testing Course Settings', () => {
824
828
} ) ;
825
829
826
830
} ) ;
831
+
832
+ describe ( 'Test converting of human readable time duration to number of seconds' , ( ) => {
833
+ test ( 'Test time duration of seconds' , ( ) => {
834
+ expect ( convertTimeDuration ( '1 sec' ) ) . toBe ( 1 ) ;
835
+ expect ( convertTimeDuration ( '15 secs' ) ) . toBe ( 15 ) ;
836
+ } ) ;
837
+
838
+ test ( 'Test time duration of mins' , ( ) => {
839
+ expect ( convertTimeDuration ( '1 min' ) ) . toBe ( 60 ) ;
840
+ expect ( convertTimeDuration ( '5 mins' ) ) . toBe ( 5 * 60 ) ;
841
+ expect ( convertTimeDuration ( '5 mins, 30 secs' ) ) . toBe ( 5 * 60 + 30 ) ;
842
+ } ) ;
843
+
844
+ test ( 'Test time duration of hours' , ( ) => {
845
+ expect ( convertTimeDuration ( '1 hour' ) ) . toBe ( 1 * 60 * 60 ) ;
846
+ expect ( convertTimeDuration ( '1 hr' ) ) . toBe ( 1 * 60 * 60 ) ;
847
+ expect ( convertTimeDuration ( '5 hours' ) ) . toBe ( 5 * 60 * 60 ) ;
848
+ expect ( convertTimeDuration ( '3 hrs' ) ) . toBe ( 3 * 60 * 60 ) ;
849
+ expect ( convertTimeDuration ( '3 hrs, 10 mins, 15 seconds' ) ) . toBe ( 3 * 60 * 60 + 10 * 60 + 15 ) ;
850
+ } ) ;
851
+
852
+ test ( 'Test time duration of days' , ( ) => {
853
+ expect ( convertTimeDuration ( '1 day' ) ) . toBe ( 1 * 24 * 60 * 60 ) ;
854
+ expect ( convertTimeDuration ( '3 days' ) ) . toBe ( 3 * 24 * 60 * 60 ) ;
855
+ expect ( convertTimeDuration ( '3 days, 12 hours' ) ) . toBe ( 3 * 24 * 60 * 60 + 12 * 60 * 60 ) ;
856
+ } ) ;
857
+
858
+ test ( 'Test time duration of weeks' , ( ) => {
859
+ expect ( convertTimeDuration ( '1 week' ) ) . toBe ( 1 * 7 * 24 * 60 * 60 ) ;
860
+ expect ( convertTimeDuration ( '2 weeks' ) ) . toBe ( 2 * 7 * 24 * 60 * 60 ) ;
861
+ expect ( convertTimeDuration ( '2 weeks, 5 days' ) ) . toBe ( 2 * 7 * 24 * 60 * 60 + 5 * 24 * 60 * 60 ) ;
862
+ } ) ;
863
+
864
+ } ) ;
865
+
866
+ describe ( 'Test conversion of num. seconds to human readable time durations' , ( ) => {
867
+ test ( 'Test time duration of secs' , ( ) => {
868
+ expect ( humanReadableTimeDuration ( 0 ) ) . toBe ( '' ) ;
869
+ expect ( humanReadableTimeDuration ( 1 ) ) . toBe ( '1 sec' ) ;
870
+ expect ( humanReadableTimeDuration ( 15 ) ) . toBe ( '15 secs' ) ;
871
+ } ) ;
872
+
873
+ test ( 'Test time duration of mins' , ( ) => {
874
+ expect ( humanReadableTimeDuration ( 60 ) ) . toBe ( '1 min' ) ;
875
+ expect ( humanReadableTimeDuration ( 5 * 60 ) ) . toBe ( '5 mins' ) ;
876
+ expect ( humanReadableTimeDuration ( 5 * 60 + 30 ) ) . toBe ( '5 mins, 30 secs' ) ;
877
+ } ) ;
878
+
879
+ test ( 'Test time duration of hours' , ( ) => {
880
+ expect ( humanReadableTimeDuration ( 3600 ) ) . toBe ( '1 hour' ) ;
881
+ expect ( humanReadableTimeDuration ( 5 * 3600 ) ) . toBe ( '5 hours' ) ;
882
+ expect ( humanReadableTimeDuration ( 5 * 3600 + 30 * 60 ) ) . toBe ( '5 hours, 30 mins' ) ;
883
+ } ) ;
884
+
885
+ test ( 'Test time duration of days' , ( ) => {
886
+ expect ( humanReadableTimeDuration ( 3600 * 24 ) ) . toBe ( '1 day' ) ;
887
+ expect ( humanReadableTimeDuration ( 3 * 3600 * 24 ) ) . toBe ( '3 days' ) ;
888
+ expect ( humanReadableTimeDuration ( 3 * 3600 * 24 + 6 * 3600 ) ) . toBe ( '3 days, 6 hours' ) ;
889
+ expect ( humanReadableTimeDuration ( 3 * 3600 * 24 + 6 * 3600 + 30 * 60 ) ) . toBe ( '3 days, 6 hours, 30 mins' ) ;
890
+ } ) ;
891
+
892
+ test ( 'Test time duration of weeks' , ( ) => {
893
+ expect ( humanReadableTimeDuration ( 3600 * 24 * 7 ) ) . toBe ( '1 week' ) ;
894
+ expect ( humanReadableTimeDuration ( 3600 * 24 * 7 * 2 ) ) . toBe ( '2 weeks' ) ;
895
+ expect ( humanReadableTimeDuration ( 3600 * 24 * 7 * 2 + 3 * 3600 * 24 ) ) . toBe ( '2 weeks, 3 days' ) ;
896
+ } ) ;
897
+ } ) ;
827
898
} ) ;
0 commit comments