|
1 | | -import React from 'react'; |
2 | | -import { |
3 | | - act, fireEvent, render, waitFor, |
4 | | -} from '@testing-library/react'; |
| 1 | +import { fireEvent, render } from '@testing-library/react'; |
5 | 2 | import { IntlProvider } from '@edx/frontend-platform/i18n'; |
6 | 3 |
|
7 | 4 | import { courseDetailsMock } from '../__mocks__'; |
@@ -29,38 +26,43 @@ describe('<LearningOutcomesSection />', () => { |
29 | 26 | }); |
30 | 27 |
|
31 | 28 | it('should create another learning outcome form on click Add learning outcome', async () => { |
32 | | - const { getAllByRole, getByRole } = render(<RootWrapper {...props} />); |
| 29 | + const { getByRole } = render(<RootWrapper {...props} />); |
33 | 30 | const addButton = getByRole('button', { name: messages.outcomesAdd.defaultMessage }); |
34 | | - act(() => { |
35 | | - fireEvent.click(addButton); |
36 | | - }); |
| 31 | + expect(onChangeMock).not.toHaveBeenCalled(); |
| 32 | + fireEvent.click(addButton); |
| 33 | + expect(onChangeMock).toHaveBeenCalledWith([ |
| 34 | + props.learningInfo[0], |
| 35 | + '', // <-- new |
| 36 | + ], 'learningInfo'); |
37 | 37 |
|
38 | | - await waitFor(() => { |
39 | | - const deleteButtons = getAllByRole('button', { name: messages.outcomesDelete.defaultMessage }); |
40 | | - expect(deleteButtons.length).toBe(2); |
41 | | - }); |
| 38 | + // FIXME: the following doesn't happen, because this is a controlled component and only changes |
| 39 | + // when the props change (in response to 'onChange'). This needs to be tested at a higher level, |
| 40 | + // e.g. testing the whole page together, not just this component. |
| 41 | + // await waitFor(() => { |
| 42 | + // const deleteButtons = getAllByRole('button', { name: messages.outcomesDelete.defaultMessage }); |
| 43 | + // expect(deleteButtons.length).toBe(2); |
| 44 | + // }); |
42 | 45 | }); |
43 | 46 |
|
44 | 47 | it('should delete learning outcome form on click Delete', async () => { |
45 | | - const { getAllByRole, getByRole } = render(<RootWrapper {...props} />); |
| 48 | + const { getByRole } = render(<RootWrapper {...props} />); |
46 | 49 | const deleteButton = getByRole('button', { name: messages.outcomesDelete.defaultMessage }); |
47 | | - act(() => { |
48 | | - fireEvent.click(deleteButton); |
49 | | - }); |
| 50 | + fireEvent.click(deleteButton); |
50 | 51 |
|
51 | 52 | expect(onChangeMock).toHaveBeenCalledWith([], 'learningInfo'); |
52 | | - await waitFor(() => { |
53 | | - const deleteButtons = getAllByRole('button', { name: messages.outcomesDelete.defaultMessage }); |
54 | | - expect(deleteButtons.length).toBe(0); |
55 | | - }); |
| 53 | + // FIXME: the following doesn't happen, because this is a controlled component and only changes |
| 54 | + // when the props change (in response to 'onChange'). This needs to be tested at a higher level, |
| 55 | + // e.g. testing the whole page together, not just this component. |
| 56 | + // await waitFor(() => { |
| 57 | + // const deleteButtons = getAllByRole('button', { name: messages.outcomesDelete.defaultMessage }); |
| 58 | + // expect(deleteButtons.length).toBe(0); |
| 59 | + // }); |
56 | 60 | }); |
57 | 61 |
|
58 | 62 | it('should call onChange if input value changed', () => { |
59 | 63 | const { getByPlaceholderText } = render(<RootWrapper {...props} />); |
60 | 64 | const input = getByPlaceholderText(messages.outcomesInputPlaceholder.defaultMessage); |
61 | | - act(() => { |
62 | | - fireEvent.change(input, { target: { value: 'abc' } }); |
63 | | - }); |
| 65 | + fireEvent.change(input, { target: { value: 'abc' } }); |
64 | 66 |
|
65 | 67 | expect(onChangeMock).toHaveBeenCalledWith(['abc'], 'learningInfo'); |
66 | 68 | }); |
|
0 commit comments