2020-03-17 17:24:27 -05:00
|
|
|
import { mount } from 'enzyme';
|
2022-04-22 08:33:13 -05:00
|
|
|
import React from 'react';
|
|
|
|
|
2020-08-06 11:35:49 -05:00
|
|
|
import { SortOrder } from 'app/core/utils/richHistory';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
|
|
|
import { ExploreId } from '../../../types/explore';
|
|
|
|
|
2020-03-17 17:24:27 -05:00
|
|
|
import { RichHistoryStarredTab, Props } from './RichHistoryStarredTab';
|
|
|
|
|
|
|
|
jest.mock('../state/selectors', () => ({ getExploreDatasources: jest.fn() }));
|
|
|
|
|
2022-04-27 08:07:44 -05:00
|
|
|
jest.mock('@grafana/runtime', () => ({
|
|
|
|
...jest.requireActual('@grafana/runtime'),
|
|
|
|
getDataSourceSrv: () => {
|
|
|
|
return {
|
|
|
|
getList: () => [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
const setup = (activeDatasourceOnly = false) => {
|
2020-03-17 17:24:27 -05:00
|
|
|
const props: Props = {
|
|
|
|
queries: [],
|
2022-05-17 05:59:16 -05:00
|
|
|
loading: false,
|
|
|
|
activeDatasourceInstance: {} as any,
|
2022-04-27 08:07:44 -05:00
|
|
|
updateFilters: jest.fn(),
|
|
|
|
clearRichHistoryResults: jest.fn(),
|
2020-03-17 17:24:27 -05:00
|
|
|
exploreId: ExploreId.left,
|
2022-04-27 08:07:44 -05:00
|
|
|
richHistorySettings: {
|
|
|
|
retentionPeriod: 7,
|
|
|
|
starredTabAsFirstTab: false,
|
|
|
|
activeDatasourceOnly,
|
|
|
|
lastUsedDatasourceFilters: [],
|
|
|
|
},
|
|
|
|
richHistorySearchFilters: {
|
|
|
|
search: '',
|
|
|
|
sortOrder: SortOrder.Ascending,
|
|
|
|
datasourceFilters: [],
|
|
|
|
from: 0,
|
|
|
|
to: 7,
|
|
|
|
starred: false,
|
|
|
|
},
|
2020-03-17 17:24:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = mount(<RichHistoryStarredTab {...props} />);
|
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('RichHistoryStarredTab', () => {
|
|
|
|
describe('sorter', () => {
|
|
|
|
it('should render sorter', () => {
|
|
|
|
const wrapper = setup();
|
|
|
|
expect(wrapper.find({ 'aria-label': 'Sort queries' })).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('select datasource', () => {
|
|
|
|
it('should render select datasource if activeDatasourceOnly is false', () => {
|
|
|
|
const wrapper = setup();
|
2022-04-12 11:55:39 -05:00
|
|
|
expect(wrapper.find({ 'aria-label': 'Filter queries for data sources(s)' }).exists()).toBeTruthy();
|
2020-03-17 17:24:27 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render select datasource if activeDatasourceOnly is true', () => {
|
2022-04-27 08:07:44 -05:00
|
|
|
const wrapper = setup(true);
|
2022-04-12 11:55:39 -05:00
|
|
|
expect(wrapper.find({ 'aria-label': 'Filter queries for data sources(s)' }).exists()).toBeFalsy();
|
2020-03-17 17:24:27 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|