|
1 | | -import { cleanup, configure, render, screen } from '@testing-library/react'; |
2 | | -import { useK8sWatchResource } from '@console/internal/components/utils/k8s-watch-hook'; |
3 | | -import { FinishTourText } from '../GuidedTourText'; |
| 1 | +import { configure, render, screen } from '@testing-library/react'; |
| 2 | +import { helpTourText, userPreferencesTourText, FinishTourText } from '../GuidedTourText'; |
| 3 | +import '@testing-library/jest-dom'; |
4 | 4 |
|
5 | | -configure({ testIdAttribute: 'data-test' }); |
6 | | - |
7 | | -jest.mock('@console/internal/components/utils/k8s-watch-hook', () => { |
8 | | - return { |
9 | | - useK8sWatchResource: jest.fn(), |
10 | | - }; |
11 | | -}); |
| 5 | +// Mock k8s-watch-hook |
| 6 | +jest.mock('@console/internal/components/utils/k8s-watch-hook', () => ({ |
| 7 | + useK8sWatchResource: () => [ |
| 8 | + [{ metadata: { name: 'openshift-blog' }, spec: { href: 'https://blog.example.com' } }], |
| 9 | + ], |
| 10 | +})); |
12 | 11 |
|
13 | 12 | describe('GuidedTourText', () => { |
14 | | - afterEach(() => cleanup()); |
15 | | - |
16 | | - it('should render openshift-blog and openshift-docs link', () => { |
17 | | - (useK8sWatchResource as jest.Mock).mockReturnValueOnce([[], true, '']); |
18 | | - render(<FinishTourText />); |
19 | | - |
20 | | - screen.getByTestId('openshift-blog-link'); |
21 | | - screen.getByTestId('openshift-docs-link'); |
| 13 | + beforeAll(() => { |
| 14 | + configure({ testIdAttribute: 'data-test' }); |
22 | 15 | }); |
23 | 16 |
|
24 | | - it('should render the openshift-blog href with link from consoleLinks', () => { |
25 | | - (useK8sWatchResource as jest.Mock).mockReturnValueOnce([ |
26 | | - [{ metadata: { name: 'openshift-blog' }, spec: { href: 'https://blog.openshift.com/' } }], |
27 | | - true, |
28 | | - '', |
29 | | - ]); |
30 | | - const { getByTestId } = render(<FinishTourText />); |
31 | | - expect(getByTestId('openshift-blog-link').getAttribute('href')).toEqual( |
32 | | - 'https://blog.openshift.com/', |
33 | | - ); |
| 17 | + it('renders helpTourText', () => { |
| 18 | + render(helpTourText); |
| 19 | + expect( |
| 20 | + screen.getByText( |
| 21 | + 'Access our new quick starts where you can learn more about creating or deploying an application using OpenShift Developer Console. You can also restart this tour anytime here.', |
| 22 | + ), |
| 23 | + ).toBeInTheDocument(); |
34 | 24 | }); |
35 | 25 |
|
36 | | - it('should render the openshift-blog href with default link if consoleLinks are not available', () => { |
37 | | - (useK8sWatchResource as jest.Mock).mockReturnValueOnce([[], true, '']); |
38 | | - const { getByTestId } = render(<FinishTourText />); |
39 | | - expect(getByTestId('openshift-blog-link').getAttribute('href')).toEqual( |
40 | | - 'https://developers.redhat.com/products/openshift/whats-new', |
41 | | - ); |
| 26 | + it('renders userPreferencesTourText', () => { |
| 27 | + render(userPreferencesTourText); |
| 28 | + expect( |
| 29 | + screen.getByText( |
| 30 | + 'Set your individual console preferences including default views, language, import settings, and more.', |
| 31 | + ), |
| 32 | + ).toBeInTheDocument(); |
42 | 33 | }); |
43 | 34 |
|
44 | | - it('should render openshift-docs href with default link', () => { |
45 | | - (useK8sWatchResource as jest.Mock).mockReturnValueOnce([[], true, '']); |
46 | | - const { getByTestId } = render(<FinishTourText />); |
47 | | - expect(getByTestId('openshift-docs-link').getAttribute('href')).toEqual( |
| 35 | + it('renders FinishTourText with blog and documentation links', () => { |
| 36 | + render(<FinishTourText />); |
| 37 | + expect(screen.getByTestId('openshift-blog-link')).toHaveAttribute( |
| 38 | + 'href', |
| 39 | + 'https://blog.example.com', |
| 40 | + ); |
| 41 | + expect(screen.getByTestId('openshift-help-link')).toHaveAttribute( |
| 42 | + 'href', |
48 | 43 | 'https://docs.okd.io/latest/', |
49 | 44 | ); |
| 45 | + expect(screen.getByText('blog')).toBeInTheDocument(); |
| 46 | + expect(screen.getByText('documentation')).toBeInTheDocument(); |
50 | 47 | }); |
51 | 48 | }); |
0 commit comments