forked from zoltantothcom/Design-Patterns-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonContainer.test.js
More file actions
73 lines (64 loc) · 1.86 KB
/
ButtonContainer.test.js
File metadata and controls
73 lines (64 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React from 'react';
import renderer from 'react-test-renderer';
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
import { mount } from 'enzyme';
import 'jest-styled-components';
import ButtonContainer, {
ButtonContainer as NotConnectedButtonContainer
} from '../../src/components/ButtonContainer';
import { answers } from '../../src/store';
import { SUBMIT } from '../../src/static/constants/actions';
describe('<ButtonContainer /> connected', () => {
const mockStore = configureMockStore();
const store = mockStore({
patterns: answers,
progress: {
current: answers[0]
}
});
it('renders without crashing and responds to button click', () => {
const container = mount(
<div key="unique">
<Provider store={store}>
<ButtonContainer />
</Provider>
</div>
);
expect(container).toBeTruthy();
container
.find('button')
.first()
.simulate('click');
const actions = store.getActions();
expect(actions).toMatchObject([{ type: SUBMIT }]);
});
});
describe('<ButtonContainer /> component', () => {
const mockClick = jest.fn();
const buttonContainerEl = (
<NotConnectedButtonContainer
patterns={answers}
current={answers[0]}
onSubmitAnswer={mockClick}
/>
);
let buttonContainer;
beforeEach(() => {
buttonContainer = mount(buttonContainerEl);
});
it('has styled-component rendered classes', () => {
const tree = renderer.create(buttonContainerEl).toJSON();
expect(tree.props.className).toBeDefined();
});
it('generates 4 buttons', () => {
expect(buttonContainer.find('button')).toHaveLength(4);
});
it('responds to button click', () => {
buttonContainer
.find('button')
.first()
.simulate('click');
expect(mockClick.mock.calls.length).toEqual(1);
});
});