@@ -32,21 +32,24 @@ describe("Form store", () => {
32
32
const formId = "FORM-ID" ;
33
33
const fieldId = "FIELD-ID" ;
34
34
const initialValue = "INITIAL-VALUE" ;
35
+ const defaultValue = "DEFAULT-VALUE" ;
35
36
const formStore = new FormStore ( formId ) ;
36
37
37
- formStore . RegisterField ( fieldId , initialValue ) ;
38
+ formStore . RegisterField ( fieldId , initialValue , defaultValue ) ;
38
39
expect ( formStore . HasField ( fieldId ) ) . toBe ( true ) ;
39
40
expect ( formStore . GetField ( fieldId ) ) . not . toBeUndefined ( ) ;
40
- expect ( formStore . GetField ( fieldId ) . InitialValue ) . toBe ( initialValue ) ;
41
+ expect ( formStore . GetField ( fieldId ) . Value ) . toBe ( initialValue ) ;
42
+ expect ( formStore . GetField ( fieldId ) . DefaultValue ) . toBe ( defaultValue ) ;
41
43
} ) ;
42
44
43
45
it ( "unregisters a field" , ( ) => {
44
46
const formId = "FORM-ID" ;
45
47
const fieldId = "FIELD-ID" ;
46
48
const initialValue = "INITIAL-VALUE" ;
49
+ const defaultValue = "DEFAULT-VALUE" ;
47
50
const formStore = new FormStore ( formId ) ;
48
51
49
- formStore . RegisterField ( fieldId , initialValue ) ;
52
+ formStore . RegisterField ( fieldId , initialValue , defaultValue ) ;
50
53
formStore . UnregisterField ( fieldId ) ;
51
54
expect ( formStore . GetField ( fieldId ) ) . toBeUndefined ( ) ;
52
55
expect ( formStore . HasField ( fieldId ) ) . toBe ( false ) ;
@@ -56,32 +59,35 @@ describe("Form store", () => {
56
59
const formId = "FORM-ID" ;
57
60
const fieldId = "FIELD-ID" ;
58
61
const initialValue = "INITIAL-VALUE" ;
62
+ const defaultValue = "DEFAULT-VALUE" ;
59
63
const formStore = new FormStore ( formId ) ;
60
64
61
65
expect ( formStore . HasField ( fieldId ) ) . toBe ( false ) ;
62
- formStore . RegisterField ( fieldId , initialValue ) ;
66
+ formStore . RegisterField ( fieldId , initialValue , defaultValue ) ;
63
67
expect ( formStore . HasField ( fieldId ) ) . toBe ( true ) ;
64
68
} ) ;
65
69
66
70
it ( "get a field" , ( ) => {
67
71
const formId = "FORM-ID" ;
68
72
const fieldId = "FIELD-ID" ;
69
73
const initialValue = "INITIAL-VALUE" ;
74
+ const defaultValue = "DEFAULT-VALUE" ;
70
75
const formStore = new FormStore ( formId ) ;
71
76
72
77
expect ( formStore . GetField ( fieldId ) ) . toBeUndefined ( ) ;
73
- formStore . RegisterField ( fieldId , initialValue ) ;
78
+ formStore . RegisterField ( fieldId , initialValue , defaultValue ) ;
74
79
expect ( formStore . GetField ( fieldId ) ) . not . toBeUndefined ( ) ;
75
80
} ) ;
76
81
77
82
it ( "value changed" , ( ) => {
78
83
const formId = "FORM-ID" ;
79
84
const fieldId = "FIELD-ID" ;
80
85
const initialValue = "INITIAL-VALUE" ;
86
+ const defaultValue = "DEFAULT-VALUE" ;
81
87
const nextValue = "NEXT-VALUE" ;
82
88
const formStore = new FormStore ( formId ) ;
83
89
84
- formStore . RegisterField ( fieldId , initialValue ) ;
90
+ formStore . RegisterField ( fieldId , initialValue , defaultValue ) ;
85
91
expect ( formStore . GetField ( fieldId ) . Value ) . toBe ( initialValue ) ;
86
92
formStore . ValueChanged ( fieldId , nextValue ) ;
87
93
expect ( formStore . GetField ( fieldId ) . Value ) . toBe ( nextValue ) ;
@@ -91,9 +97,10 @@ describe("Form store", () => {
91
97
const formId = "FORM-ID" ;
92
98
const fieldId = "FIELD-ID" ;
93
99
const initialValue = "INITIAL-VALUE" ;
100
+ const defaultValue = "DEFAULT-VALUE" ;
94
101
const formStore = new FormStore ( formId ) ;
95
102
96
- formStore . RegisterField ( fieldId , initialValue ) ;
103
+ formStore . RegisterField ( fieldId , initialValue , defaultValue ) ;
97
104
const validationPromise = new Promise < void > ( ( resolve , reject ) => {
98
105
setTimeout ( ( ) => {
99
106
resolve ( ) ;
@@ -120,10 +127,11 @@ describe("Form store", () => {
120
127
const formId = "FORM-ID" ;
121
128
const fieldId = "FIELD-ID" ;
122
129
const initialValue = "INITIAL-VALUE" ;
130
+ const defaultValue = "DEFAULT-VALUE" ;
123
131
const formStore = new FormStore ( formId ) ;
124
132
const formError : FormError = { Message : "Error Message" } ;
125
133
126
- formStore . RegisterField ( fieldId , initialValue ) ;
134
+ formStore . RegisterField ( fieldId , initialValue , defaultValue ) ;
127
135
const validationPromise = new Promise < void > ( ( resolve , reject ) => {
128
136
setTimeout ( ( ) => {
129
137
reject ( formError ) ;
@@ -161,10 +169,11 @@ describe("Form store", () => {
161
169
const formId = "FORM-ID" ;
162
170
const fieldId = "FIELD-ID" ;
163
171
const initialValue = "INITIAL-VALUE" ;
172
+ const defaultValue = "DEFAULT-VALUE" ;
164
173
const formStore = new FormStore ( formId ) ;
165
174
const formError = "field error" ;
166
175
167
- formStore . RegisterField ( fieldId , initialValue ) ;
176
+ formStore . RegisterField ( fieldId , initialValue , defaultValue ) ;
168
177
const validationPromise = new Promise < void > ( ( resolve , reject ) => {
169
178
setTimeout ( ( ) => {
170
179
reject ( formError ) ;
@@ -203,14 +212,16 @@ describe("Form store", () => {
203
212
it ( "registers field with props" , ( ) => {
204
213
const formId = "FORM-ID" ;
205
214
const fieldId = "FIELD-ID" ;
215
+ const defaultValue = "DEFAULT-VALUE" ;
206
216
const fieldProps : MyFieldProps = {
207
217
name : "fieldName" ,
208
218
value : "initial-value" ,
219
+ defaultValue : defaultValue ,
209
220
randomKey : "random value"
210
221
} ;
211
222
const formStore = new FormStore ( formId ) ;
212
223
213
- formStore . RegisterField ( fieldId , fieldProps . value , fieldProps ) ;
224
+ formStore . RegisterField ( fieldId , fieldProps . value , fieldProps . defaultValue , fieldProps ) ;
214
225
215
226
const fieldPropsRecord = recordify < FieldStateProps , FieldStatePropsRecord > ( fieldProps ) ;
216
227
@@ -221,9 +232,11 @@ describe("Form store", () => {
221
232
it ( "updates field props" , ( ) => {
222
233
const formId = "FORM-ID" ;
223
234
const fieldId = "FIELD-ID" ;
235
+ const defaultValue = "DEFAULT-VALUE" ;
224
236
const fieldProps : MyFieldProps = {
225
237
name : "field-name" ,
226
238
value : "initialValue" ,
239
+ defaultValue : defaultValue ,
227
240
randomKey : "random value"
228
241
} ;
229
242
@@ -235,7 +248,7 @@ describe("Form store", () => {
235
248
const fieldPropsNextRecord = recordify < FieldStateProps , FieldStatePropsRecord > ( fieldPropsNext ) ;
236
249
const formStore = new FormStore ( formId ) ;
237
250
238
- formStore . RegisterField ( fieldId , fieldProps . value , fieldProps ) ;
251
+ formStore . RegisterField ( fieldId , fieldProps . value , fieldProps . defaultValue , fieldProps ) ;
239
252
formStore . UpdateProps ( fieldId , fieldPropsNext ) ;
240
253
241
254
// Deep-check the updated props
0 commit comments