prometheus/web/ui/react-app/src/Checkbox.test.tsx
Dustin Hooten e0443e6fa3 Add unit tests for react-app (#6234)
* Add MetricFormat unit tests

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add App unit tests; Add debug script

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add Checkbox unit tests

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add SeriesName unit tests

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add QueryStatsView unit test

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add Legend unit tests

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Remove unused utils/func

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add utils/urlParams unit test

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add utils/timeFormat unit test

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add ExpressionInput unit tests

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add GraphControls unit test

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add TimeInput unit test

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add DataTable unit test

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add SanitizeHTML unit test

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add Graph unit test

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Extract utils/html

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add PanelList unit test

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add Panel unit test

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add react-ui test coverage report to CI

Signed-off-by: Dustin Hooten <dhooten@splunk.com>
2019-10-28 18:09:48 +01:00

66 lines
2.4 KiB
TypeScript
Executable file

import * as React from 'react';
import { shallow } from 'enzyme';
import Checkbox from './Checkbox';
import { FormGroup, Label, Input } from 'reactstrap';
const MockCmp: React.FC = () => <div className="mock" />;
describe('Checkbox', () => {
it('renders with subcomponents', () => {
const checkBox = shallow(<Checkbox />);
[FormGroup, Input, Label].forEach(component => expect(checkBox.find(component)).toHaveLength(1));
});
it('passes down the correct FormGroup props', () => {
const checkBoxProps = { wrapperStyles: { color: 'orange' } };
const checkBox = shallow(<Checkbox {...checkBoxProps} />);
const formGroup = checkBox.find(FormGroup);
expect(Object.keys(formGroup.props())).toHaveLength(4);
expect(formGroup.prop('className')).toEqual('custom-control custom-checkbox');
expect(formGroup.prop('children')).toHaveLength(2);
expect(formGroup.prop('style')).toEqual({ color: 'orange' });
expect(formGroup.prop('tag')).toEqual('div');
});
it('passes down the correct FormGroup Input props', () => {
const results: string[] = [];
const checkBoxProps = {
onChange: (): void => {
results.push('clicked');
},
};
const checkBox = shallow(<Checkbox {...checkBoxProps} id="1" />);
const input = checkBox.find(Input);
expect(Object.keys(input.props())).toHaveLength(4);
expect(input.prop('className')).toEqual('custom-control-input');
expect(input.prop('id')).toMatch('1');
expect(input.prop('type')).toEqual('checkbox');
input.simulate('change');
expect(results).toHaveLength(1);
expect(results[0]).toEqual('clicked');
});
it('passes down the correct Label props', () => {
const checkBox = shallow(
<Checkbox id="1">
<MockCmp />
</Checkbox>
);
const label = checkBox.find(Label);
expect(Object.keys(label.props())).toHaveLength(6);
expect(label.prop('className')).toEqual('custom-control-label');
expect(label.find(MockCmp)).toHaveLength(1);
expect(label.prop('for')).toMatch('1');
expect(label.prop('style')).toEqual({ userSelect: 'none' });
expect(label.prop('tag')).toEqual('label');
});
it('shares checkbox `id` uuid with Input/Label subcomponents', () => {
const checkBox = shallow(<Checkbox id="2" />);
const input = checkBox.find(Input);
const label = checkBox.find(Label);
expect(label.prop('for')).toBeDefined();
expect(label.prop('for')).toEqual(input.prop('id'));
});
});