Skip to content

Commit eea5999

Browse files
author
Martynas Žilinskas
authored
Feature/dom-tests (#27)
* Added dependencies for jest. * Added form component tests.
1 parent ef71375 commit eea5999

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
});

packages/simplr-forms-dom/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
"mv": "^2.1.1",
4848
"mz": "^2.6.0",
4949
"on-build-webpack": "^0.1.0",
50+
"react-dom": "^15.5.4",
51+
"react-test-renderer": "^15.5.4",
5052
"simplr-mvdir": "0.0.1-beta.6",
5153
"sinon": "^2.1.0",
5254
"ts-jest": "^19.0.8",

0 commit comments

Comments
 (0)