2020-03-17 17:24:27 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import { GrafanaTheme } from '@grafana/data';
|
|
|
|
import { ExploreId } from '../../../types/explore';
|
2021-02-11 06:45:25 -06:00
|
|
|
import { RichHistory, RichHistoryProps, Tabs } from './RichHistory';
|
2020-08-06 10:22:54 -05:00
|
|
|
import { Tab } from '@grafana/ui';
|
2020-03-17 17:24:27 -05:00
|
|
|
|
|
|
|
jest.mock('../state/selectors', () => ({ getExploreDatasources: jest.fn() }));
|
|
|
|
|
|
|
|
const setup = (propOverrides?: Partial<RichHistoryProps>) => {
|
|
|
|
const props: RichHistoryProps = {
|
|
|
|
theme: {} as GrafanaTheme,
|
|
|
|
exploreId: ExploreId.left,
|
|
|
|
height: 100,
|
|
|
|
activeDatasourceInstance: 'Test datasource',
|
|
|
|
richHistory: [],
|
|
|
|
firstTab: Tabs.RichHistory,
|
|
|
|
deleteRichHistory: jest.fn(),
|
|
|
|
onClose: jest.fn(),
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
|
|
|
|
const wrapper = mount(<RichHistory {...props} />);
|
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('RichHistory', () => {
|
|
|
|
it('should render all tabs in tab bar', () => {
|
|
|
|
const wrapper = setup();
|
|
|
|
expect(wrapper.find(Tab)).toHaveLength(3);
|
|
|
|
});
|
2020-08-06 10:22:54 -05:00
|
|
|
|
2020-03-17 17:24:27 -05:00
|
|
|
it('should render correct lebels of tabs in tab bar', () => {
|
|
|
|
const wrapper = setup();
|
2021-01-20 00:59:48 -06:00
|
|
|
expect(wrapper.find(Tab).at(0).text()).toEqual('Query history');
|
|
|
|
expect(wrapper.find(Tab).at(1).text()).toEqual('Starred');
|
|
|
|
expect(wrapper.find(Tab).at(2).text()).toEqual('Settings');
|
2020-03-17 17:24:27 -05:00
|
|
|
});
|
2020-08-06 10:22:54 -05:00
|
|
|
|
2020-03-17 17:24:27 -05:00
|
|
|
it('should correctly render query history tab as active tab', () => {
|
|
|
|
const wrapper = setup();
|
2020-08-06 10:22:54 -05:00
|
|
|
expect(wrapper.find('RichHistoryQueriesTab')).toHaveLength(1);
|
2020-03-17 17:24:27 -05:00
|
|
|
});
|
2020-08-06 10:22:54 -05:00
|
|
|
|
2020-03-17 17:24:27 -05:00
|
|
|
it('should correctly render starred tab as active tab', () => {
|
|
|
|
const wrapper = setup({ firstTab: Tabs.Starred });
|
2020-08-06 10:22:54 -05:00
|
|
|
expect(wrapper.find('RichHistoryStarredTab')).toHaveLength(1);
|
2020-03-17 17:24:27 -05:00
|
|
|
});
|
|
|
|
});
|