File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
packages/simplr-forms-dom Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ import * as React from "react" ;
2
+ import { mount } from "enzyme" ;
3
+ import * as sinon from "sinon" ;
4
+
5
+ import { FormStore , FSHContainer , FormStoresHandler } from "simplr-forms-core/stores" ;
6
+
7
+ import { Form } from "../../src/components/form" ;
8
+ import { Text } from "../../src/components/text" ;
9
+ import { FormOnSubmitCallback } from "../../src/contracts/form" ;
10
+
11
+ describe ( "Form" , ( ) => {
12
+ beforeEach ( ( ) => {
13
+ FSHContainer . SetFormStoresHandler ( new FormStoresHandler ( ) , true ) ;
14
+ } ) ;
15
+
16
+ it ( "calls submit callback when submit button is clicked" , ( ) => {
17
+ const submitCallback = sinon . stub ( ) ;
18
+
19
+ const wrapper = mount ( < Form onSubmit = { submitCallback } >
20
+ < button type = "submit" > Submit</ button >
21
+ </ Form > ) ;
22
+
23
+ wrapper . find ( "button" ) . simulate ( "submit" ) ;
24
+
25
+ expect ( submitCallback . called ) . toBe ( true ) ;
26
+ } ) ;
27
+
28
+ it ( "calls submit callback when submit called from FormStore" , ( ) => {
29
+ const formId = "form-id" ;
30
+ const submitCallback = sinon . stub ( ) ;
31
+
32
+ const wrapper = mount ( < Form formId = { formId } onSubmit = { submitCallback } > </ Form > ) ;
33
+
34
+ const formStore = FSHContainer . FormStoresHandler . GetStore ( formId ) ;
35
+ formStore . InitiateSubmit ( ) ;
36
+
37
+ expect ( submitCallback . called ) . toBe ( true ) ;
38
+ } ) ;
39
+ } ) ;
Original file line number Diff line number Diff line change 47
47
"mv" : " ^2.1.1" ,
48
48
"mz" : " ^2.6.0" ,
49
49
"on-build-webpack" : " ^0.1.0" ,
50
+ "react-dom" : " ^15.5.4" ,
51
+ "react-test-renderer" : " ^15.5.4" ,
50
52
"simplr-mvdir" : " 0.0.1-beta.6" ,
51
53
"sinon" : " ^2.1.0" ,
52
54
"ts-jest" : " ^19.0.8" ,
You can’t perform that action at this time.
0 commit comments