|
1 | | -import { IntlProvider } from '@edx/frontend-platform/i18n'; |
2 | | -import { render, screen } from '@testing-library/react'; |
| 1 | +import { |
| 2 | + render, screen, fireEvent, waitFor, initializeMocks, |
| 3 | +} from '@src/testUtils'; |
3 | 4 | import { UpstreamInfoIcon, UpstreamInfoIconProps } from '.'; |
4 | 5 |
|
5 | 6 | type UpstreamInfo = UpstreamInfoIconProps['upstreamInfo']; |
| 7 | +const mockOpenSyncModal = jest.fn(); |
6 | 8 |
|
7 | 9 | const renderComponent = (upstreamInfo?: UpstreamInfo) => ( |
8 | 10 | render( |
9 | | - <IntlProvider locale="en"> |
10 | | - <UpstreamInfoIcon upstreamInfo={upstreamInfo} /> |
11 | | - </IntlProvider>, |
| 11 | + <UpstreamInfoIcon upstreamInfo={upstreamInfo} openSyncModal={mockOpenSyncModal} />, |
12 | 12 | ) |
13 | 13 | ); |
14 | 14 |
|
15 | 15 | describe('<UpstreamInfoIcon>', () => { |
| 16 | + beforeEach(() => { |
| 17 | + initializeMocks(); |
| 18 | + }); |
| 19 | + |
16 | 20 | it('should render with link', () => { |
17 | | - renderComponent({ upstreamRef: 'some-ref', errorMessage: null }); |
| 21 | + renderComponent({ |
| 22 | + upstreamRef: 'some-ref', |
| 23 | + errorMessage: null, |
| 24 | + readyToSync: false, |
| 25 | + }); |
18 | 26 | expect(screen.getByTitle('This item is linked to a library item.')).toBeInTheDocument(); |
19 | | - expect(screen.queryByTitle('The link to the library item is broken.')).not.toBeInTheDocument(); |
| 27 | + expect(screen.queryByTitle('The referenced library or library object is not available.')).not.toBeInTheDocument(); |
20 | 28 | }); |
21 | 29 |
|
22 | 30 | it('should render with broken link', () => { |
23 | | - renderComponent({ upstreamRef: 'some-ref', errorMessage: 'upstream error' }); |
| 31 | + renderComponent({ |
| 32 | + upstreamRef: 'some-ref', |
| 33 | + errorMessage: 'upstream error', |
| 34 | + readyToSync: false, |
| 35 | + }); |
24 | 36 | expect(screen.getByTitle('This item is linked to a library item.')).toBeInTheDocument(); |
25 | | - expect(screen.getByTitle('The link to the library item is broken.')).toBeInTheDocument(); |
| 37 | + expect(screen.getByTitle('The referenced library or library object is not available.')).toBeInTheDocument(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should render with ready to sync link and opens the sync modal', async () => { |
| 41 | + renderComponent({ |
| 42 | + upstreamRef: 'some-ref', |
| 43 | + errorMessage: null, |
| 44 | + readyToSync: true, |
| 45 | + }); |
| 46 | + |
| 47 | + const icon = screen.getByTitle('This item is linked to a library item.'); |
| 48 | + expect(icon).toBeInTheDocument(); |
| 49 | + expect(screen.getByTitle('The linked library or library object has updates available.')).toBeInTheDocument(); |
| 50 | + |
| 51 | + fireEvent.click(icon); |
| 52 | + await waitFor(() => expect(mockOpenSyncModal).toHaveBeenCalled()); |
26 | 53 | }); |
27 | 54 |
|
28 | 55 | it('should render null without upstream', () => { |
29 | | - const { container } = renderComponent(undefined); |
| 56 | + renderComponent(undefined); |
| 57 | + const container = screen.getByTestId('redux-provider'); |
30 | 58 | expect(container).toBeEmptyDOMElement(); |
31 | 59 | }); |
32 | 60 |
|
33 | 61 | it('should render null without upstreamRf', () => { |
34 | | - const { container } = renderComponent({ upstreamRef: null, errorMessage: null }); |
| 62 | + renderComponent({ upstreamRef: null, errorMessage: null }); |
| 63 | + const container = screen.getByTestId('redux-provider'); |
35 | 64 | expect(container).toBeEmptyDOMElement(); |
36 | 65 | }); |
37 | 66 | }); |
0 commit comments