Passed
Push — master ( bedc68...139be6 )
by
unknown
04:13
created

test/integration/EnvironmentSelect.test.tsx   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 34
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 28
mnd 0
bc 0
fnc 1
dl 0
loc 34
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A EnvironmentSelect.test.tsx ➔ generateProps 0 8 1
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