|
1 |
| -import { screen, waitFor } from "@testing-library/react" |
2 |
| -import App from "./App" |
3 |
| -import { renderWithProviders } from "./utils/test-utils" |
| 1 | +import { screen, waitFor } from '@testing-library/react' |
| 2 | +import App from './App' |
| 3 | +import { renderWithProviders } from './utils/test-utils' |
4 | 4 |
|
5 |
| -test("App should have correct initial render", () => { |
| 5 | +test('App should have correct initial render', () => { |
6 | 6 | renderWithProviders(<App />)
|
7 | 7 |
|
8 | 8 | // The app should be rendered correctly
|
9 | 9 | expect(screen.getByText(/learn/i)).toBeInTheDocument()
|
10 | 10 |
|
11 | 11 | // Initial state: count should be 0, incrementValue should be 2
|
12 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("0") |
13 |
| - expect(screen.getByLabelText("Set increment amount")).toHaveValue(2) |
| 12 | + expect(screen.getByLabelText('Count')).toHaveTextContent('0') |
| 13 | + expect(screen.getByLabelText('Set increment amount')).toHaveValue(2) |
14 | 14 | })
|
15 | 15 |
|
16 |
| -test("Increment value and Decrement value should work as expected", async () => { |
| 16 | +test('Increment value and Decrement value should work as expected', async () => { |
17 | 17 | const { user } = renderWithProviders(<App />)
|
18 | 18 |
|
19 | 19 | // Click on "+" => Count should be 1
|
20 |
| - await user.click(screen.getByLabelText("Increment value")) |
21 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("1") |
| 20 | + await user.click(screen.getByLabelText('Increment value')) |
| 21 | + expect(screen.getByLabelText('Count')).toHaveTextContent('1') |
22 | 22 |
|
23 | 23 | // Click on "-" => Count should be 0
|
24 |
| - await user.click(screen.getByLabelText("Decrement value")) |
25 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("0") |
| 24 | + await user.click(screen.getByLabelText('Decrement value')) |
| 25 | + expect(screen.getByLabelText('Count')).toHaveTextContent('0') |
26 | 26 | })
|
27 | 27 |
|
28 |
| -test("Add Amount should work as expected", async () => { |
| 28 | +test('Add Amount should work as expected', async () => { |
29 | 29 | const { user } = renderWithProviders(<App />)
|
30 | 30 |
|
31 | 31 | // "Add Amount" button is clicked => Count should be 2
|
32 |
| - await user.click(screen.getByText("Add Amount")) |
33 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("2") |
| 32 | + await user.click(screen.getByText('Add Amount')) |
| 33 | + expect(screen.getByLabelText('Count')).toHaveTextContent('2') |
34 | 34 |
|
35 |
| - const incrementValueInput = screen.getByLabelText("Set increment amount") |
| 35 | + const incrementValueInput = screen.getByLabelText('Set increment amount') |
36 | 36 | // incrementValue is 2, click on "Add Amount" => Count should be 4
|
37 | 37 | await user.clear(incrementValueInput)
|
38 |
| - await user.type(incrementValueInput, "2") |
39 |
| - await user.click(screen.getByText("Add Amount")) |
40 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("4") |
| 38 | + await user.type(incrementValueInput, '2') |
| 39 | + await user.click(screen.getByText('Add Amount')) |
| 40 | + expect(screen.getByLabelText('Count')).toHaveTextContent('4') |
41 | 41 |
|
42 | 42 | // [Negative number] incrementValue is -1, click on "Add Amount" => Count should be 3
|
43 | 43 | await user.clear(incrementValueInput)
|
44 |
| - await user.type(incrementValueInput, "-1") |
45 |
| - await user.click(screen.getByText("Add Amount")) |
46 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("3") |
| 44 | + await user.type(incrementValueInput, '-1') |
| 45 | + await user.click(screen.getByText('Add Amount')) |
| 46 | + expect(screen.getByLabelText('Count')).toHaveTextContent('3') |
47 | 47 | })
|
48 | 48 |
|
49 |
| -it("Add Async should work as expected", async () => { |
| 49 | +it('Add Async should work as expected', async () => { |
50 | 50 | const { user } = renderWithProviders(<App />)
|
51 | 51 |
|
52 | 52 | // "Add Async" button is clicked => Count should be 2
|
53 |
| - await user.click(screen.getByText("Add Async")) |
| 53 | + await user.click(screen.getByText('Add Async')) |
54 | 54 |
|
55 | 55 | await waitFor(() =>
|
56 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("2"), |
| 56 | + expect(screen.getByLabelText('Count')).toHaveTextContent('2'), |
57 | 57 | )
|
58 | 58 |
|
59 |
| - const incrementValueInput = screen.getByLabelText("Set increment amount") |
| 59 | + const incrementValueInput = screen.getByLabelText('Set increment amount') |
60 | 60 | // incrementValue is 2, click on "Add Async" => Count should be 4
|
61 | 61 | await user.clear(incrementValueInput)
|
62 |
| - await user.type(incrementValueInput, "2") |
| 62 | + await user.type(incrementValueInput, '2') |
63 | 63 |
|
64 |
| - await user.click(screen.getByText("Add Async")) |
| 64 | + await user.click(screen.getByText('Add Async')) |
65 | 65 | await waitFor(() =>
|
66 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("4"), |
| 66 | + expect(screen.getByLabelText('Count')).toHaveTextContent('4'), |
67 | 67 | )
|
68 | 68 |
|
69 | 69 | // [Negative number] incrementValue is -1, click on "Add Async" => Count should be 3
|
70 | 70 | await user.clear(incrementValueInput)
|
71 |
| - await user.type(incrementValueInput, "-1") |
72 |
| - await user.click(screen.getByText("Add Async")) |
| 71 | + await user.type(incrementValueInput, '-1') |
| 72 | + await user.click(screen.getByText('Add Async')) |
73 | 73 | await waitFor(() =>
|
74 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("3"), |
| 74 | + expect(screen.getByLabelText('Count')).toHaveTextContent('3'), |
75 | 75 | )
|
76 | 76 | })
|
77 | 77 |
|
78 |
| -test("Add If Odd should work as expected", async () => { |
| 78 | +test('Add If Odd should work as expected', async () => { |
79 | 79 | const { user } = renderWithProviders(<App />)
|
80 | 80 |
|
81 | 81 | // "Add If Odd" button is clicked => Count should stay 0
|
82 |
| - await user.click(screen.getByText("Add If Odd")) |
83 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("0") |
| 82 | + await user.click(screen.getByText('Add If Odd')) |
| 83 | + expect(screen.getByLabelText('Count')).toHaveTextContent('0') |
84 | 84 |
|
85 | 85 | // Click on "+" => Count should be updated to 1
|
86 |
| - await user.click(screen.getByLabelText("Increment value")) |
87 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("1") |
| 86 | + await user.click(screen.getByLabelText('Increment value')) |
| 87 | + expect(screen.getByLabelText('Count')).toHaveTextContent('1') |
88 | 88 |
|
89 | 89 | // "Add If Odd" button is clicked => Count should be updated to 3
|
90 |
| - await user.click(screen.getByText("Add If Odd")) |
91 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("3") |
| 90 | + await user.click(screen.getByText('Add If Odd')) |
| 91 | + expect(screen.getByLabelText('Count')).toHaveTextContent('3') |
92 | 92 |
|
93 |
| - const incrementValueInput = screen.getByLabelText("Set increment amount") |
| 93 | + const incrementValueInput = screen.getByLabelText('Set increment amount') |
94 | 94 | // incrementValue is 1, click on "Add If Odd" => Count should be updated to 4
|
95 | 95 | await user.clear(incrementValueInput)
|
96 |
| - await user.type(incrementValueInput, "1") |
97 |
| - await user.click(screen.getByText("Add If Odd")) |
98 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("4") |
| 96 | + await user.type(incrementValueInput, '1') |
| 97 | + await user.click(screen.getByText('Add If Odd')) |
| 98 | + expect(screen.getByLabelText('Count')).toHaveTextContent('4') |
99 | 99 |
|
100 | 100 | // click on "Add If Odd" => Count should stay 4
|
101 | 101 | await user.clear(incrementValueInput)
|
102 |
| - await user.type(incrementValueInput, "-1") |
103 |
| - await user.click(screen.getByText("Add If Odd")) |
104 |
| - expect(screen.getByLabelText("Count")).toHaveTextContent("4") |
| 102 | + await user.type(incrementValueInput, '-1') |
| 103 | + await user.click(screen.getByText('Add If Odd')) |
| 104 | + expect(screen.getByLabelText('Count')).toHaveTextContent('4') |
105 | 105 | })
|
0 commit comments