-
Notifications
You must be signed in to change notification settings - Fork 4
/
quotePage.tsx
52 lines (44 loc) · 1.89 KB
/
quotePage.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
import { ReactWrapper, mount } from 'enzyme';
import React from 'react';
import { Provider } from 'react-redux';
import { MemoryRouter, Route } from 'react-router';
import configureStore, { MockStoreEnhanced } from 'redux-mock-store';
import { quotePageRoute, mainRoute } from '../../../../router/routerPaths';
import { initEnzyme } from 'test-utils/initEnzyme';
import { quotesMock } from 'test-utils/mocks/qoutes.mock';
import { generateState } from '../../../../test-utils/generateState';
import { QuotePage } from '../quotePage';
import { QuoteText, QuoteAuthor, ToMain } from '../quotePage.elements';
describe('QuotePage - quote page component', () => {
const mockStore = configureStore();
const [currentQuote] = quotesMock;
const currentPath = quotePageRoute(currentQuote.id);
const mainPageText = 'main page';
let wrapper: ReactWrapper;
let store: MockStoreEnhanced;
beforeAll(() => {
initEnzyme();
});
beforeEach(() => {
store = mockStore(generateState(currentPath));
wrapper = mount(
<Provider store={store}>
<MemoryRouter initialEntries={[currentPath]}
initialIndex={0}>
<Route exact path={mainRoute} render={() => mainPageText}/>
<Route exact path={quotePageRoute()} component={QuotePage}/>
</MemoryRouter>
</Provider>
);
});
it('Displayed text of quote is correct', () => {
expect(wrapper.find(QuoteText).first().text()).toBe(currentQuote.text);
});
it('Displayed author of quote is correct', () => {
expect(wrapper.find(QuoteAuthor).first().text()).toBe(currentQuote.author);
});
it('Page should be changed to main on click to "To quotes list"', () => {
wrapper.find(ToMain).first().simulate('click', {button: 0});
expect(wrapper.text()).toBe(mainPageText);
});
});