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
|
import { mount } from 'enzyme';
import wait from 'waait';
import toJSON from 'enzyme-to-json';
import Nav from '../components/Nav';
import { CURRENT_USER_QUERY } from '../components/User';
import { MockedProvider } from 'react-apollo/test-utils';
import { fakeUser, fakeCartItem } from '../lib/testUtils';
const notSignedInMocks = [
{
request: { query: CURRENT_USER_QUERY },
result: { data: { me: null } },
},
];
const signedInMocks = [
{
request: { query: CURRENT_USER_QUERY },
result: { data: { me: fakeUser() } },
},
];
const signedInMocksWithCartItems = [
{
request: { query: CURRENT_USER_QUERY },
result: {
data: {
me: {
...fakeUser(),
cart: [fakeCartItem(), fakeCartItem(), fakeCartItem()],
},
},
},
},
];
describe('<Nav/>', () => {
it('renders a minimal nav when signed out', async () => {
const wrapper = mount(
<MockedProvider mocks={notSignedInMocks}>
<Nav />
</MockedProvider>
);
await wait();
wrapper.update();
// console.log(wrapper.debug());
const nav = wrapper.find('ul[data-test="nav"]');
expect(toJSON(nav)).toMatchSnapshot();
});
it('renders full nav when signed in', async () => {
const wrapper = mount(
<MockedProvider mocks={signedInMocks}>
<Nav />
</MockedProvider>
);
await wait();
wrapper.update();
const nav = wrapper.find('ul[data-test="nav"]');
expect(nav.children().length).toBe(6);
expect(nav.text()).toContain('Sign Out');
});
it('renders the amount of items in the cart', async () => {
const wrapper = mount(
<MockedProvider mocks={signedInMocksWithCartItems}>
<Nav />
</MockedProvider>
);
await wait();
wrapper.update();
const nav = wrapper.find('[data-test="nav"]');
const count = nav.find('div.count');
expect(toJSON(count)).toMatchSnapshot();
});
});
|