@@ -2,10 +2,22 @@ import { describe, it, mock } from "node:test";
22import assert from "node:assert" ;
33import { initSettings , showSettings , hideSettings , submitSettings , updateSettingsForm } from "../settings.mjs" ;
44
5+ const settingsFormElementEmpty = {
6+ [ "color-scheme" ] : { value : undefined } ,
7+ [ "threshold1" ] : { value : undefined } ,
8+ [ "threshold2" ] : { value : undefined } ,
9+ [ "threshold3" ] : { value : undefined } ,
10+ durationMinutes : { value : undefined } ,
11+ durationSeconds : { value : undefined } ,
12+ orientation : { value : undefined } ,
13+ [ "show-timer" ] : { checked : undefined } ,
14+ [ "play-sound" ] : { checked : undefined } ,
15+ overtime : { checked : undefined } ,
16+ } ;
517
618describe ( 'initSettings' , ( ) => {
719 it ( `Should create settings with given parameters` , ( ) => {
8- const settings = initSettings ( { durationInSeconds : 20 , soundEnabled : true } ) ;
20+ const settings = initSettings ( { durationInSeconds : 20 , soundEnabled : true , settingsFormElement : { ... settingsFormElementEmpty } } ) ;
921
1022 assert . deepEqual ( settings , {
1123 colorScheme : 'zenika-colors' ,
@@ -16,6 +28,7 @@ describe('initSettings', () => {
1628 showTimer : true ,
1729 soundEnabled : true ,
1830 thirdThreshold : 0.95 ,
31+ overtime : true ,
1932 } ) ;
2033 } ) ;
2134} ) ;
@@ -24,7 +37,7 @@ describe('initSettings', () => {
2437describe ( 'showSettings' , ( ) => {
2538 it ( `Should open the modal` , ( ) => {
2639 const settingsModalElement = { showModal : mock . fn ( ) , close : mock . fn ( ) } ;
27- initSettings ( { settingsModalElement } ) ;
40+ initSettings ( { settingsModalElement, settingsFormElement : { ... settingsFormElementEmpty } } ) ;
2841
2942 showSettings ( ) ;
3043
@@ -36,7 +49,7 @@ describe('showSettings', () => {
3649describe ( 'hideSettings' , ( ) => {
3750 it ( `Should close the modal` , ( ) => {
3851 const settingsModalElement = { showModal : mock . fn ( ) , close : mock . fn ( ) } ;
39- initSettings ( { settingsModalElement } ) ;
52+ initSettings ( { settingsModalElement, settingsFormElement : { ... settingsFormElementEmpty } } ) ;
4053
4154 hideSettings ( ) ;
4255
@@ -57,22 +70,23 @@ describe('submitSettings', () => {
5770 orientation : { value : 'downward' } ,
5871 [ "show-timer" ] : { checked : false } ,
5972 [ "play-sound" ] : { checked : false } ,
73+ overtime : { checked : false } ,
6074 } ;
6175
6276 it ( `Should close the modal` , ( ) => {
6377 const settingsModalElement = { showModal : mock . fn ( ) , close : mock . fn ( ) } ;
64- initSettings ( { settingsModalElement, settingsFormElement } ) ;
78+ initSettings ( { settingsModalElement, settingsFormElement : { ... settingsFormElementEmpty } } ) ;
6579
66- submitSettings ( ) ;
80+ submitSettings ( settingsFormElement ) ;
6781
6882 assert . equal ( settingsModalElement . close . mock . callCount ( ) , 1 ) ;
6983 } ) ;
7084
7185 it ( `Should update the settings with the given form` , ( ) => {
7286 const settingsModalElement = { showModal : mock . fn ( ) , close : mock . fn ( ) } ;
73- const settings = initSettings ( { settingsModalElement, settingsFormElement } ) ;
87+ const settings = initSettings ( { durationInSeconds : 61 , settingsModalElement, settingsFormElement : { ... settingsFormElementEmpty } } ) ;
7488
75- submitSettings ( ) ;
89+ submitSettings ( settingsFormElement ) ;
7690
7791 assert . deepEqual ( settings , {
7892 colorScheme : 'zenika-other-colors' ,
@@ -83,29 +97,19 @@ describe('submitSettings', () => {
8397 orientation : 'downward' ,
8498 showTimer : false ,
8599 soundEnabled : false ,
100+ overtime : false ,
86101 } ) ;
87102 } ) ;
88103} ) ;
89104
90105
91106describe ( 'updateSettingsForm' , ( ) => {
92- const settingsFormElement = {
93- [ "color-scheme" ] : { value : undefined } ,
94- [ "threshold1" ] : { value : undefined } ,
95- [ "threshold2" ] : { value : undefined } ,
96- [ "threshold3" ] : { value : undefined } ,
97- durationMinutes : { value : undefined } ,
98- durationSeconds : { value : undefined } ,
99- orientation : { value : undefined } ,
100- [ "show-timer" ] : { checked : undefined } ,
101- [ "play-sound" ] : { checked : undefined } ,
102- } ;
103-
104107 it ( `Should update the form with the given settings` , ( ) => {
105108 const settingsModalElement = { showModal : mock . fn ( ) , close : mock . fn ( ) } ;
109+ const settingsFormElement = { ...settingsFormElementEmpty } ;
106110 initSettings ( { settingsModalElement, settingsFormElement, soundEnabled : true , durationInSeconds : 123 } ) ;
107111
108- updateSettingsForm ( ) ;
112+ updateSettingsForm ( settingsFormElement ) ;
109113
110114 assert . deepEqual ( settingsFormElement , {
111115 [ "color-scheme" ] : { value : 'zenika-colors' } ,
@@ -117,6 +121,7 @@ describe('updateSettingsForm', () => {
117121 orientation : { value : 'upward' } ,
118122 [ "show-timer" ] : { checked : true } ,
119123 [ "play-sound" ] : { checked : true } ,
124+ overtime : { checked : true } ,
120125 } ) ;
121126 } ) ;
122127} ) ;
0 commit comments