-
Notifications
You must be signed in to change notification settings - Fork 4
/
quotesPage.tsx
55 lines (44 loc) · 2.02 KB
/
quotesPage.tsx
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
import { mount, ReactWrapper } from 'enzyme';
import React from 'react';
import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router';
import { initEnzyme } from 'test-utils/initEnzyme';
import { quotesMock } from 'test-utils/mocks/qoutes.mock';
import { UIButton } from 'ui-elements/button';
import { QuoteCreateForm } from 'components/pure/quoteCreateForm/quoteCreateForm';
import { CloseForm } from 'components/pure/quoteCreateForm/qutesCreateForm.elements';
import { QuoteItem } from 'components/pure/quotesList/qutesList.elements';
import { QuotesPage } from '../quotesPage';
import configureStore, { MockStoreEnhanced } from 'redux-mock-store';
import { QuotesPageTitle } from '../quotesPage.elements';
describe('QuotesPage - quotes page component', () => {
const mockStore = configureStore();
const initialState = {quotes: quotesMock};
let wrapper: ReactWrapper;
let store: MockStoreEnhanced;
beforeAll(() => {
initEnzyme();
});
beforeEach(() => {
store = mockStore(initialState);
wrapper = mount(<Provider store={store}><MemoryRouter><QuotesPage/></MemoryRouter></Provider>);
});
it('Title of page contains correct text', () => {
expect(wrapper.find(QuotesPageTitle).text()).toBe('Quotes app');
});
it('Quotes list is displayed and count of displayed quotes matches the input data', () => {
expect(wrapper.find(QuoteItem).length).toBe(quotesMock.length);
});
it('Quote create form is opened by default', () => {
expect(wrapper.find(QuoteCreateForm).length).toBe(1);
});
it('Form is closing when "X" button is clicked', () => {
wrapper.find(CloseForm).first().simulate('click');
expect(wrapper.find(QuoteCreateForm).length).toBe(0);
});
it('Form is opening when "Create quote" button is clicked', () => {
wrapper.find(CloseForm).first().simulate('click');
wrapper.find(UIButton).first().simulate('click');
expect(wrapper.find(QuoteCreateForm).length).toBe(1);
});
});