prometheus/web/ui/react-app/src/PanelList.test.tsx

41 lines
1.4 KiB
TypeScript
Raw Normal View History

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 10:09:48 -07:00
import * as React from 'react';
import { mount, shallow } from 'enzyme';
import PanelList from './pages/PanelList';
import Checkbox from './Checkbox';
import { Alert, Button } from 'reactstrap';
import Panel from './Panel';
describe('PanelList', () => {
it('renders a query history checkbox', () => {
const panelList = shallow(<PanelList />);
const checkbox = panelList.find(Checkbox);
expect(checkbox.prop('id')).toEqual('query-history-checkbox');
expect(checkbox.prop('wrapperStyles')).toEqual({
margin: '0 0 0 15px',
alignSelf: 'center',
});
expect(checkbox.prop('defaultChecked')).toBe(false);
expect(checkbox.children().text()).toBe('Enable query history');
});
it('renders an alert when no data is queried yet', () => {
const panelList = mount(<PanelList />);
const alert = panelList.find(Alert);
expect(alert.prop('color')).toEqual('light');
expect(alert.children().text()).toEqual('No data queried yet');
});
it('renders panels', () => {
const panelList = shallow(<PanelList />);
const panels = panelList.find(Panel);
expect(panels.length).toBeGreaterThan(0);
});
it('renders a button to add a panel', () => {
const panelList = shallow(<PanelList />);
const btn = panelList.find(Button).filterWhere(btn => btn.prop('className') === 'add-panel-btn');
expect(btn.prop('color')).toEqual('primary');
expect(btn.children().text()).toEqual('Add Panel');
});
});