@@ -5,10 +5,9 @@ import { spy } from "sinon";
5
5
6
6
import { FormStoresHandlerClass , FSHContainer } from "../../src/stores/form-stores-handler" ;
7
7
import { FormStore } from "../../src/stores/form-store" ;
8
- import { BasicForm } from "../basic -components/basic -form" ;
9
- import { BasicField } from "../basic -components/basic -field" ;
8
+ import { MyTestForm } from "../test -components/test -form" ;
9
+ import { MyTestField , MyFieldProps } from "../test -components/test -field" ;
10
10
import { FormChildContext } from "../../src/contracts/form" ;
11
- import { MyFieldProps } from "../basic-components/basic-field" ;
12
11
13
12
describe ( "Field Base" , ( ) => {
14
13
beforeEach ( ( ) => {
@@ -21,7 +20,7 @@ describe("Field Base", () => {
21
20
22
21
it ( "is rendered outside of Form" , ( ) => {
23
22
expect ( ( ) => shallow (
24
- < BasicField name = "fieldName" > </ BasicField >
23
+ < MyTestField name = "fieldName" > </ MyTestField >
25
24
) ) . toThrow ( ) ;
26
25
} ) ;
27
26
@@ -30,9 +29,9 @@ describe("Field Base", () => {
30
29
const formId = "FORM_ID" ;
31
30
const fieldName = "fieldName" ;
32
31
33
- mount ( < BasicForm formId = { formId } >
34
- < BasicField name = "fieldName" > </ BasicField >
35
- </ BasicForm > ) ;
32
+ mount ( < MyTestForm formId = { formId } >
33
+ < MyTestField name = "fieldName" > </ MyTestField >
34
+ </ MyTestForm > ) ;
36
35
37
36
const formStore = FormStoresHandler . GetStore ( formId ) ;
38
37
const fieldId = formStore . GetFieldId ( fieldName ) ;
@@ -45,9 +44,9 @@ describe("Field Base", () => {
45
44
const formId = "FORM_ID" ;
46
45
const fieldName = "fieldName" ;
47
46
48
- let form = mount ( < BasicForm formId = { formId } >
49
- < BasicField name = "fieldName" > </ BasicField >
50
- </ BasicForm > ) ;
47
+ let form = mount ( < MyTestForm formId = { formId } >
48
+ < MyTestField name = "fieldName" > </ MyTestField >
49
+ </ MyTestForm > ) ;
51
50
52
51
let formStore = FormStoresHandler . GetStore ( formId ) ;
53
52
const fieldId = formStore . GetFieldId ( fieldName ) ;
@@ -67,9 +66,9 @@ describe("Field Base", () => {
67
66
const formId = "FORM_ID" ;
68
67
const fieldName = "fieldName" ;
69
68
70
- let form = mount ( < BasicForm formId = { formId } >
71
- < BasicField destroyOnUnmount = { true } name = "fieldName" > </ BasicField >
72
- </ BasicForm > ) ;
69
+ let form = mount ( < MyTestForm formId = { formId } >
70
+ < MyTestField destroyOnUnmount = { true } name = "fieldName" > </ MyTestField >
71
+ </ MyTestForm > ) ;
73
72
74
73
let formStore = FormStoresHandler . GetStore ( formId ) ;
75
74
const fieldId = formStore . GetFieldId ( fieldName ) ;
@@ -88,42 +87,42 @@ describe("Field Base", () => {
88
87
expect ( ( ) => {
89
88
const fieldName = "fieldName" ;
90
89
91
- mount ( < BasicForm >
92
- < BasicField name = { fieldName } > </ BasicField >
93
- < BasicField name = { fieldName } > </ BasicField >
94
- </ BasicForm > ) ;
90
+ mount ( < MyTestForm >
91
+ < MyTestField name = { fieldName } > </ MyTestField >
92
+ < MyTestField name = { fieldName } > </ MyTestField >
93
+ </ MyTestForm > ) ;
95
94
} ) . toThrow ( ) ;
96
95
} ) ;
97
96
98
97
it ( "throws when rendering an empty fieldName" , ( ) => {
99
98
expect ( ( ) => {
100
- mount ( < BasicForm >
101
- < BasicField name = "" > </ BasicField >
102
- </ BasicForm > ) ;
99
+ mount ( < MyTestForm >
100
+ < MyTestField name = "" > </ MyTestField >
101
+ </ MyTestForm > ) ;
103
102
} ) . toThrow ( ) ;
104
103
} ) ;
105
104
106
105
it ( "throws when rendering an undefined fieldName" , ( ) => {
107
106
expect ( ( ) => {
108
- mount ( < BasicForm >
109
- < BasicField name = { undefined as any } > </ BasicField >
110
- </ BasicForm > ) ;
107
+ mount ( < MyTestForm >
108
+ < MyTestField name = { undefined as any } > </ MyTestField >
109
+ </ MyTestForm > ) ;
111
110
} ) . toThrow ( ) ;
112
111
} ) ;
113
112
114
113
it ( "throws when rendering a null fieldName" , ( ) => {
115
114
expect ( ( ) => {
116
- mount ( < BasicForm >
117
- < BasicField name = { null as any } > </ BasicField >
118
- </ BasicForm > ) ;
115
+ mount ( < MyTestForm >
116
+ < MyTestField name = { null as any } > </ MyTestField >
117
+ </ MyTestForm > ) ;
119
118
} ) . toThrow ( ) ;
120
119
} ) ;
121
120
122
121
it ( "renders html without wrappers" , ( ) => {
123
122
const formId = "FORM_ID" ;
124
- let form = mount ( < BasicForm formId = { formId } >
125
- < BasicField name = "fieldName" > </ BasicField >
126
- </ BasicForm > ) ;
123
+ let form = mount ( < MyTestForm formId = { formId } >
124
+ < MyTestField name = "fieldName" > </ MyTestField >
125
+ </ MyTestForm > ) ;
127
126
128
127
const formDOM = ReactDOM . findDOMNode ( form . instance ( ) ) ;
129
128
expect ( formDOM . tagName ) . toEqual ( "FORM" ) ;
@@ -134,9 +133,9 @@ describe("Field Base", () => {
134
133
it ( "adds event listener to form store when mounts" , ( ) => {
135
134
const FormStoresHandler = FSHContainer . FormStoresHandler ;
136
135
const formId = "FORM_ID" ;
137
- mount ( < BasicForm formId = { formId } >
138
- < BasicField name = "fieldName" > </ BasicField >
139
- </ BasicForm > ) ;
136
+ mount ( < MyTestForm formId = { formId } >
137
+ < MyTestField name = "fieldName" > </ MyTestField >
138
+ </ MyTestForm > ) ;
140
139
141
140
const formStore = FormStoresHandler . GetStore ( formId ) ;
142
141
@@ -146,9 +145,9 @@ describe("Field Base", () => {
146
145
it ( "removes event listener form store when destroyOnUnmount is true and it is unmounted" , ( ) => {
147
146
const FormStoresHandler = FSHContainer . FormStoresHandler ;
148
147
const formId = "FORM_ID" ;
149
- const form = mount ( < BasicForm formId = { formId } >
150
- < BasicField name = "fieldName" destroyOnUnmount = { true } > </ BasicField >
151
- </ BasicForm > ) ;
148
+ const form = mount ( < MyTestForm formId = { formId } >
149
+ < MyTestField name = "fieldName" destroyOnUnmount = { true } > </ MyTestField >
150
+ </ MyTestForm > ) ;
152
151
153
152
const formStore = FormStoresHandler . GetStore ( formId ) ;
154
153
expect ( formStore . listenersCount ( ) ) . toBe ( 1 ) ;
@@ -168,9 +167,9 @@ describe("Field Base", () => {
168
167
spy ( FormStore . prototype , "ValueChanged" ) ;
169
168
170
169
const fieldName = "fieldName" ;
171
- const form = mount ( < BasicForm formId = { formId } >
172
- < BasicField name = { fieldName } > </ BasicField >
173
- </ BasicForm > ) ;
170
+ const form = mount ( < MyTestForm formId = { formId } >
171
+ < MyTestField name = { fieldName } > </ MyTestField >
172
+ </ MyTestForm > ) ;
174
173
const formStore = FSHContainer . FormStoresHandler . GetStore ( formId ) ;
175
174
176
175
expect ( ( FormStore . prototype . ValueChanged as any ) . callCount ) . toEqual ( 0 ) ;
@@ -192,9 +191,9 @@ describe("Field Base", () => {
192
191
const newValue = "NEW_VALUE" ;
193
192
const fieldName = "fieldName" ;
194
193
195
- const form = mount ( < BasicForm >
196
- < BasicField name = { fieldName } > </ BasicField >
197
- </ BasicForm > ) ;
194
+ const form = mount ( < MyTestForm >
195
+ < MyTestField name = { fieldName } > </ MyTestField >
196
+ </ MyTestForm > ) ;
198
197
199
198
const input = form . find ( "input" ) ;
200
199
@@ -216,9 +215,9 @@ describe("Field Base", () => {
216
215
value : "initialValue"
217
216
} ;
218
217
219
- mount ( < BasicForm formId = { formId } >
220
- < BasicField { ...fieldProps } />
221
- </ BasicForm > ) ;
218
+ mount ( < MyTestForm formId = { formId } >
219
+ < MyTestField { ...fieldProps } />
220
+ </ MyTestForm > ) ;
222
221
const formStore = FSHContainer . FormStoresHandler . GetStore ( formId ) ;
223
222
224
223
expect ( ( formStore . GetField ( fieldName ) . Props as MyFieldProps ) . value ) . toBe ( fieldProps . value ) ;
@@ -238,25 +237,25 @@ describe("Field Base", () => {
238
237
239
238
// Set spies on methods
240
239
spy ( FormStore . prototype , "UpdateProps" ) ;
241
- spy ( BasicField . prototype , "componentWillReceiveProps" ) ;
240
+ spy ( MyTestField . prototype , "componentWillReceiveProps" ) ;
242
241
243
242
// Render form to create FormStore
244
- shallow ( < BasicForm formId = { formId } > </ BasicForm > ) ;
243
+ shallow ( < MyTestForm formId = { formId } > </ MyTestForm > ) ;
245
244
246
245
const formStore = FSHContainer . FormStoresHandler . GetStore ( formId ) ;
247
246
248
247
// Mount with formId as a context
249
- const field = mount < MyFieldProps > ( < BasicField { ...fieldProps } /> , {
248
+ const field = mount < MyFieldProps > ( < MyTestField { ...fieldProps } /> , {
250
249
context : {
251
250
FormId : formId
252
251
} as FormChildContext
253
252
} ) ;
254
253
255
- // Update BasicField props
254
+ // Update MyTestField props
256
255
field . setProps ( fieldPropsNext ) ;
257
256
258
257
expect ( ( FormStore . prototype . UpdateProps as any ) . callCount ) . toEqual ( 1 ) ;
259
- expect ( ( BasicField . prototype . componentWillReceiveProps as any ) . callCount ) . toEqual ( 1 ) ;
258
+ expect ( ( MyTestField . prototype . componentWillReceiveProps as any ) . callCount ) . toEqual ( 1 ) ;
260
259
expect ( ( formStore . GetField ( fieldId ) . Props as MyFieldProps ) . value ) . toBe ( fieldPropsNext . value ) ;
261
260
} ) ;
262
261
} ) ;
0 commit comments