/
App.test.js
88 lines (68 loc) · 2.41 KB
/
App.test.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from 'react';
import { mount, shallow } from 'enzyme';
import { MemoryRouter } from 'react-router';
import App from './App';
import Crawler from '../Crawler/Crawler';
import Cards from '../Cards/Cards';
describe('App', () => {
let wrapper;
beforeEach(() => {
wrapper = shallow(<App />)
});
it('should render without crashing', () => {
expect(wrapper.length).toEqual(1)
});
it('should update state to show favorited cards when favoriteCard is invoked', () => {
const mockPerson = { name: 'David', homeworld: 'Kamino', species: 'wookie', population: 20};
const expected = [{ name: 'David', homeworld: 'Kamino', species: 'wookie', population: 20}];
wrapper.setState({ people: [mockPerson] });
wrapper.instance().favoriteCard(mockPerson);
expect(wrapper.state('people')).toEqual(expected);
expect(wrapper.state('favorites')).toEqual(expected);
});
it('should match the snapshot with all data passed in correctly', () => {
expect(wrapper).toMatchSnapshot();
});
describe('Route', () => {
it('should route to the homepage with the Crawler displayed by default', () => {
const wrapper = mount(
<MemoryRouter initialEntries={['/']}>
<App />
</MemoryRouter>
);
expect(wrapper.find(Crawler)).toHaveLength(1);
});
it('should route to the people page when the people link is clicked', () => {
const wrapper = mount(
<MemoryRouter initialEntries={['/people']}>
<App />
</MemoryRouter>
);
expect(wrapper.find(Cards)).toHaveLength(1);
});
it('should route to the planets page when the planets link is clicked', () => {
const wrapper = mount(
<MemoryRouter initialEntries={['/planets']}>
<App />
</MemoryRouter>
);
expect(wrapper.find(Cards)).toHaveLength(1);
});
it('should route to the vehicles page when the vehicles link is clicked', () => {
const wrapper = mount(
<MemoryRouter initialEntries={['/vehicles']}>
<App />
</MemoryRouter>
);
expect(wrapper.find(Cards)).toHaveLength(1);
});
it('should route to the favorites page when the favorites link is clicked', () => {
const wrapper = mount(
<MemoryRouter initialEntries={['/favorites']}>
<App />
</MemoryRouter>
);
expect(wrapper.find(Cards)).toHaveLength(1);
});
});
});