|
| 1 | +import React from 'react'; |
| 2 | +import { screen, render, waitFor } from '@testing-library/react'; |
| 3 | +import userEvent from '@testing-library/user-event'; |
| 4 | +import ConfigEditor from './ConfigEditor'; |
| 5 | + |
| 6 | +describe('Config Editor', () => { |
| 7 | + it('should select basic license type as checked by default', async () => { |
| 8 | + const onOptionsChange = jest.fn(); |
| 9 | + const options = { jsonData: {}, secureJsonFields: {} } as any; |
| 10 | + render(<ConfigEditor options={options} onOptionsChange={onOptionsChange} />); |
| 11 | + await waitFor(() => expect(screen.getByText('Additional Settings')).toBeInTheDocument()); |
| 12 | + expect(screen.getByLabelText('Basic')).toBeChecked(); |
| 13 | + expect(screen.getByLabelText('Enterprise')).not.toBeChecked(); |
| 14 | + expect(screen.queryByText('GitHub Enterprise URL')).not.toBeInTheDocument(); |
| 15 | + expect(onOptionsChange).toHaveBeenCalledTimes(0); |
| 16 | + await userEvent.click(screen.getByLabelText('Enterprise')); |
| 17 | + expect(onOptionsChange).toHaveBeenCalledTimes(0); |
| 18 | + expect(screen.queryByText('GitHub Enterprise URL')).toBeInTheDocument(); |
| 19 | + }); |
| 20 | + it('should select enterprise license type as checked when the url is not empty', async () => { |
| 21 | + const onOptionsChange = jest.fn(); |
| 22 | + const options = { jsonData: { githubUrl: 'https://foo.bar' }, secureJsonFields: {} } as any; |
| 23 | + render(<ConfigEditor options={options} onOptionsChange={onOptionsChange} />); |
| 24 | + await waitFor(() => expect(screen.getByText('Additional Settings')).toBeInTheDocument()); |
| 25 | + expect(screen.getByLabelText('Basic')).not.toBeChecked(); |
| 26 | + expect(screen.getByLabelText('Enterprise')).toBeChecked(); |
| 27 | + expect(screen.queryByText('GitHub Enterprise URL')).toBeInTheDocument(); |
| 28 | + expect(onOptionsChange).toHaveBeenCalledTimes(0); |
| 29 | + await userEvent.click(screen.getByLabelText('Basic')); |
| 30 | + expect(onOptionsChange).toHaveBeenNthCalledWith(1, { jsonData: { githubUrl: '' }, secureJsonFields: {} }); |
| 31 | + expect(screen.queryByText('GitHub Enterprise URL')).not.toBeInTheDocument(); |
| 32 | + }); |
| 33 | +}); |
0 commit comments