|
1 | | -import { Popover } from '@patternfly/react-core'; |
2 | | -import { shallow } from 'enzyme'; |
| 1 | +import { render, screen, waitFor } from '@testing-library/react'; |
3 | 2 | import { getQuickStarts } from '../../data/test-utils'; |
| 3 | +import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context'; |
4 | 4 | import QuickStartTileDescription from '../QuickStartTileDescription'; |
5 | 5 |
|
6 | | -jest.mock('react', () => { |
7 | | - const ActualReact = require.requireActual('react'); |
8 | | - return { |
9 | | - ...ActualReact, |
10 | | - useContext: () => jest.fn(), |
11 | | - }; |
12 | | -}); |
| 6 | +const contextValues = { |
| 7 | + ...QuickStartContextDefaults, |
| 8 | + activeQuickStartID: '', |
| 9 | + startQuickStart: jest.fn(), |
| 10 | + restartQuickStart: jest.fn(), |
| 11 | + getResource: (key: string) => key, |
| 12 | +}; |
13 | 13 |
|
14 | | -xdescribe('QuickStartCatalog', () => { |
15 | | - beforeEach(() => { |
16 | | - spyOn(React, 'useContext').and.returnValue({ |
17 | | - activeQuickStartID: '', |
18 | | - startQuickStart: () => {}, |
19 | | - restartQuickStart: () => {}, |
20 | | - getResource: (key) => `quickstart~${key}`, |
21 | | - }); |
22 | | - }); |
| 14 | +const renderWithContext = (props: any) => |
| 15 | + render( |
| 16 | + <QuickStartContext.Provider value={contextValues}> |
| 17 | + <QuickStartTileDescription {...props} /> |
| 18 | + </QuickStartContext.Provider>, |
| 19 | + ); |
23 | 20 |
|
24 | | - it('should show prerequisites only if provided', () => { |
25 | | - // this quick start does not have prereqs |
| 21 | +describe('QuickStartTileDescription', () => { |
| 22 | + it('should show prerequisites only if provided', async () => { |
26 | 23 | const quickStart = getQuickStarts()[0].spec; |
27 | | - const QuickStartTileDescriptionWrapper = shallow( |
28 | | - <QuickStartTileDescription description={quickStart.description} />, |
29 | | - ); |
30 | | - expect(QuickStartTileDescriptionWrapper.find(Text)).toHaveLength(0); |
| 24 | + renderWithContext({ description: quickStart.description }); |
| 25 | + await waitFor(() => { |
| 26 | + expect( |
| 27 | + screen.queryByRole('button', { name: 'Show prerequisites' }), |
| 28 | + ).not.toBeInTheDocument(); |
| 29 | + }); |
31 | 30 | }); |
32 | 31 |
|
33 | | - it('shoould render prerequisites inside a popover', () => { |
| 32 | + it('should render prerequisites trigger when prerequisite list is non-empty', async () => { |
34 | 33 | const quickStart = getQuickStarts()[2].spec; |
35 | | - const QuickStartTileDescriptionWrapper = shallow( |
36 | | - <QuickStartTileDescription |
37 | | - description={quickStart.description} |
38 | | - prerequisites={quickStart.prerequisites} |
39 | | - />, |
40 | | - ); |
41 | | - expect(QuickStartTileDescriptionWrapper.find(Popover)).toHaveLength(1); |
| 34 | + renderWithContext({ |
| 35 | + description: quickStart.description, |
| 36 | + prerequisites: quickStart.prerequisites, |
| 37 | + }); |
| 38 | + await waitFor(() => { |
| 39 | + expect( |
| 40 | + screen.getByRole('button', { name: 'Show prerequisites' }), |
| 41 | + ).toBeInTheDocument(); |
| 42 | + }); |
42 | 43 | }); |
43 | 44 | }); |
0 commit comments