-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathComps.test.js
74 lines (65 loc) · 1.66 KB
/
Comps.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
import React from 'react';
import { Provider } from 'react-redux';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { PaymentFooter } from './Comps';
import { createReduxStore, ACTIONS } from './redux';
const foodData = [
{
id: 'SM',
label: 'Sausage McMuffin',
description: 'Description of McMuffin',
price: 12,
},
{
id: 'MP',
label: 'Mushroom Pizza',
diet: 'veg',
description: 'Description of Pizza',
price: 20,
},
];
describe('Test PaymentFooter', () => {
const cartIds = ['SM', 'SM', 'MP'];
function renderPaymentFooter(store = createReduxStore(), props = {}) {
return render(
<Provider store={store}>
<PaymentFooter {...props} />
</Provider>,
);
}
const addItemsInStore = (store) => {
store.dispatch({
type: ACTIONS.LOAD_MENU,
payload: {
menu: foodData,
},
});
cartIds.forEach((id) => {
store.dispatch({
type: ACTIONS.ADD_TO_CART,
payload: {
itemId: id,
},
});
});
};
const resetMenu = (store) => {
cartIds.forEach((id) => {
store.dispatch({
type: ACTIONS.REMOVE_FROM_CART,
payload: {
itemId: id,
},
});
});
};
test('payment footer shows cart price when items present in cart', () => {
const store = createReduxStore();
addItemsInStore(store);
renderPaymentFooter(store);
expect(screen.getByRole('link', {name: /Pay for food/i})).toHaveTextContent('Pay for food ($44)');
resetMenu(store);
expect(screen.queryByRole('link', {name: /Pay for food/i})).toBe(null);
});
});