-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtotalUpdates.test.jsx
More file actions
127 lines (106 loc) · 4.29 KB
/
totalUpdates.test.jsx
File metadata and controls
127 lines (106 loc) · 4.29 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { render, screen } from '../../../test-utils/testing-library-utils';
import userEvent from '@testing-library/user-event';
import Options from '../Options';
import OrderEntry from '../OrderEntry';
test('update scoop subtotal when scoops change', async () => {
render(<Options optionType="scoops" />);
// make sure total starts out $0.00
const scoopsSubtotal = screen.getByText('Scoops total: $', { exact: false });
expect(scoopsSubtotal).toHaveTextContent('0.00');
// update vanilla scoops to 1 and check the subtotal
const vanillaInput = await screen.findByRole('spinbutton', {
name: 'Vanilla',
});
userEvent.clear(vanillaInput);
userEvent.type(vanillaInput, '1');
expect(scoopsSubtotal).toHaveTextContent('2.00');
// update chocolate scoops to 2 and check subtotal
const chocolateInput = await screen.findByRole('spinbutton', {
name: 'Chocolate',
});
userEvent.clear(chocolateInput);
userEvent.type(chocolateInput, '2');
expect(scoopsSubtotal).toHaveTextContent('6.00');
});
test('update toppings subtotal when toppings change', async () => {
// render parent component
render(<Options optionType="toppings" />);
// make sure total starts out at $0.00
const toppingsTotal = screen.getByText('Toppings total: $', { exact: false });
expect(toppingsTotal).toHaveTextContent('0.00');
// add cherries and check subtotal
const cherriesCheckbox = await screen.findByRole('checkbox', {
name: 'Cherries',
});
userEvent.click(cherriesCheckbox);
expect(toppingsTotal).toHaveTextContent('1.50');
// add hot fudge and check subtotal
const hotFudgeCheckbox = screen.getByRole('checkbox', { name: 'Hot fudge' });
userEvent.click(hotFudgeCheckbox);
expect(toppingsTotal).toHaveTextContent('3.00');
// remove hot fudge and check subtotal
userEvent.click(hotFudgeCheckbox);
expect(toppingsTotal).toHaveTextContent('1.50');
});
describe('grand total', () => {
test('grand total updates properly if scoop is added first', async () => {
// Test that the total starts out at $0.00
render(<OrderEntry />);
const grandTotal = screen.getByRole('heading', { name: /Grand total: \$/ });
expect(grandTotal).toHaveTextContent('0.00');
// update vanilla scoops to 2 and check grand total
const vanillaInput = await screen.findByRole('spinbutton', {
name: 'Vanilla',
});
userEvent.clear(vanillaInput);
userEvent.type(vanillaInput, '2');
expect(grandTotal).toHaveTextContent('4.00');
// add cherries and check grand total
const cherriesCheckbox = await screen.findByRole('checkbox', {
name: 'Cherries',
});
userEvent.click(cherriesCheckbox);
expect(grandTotal).toHaveTextContent('5.50');
});
test('grand total updates properly if topping is added first', async () => {
render(<OrderEntry />);
// add cherries and check grand total
const cherriesCheckbox = await screen.findByRole('checkbox', {
name: 'Cherries',
});
userEvent.click(cherriesCheckbox);
const grandTotal = screen.getByRole('heading', { name: /Grand total: \$/ });
expect(grandTotal).toHaveTextContent('1.50');
// update vanilla scoops to 2 and check grand total
const vanillaInput = await screen.findByRole('spinbutton', {
name: 'Vanilla',
});
userEvent.clear(vanillaInput);
userEvent.type(vanillaInput, '2');
expect(grandTotal).toHaveTextContent('5.50');
});
test('grand total updates properly if item is removed', async () => {
render(<OrderEntry />);
// add cherries
const cherriesCheckbox = await screen.findByRole('checkbox', {
name: 'Cherries',
});
userEvent.click(cherriesCheckbox);
// grand total $1.50
// update vanilla scoops to 2; grand total should be $5.50
const vanillaInput = await screen.findByRole('spinbutton', {
name: 'Vanilla',
});
userEvent.clear(vanillaInput);
userEvent.type(vanillaInput, '2');
// remove 1 scoop of vanilla and check grand total
userEvent.clear(vanillaInput);
userEvent.type(vanillaInput, '1');
// check grand total
const grandTotal = screen.getByRole('heading', { name: /Grand total: \$/ });
expect(grandTotal).toHaveTextContent('3.50');
// remove cherries and check grand total
userEvent.click(cherriesCheckbox);
expect(grandTotal).toHaveTextContent('2.00');
});
});