-
Notifications
You must be signed in to change notification settings - Fork 4
/
quotesList.tsx
58 lines (44 loc) · 1.82 KB
/
quotesList.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
56
57
58
import React from 'react';
import { MemoryRouter } from 'react-router';
import { quotesMock } from '../../../../test-utils/mocks/qoutes.mock';
import { quotePageRoute } from '../../../../router/routerPaths';
import { QuotesList } from '../quotesList';
import { QuoteItem, QuoteText, QuoteAuthor } from '../qutesList.elements';
import { create, ReactTestRenderer, ReactTestInstance } from 'react-test-renderer';
describe('QuotesList - quotes list component', () => {
const [firstQuote] = quotesMock;
let container: ReactTestRenderer;
let instance: ReactTestInstance;
beforeEach(() => {
container = create(<MemoryRouter><QuotesList quotes={quotesMock} /></MemoryRouter>);
instance = container.root;
});
afterEach(() => {
container.unmount();
});
it('Snapshot of component is match', () => {
expect(container.toJSON()).toMatchSnapshot();
});
/**
* TODO: other tests is legacy
* @see https://www.valentinog.com/blog/testing-react/
*/
it('Count of displayed quotes matches the input data', () => {
const quotesList = instance.findAllByType(QuoteItem);
expect(quotesList.length).toBe(quotesMock.length);
});
it('Text of first quote is correct', () => {
const [quoteText] = instance.findAllByType(QuoteText);
const text = quoteText.props.children;
expect(text).toBe(firstQuote.text);
});
it('Author of first quote is correct', () => {
const [quoteAuthor] = instance.findAllByType(QuoteAuthor);
const text = quoteAuthor.props.children;
expect(text).toBe(firstQuote.author);
});
it('First quote item have link to its page', () => {
const [quoteItem] = instance.findAllByType(QuoteItem);
expect(quoteItem.props.to).toBe(quotePageRoute(firstQuote.id));
});
});