| Total Complexity | 1 |
| Complexity/F | 1 |
| Lines of Code | 34 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import * as React from 'react'; |
||
| 2 | import { EnvironmentSelect, EnvironmentSelectProps } from '../../src/components/EnvironmentSelect'; |
||
| 3 | import { render, fireEvent, within } from '@testing-library/react'; |
||
| 4 | |||
| 5 | describe('EnvironmentSelect', () => { |
||
| 6 | it('should render', () => { |
||
| 7 | const mockedProps = generateProps(); |
||
| 8 | render(<EnvironmentSelect {...mockedProps} />); |
||
| 9 | }); |
||
| 10 | |||
| 11 | it('should change environment', () => { |
||
| 12 | const mockedProps = generateProps(); |
||
| 13 | const { getByTestId } = render(<EnvironmentSelect {...mockedProps} />); |
||
| 14 | const environmentSelect = getByTestId('environment-select') as HTMLDivElement; |
||
| 15 | expect(environmentSelect.children[0].textContent).toBe(mockedProps.env); |
||
| 16 | |||
| 17 | const selectedEnvironment = mockedProps.options[1]; |
||
| 18 | const selectedOption = within(environmentSelect).getByText(selectedEnvironment); |
||
| 19 | fireEvent.click(selectedOption); |
||
| 20 | |||
| 21 | expect(mockedProps.onEnvironmentChange).toHaveBeenCalledWith(selectedEnvironment); |
||
| 22 | }); |
||
| 23 | }); |
||
| 24 | |||
| 25 | function generateProps(props?: EnvironmentSelectProps): EnvironmentSelectProps { |
||
| 26 | return { |
||
| 27 | env: 'DEMO', |
||
| 28 | disabled: false, |
||
| 29 | onEnvironmentChange: jest.fn(), |
||
| 30 | options: ['DEMO', 'SIT', 'UAT'], |
||
| 31 | ...props, |
||
| 32 | }; |
||
| 33 | } |
||
| 34 |