|
1 | 1 | import React from 'react'; |
2 | | -import { screen } from '@testing-library/react'; |
| 2 | +import { screen, waitFor } from '@testing-library/react'; |
| 3 | +import userEvent from '@testing-library/user-event'; |
3 | 4 |
|
4 | 5 | import render from '../../__mocks__/render'; |
5 | 6 |
|
6 | 7 | import * as SubAzure from '../../../../components/addSourceWizard/hardcodedComponents/azure/subscriptionWatch'; |
| 8 | +import * as api from '../../../../api/entities'; |
| 9 | +import * as useFormApi from '@data-driven-forms/react-form-renderer/use-form-api/use-form-api'; |
7 | 10 |
|
8 | 11 | describe('Azure-Subwatch hardcoded schemas', () => { |
9 | | - it('OfflineToken is rendered correctly', () => { |
10 | | - render(<SubAzure.OfflineToken />); |
| 12 | + describe('LightHouseDescription', () => { |
| 13 | + it('is rendered correctly', async () => { |
| 14 | + const getLighthouseLink = mockApi(); |
11 | 15 |
|
12 | | - expect(screen.getByText('Generate a token to authenticate the calls to APIs for Red Hat services.')).toBeInTheDocument(); |
13 | | - expect(screen.getByText('To obtain an offline token, follow the steps at', { exact: false })).toBeInTheDocument(); |
14 | | - expect(screen.getByText('https://access.redhat.com/management/api', { selector: 'a' })).toBeInTheDocument(); |
| 16 | + api.getSourcesApi = () => ({ |
| 17 | + getLighthouseLink, |
| 18 | + }); |
| 19 | + |
| 20 | + render(<SubAzure.LightHouseDescription />); |
| 21 | + |
| 22 | + expect( |
| 23 | + screen.getByText( |
| 24 | + "Complete configuration steps in Azure Lighthouse according to Microsoft instructions. When you're finished, return to this wizard to finish creating this Azure source." |
| 25 | + ) |
| 26 | + ).toBeInTheDocument(); |
| 27 | + expect(screen.getByText('Take me to Lighthouse')).toHaveAttribute('aria-disabled', 'true'); |
| 28 | + |
| 29 | + getLighthouseLink.resolve({ data: [{ payload: 'href123' }] }); |
| 30 | + |
| 31 | + await waitFor(() => expect(screen.getByText('Take me to Lighthouse')).not.toHaveAttribute('aria-disabled', 'true')); |
| 32 | + expect(screen.getByText('Take me to Lighthouse')).toHaveAttribute('href', 'href123'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('is rendered with error', async () => { |
| 36 | + const _cons = console.error; |
| 37 | + console.error = jest.fn(); |
| 38 | + |
| 39 | + const getLighthouseLink = mockApi(); |
| 40 | + |
| 41 | + api.getSourcesApi = () => ({ |
| 42 | + getLighthouseLink, |
| 43 | + }); |
| 44 | + |
| 45 | + render(<SubAzure.LightHouseDescription />); |
| 46 | + |
| 47 | + getLighthouseLink.reject(); |
| 48 | + |
| 49 | + await waitFor(() => expect(screen.getByText('Take me to Lighthouse')).toHaveAttribute('aria-disabled', 'true')); |
| 50 | + expect( |
| 51 | + screen.getByText('There is an error with loading of the configuration. Please go back and return to this step.') |
| 52 | + ).toBeInTheDocument(); |
| 53 | + |
| 54 | + console.error = _cons; |
| 55 | + }); |
| 56 | + |
| 57 | + it('button changes the value', async () => { |
| 58 | + const change = jest.fn(); |
| 59 | + |
| 60 | + const mock = jest.spyOn(useFormApi, 'default').mockImplementation(() => ({ change })); |
| 61 | + |
| 62 | + api.getSourcesApi = () => ({ |
| 63 | + getLighthouseLink: jest.fn().mockResolvedValue({ data: [{ payload: 'href123' }] }), |
| 64 | + }); |
| 65 | + |
| 66 | + render(<SubAzure.LightHouseDescription />); |
| 67 | + |
| 68 | + const user = userEvent.setup(); |
| 69 | + |
| 70 | + await user.click(screen.getByText('Take me to Lighthouse')); |
| 71 | + |
| 72 | + expect(change).toHaveBeenCalledWith('lighthouse-clicked', true); |
| 73 | + |
| 74 | + mock.mockRestore(); |
| 75 | + }); |
15 | 76 | }); |
16 | 77 |
|
17 | | - it('AnsiblePlaybook is rendered correctly', () => { |
18 | | - render(<SubAzure.AnsiblePlaybook />); |
| 78 | + it('SubscriptionID is rendered correctly', () => { |
| 79 | + render(<SubAzure.SubscriptionID />); |
19 | 80 |
|
20 | | - expect(screen.getByText('Download and run the following commands against a running Azure VM.')).toBeInTheDocument(); |
21 | | - expect(screen.getAllByLabelText('Copyable input')[0]).toHaveValue( |
22 | | - 'ansible-galaxy collection install redhatinsights.subscriptions' |
23 | | - ); |
24 | | - expect(screen.getAllByLabelText('Copyable input')[1]).toHaveValue( |
25 | | - 'ansible-playbook -i <AZURE_VM_HOSTNAME>, -b ~/.ansible/collections/ansible_collections/redhatinsights/subscriptions/playbooks/verify_account.yml -e rh_api_refresh_token=<OFFLINE_AUTH_TOKEN>' |
26 | | - ); |
| 81 | + expect( |
| 82 | + screen.getByText( |
| 83 | + 'Log in to your Azure account and navigate to your subscriptions. Copy the subscription ID you wish to use and paste it into the field below.' |
| 84 | + ) |
| 85 | + ).toBeInTheDocument(); |
27 | 86 | }); |
28 | 87 | }); |
0 commit comments