2020-03-17 17:24:27 -05:00
|
|
|
import React from 'react';
|
2022-04-06 06:49:25 -05:00
|
|
|
import { render } from '@testing-library/react';
|
2020-03-17 17:24:27 -05:00
|
|
|
|
|
|
|
import { ExploreId } from '../../../types/explore';
|
|
|
|
import { RichHistoryContainer, Props } from './RichHistoryContainer';
|
|
|
|
import { Tabs } from './RichHistory';
|
2022-04-12 11:55:39 -05:00
|
|
|
import { SortOrder } from '../../../core/utils/richHistoryTypes';
|
2020-03-17 17:24:27 -05:00
|
|
|
|
|
|
|
jest.mock('../state/selectors', () => ({ getExploreDatasources: jest.fn() }));
|
|
|
|
|
|
|
|
const setup = (propOverrides?: Partial<Props>) => {
|
|
|
|
const props: Props = {
|
|
|
|
width: 500,
|
|
|
|
exploreId: ExploreId.left,
|
|
|
|
activeDatasourceInstance: 'Test datasource',
|
|
|
|
richHistory: [],
|
|
|
|
firstTab: Tabs.RichHistory,
|
|
|
|
deleteRichHistory: jest.fn(),
|
2022-04-12 11:55:39 -05:00
|
|
|
initRichHistory: jest.fn(),
|
|
|
|
updateHistorySearchFilters: jest.fn(),
|
|
|
|
updateHistorySettings: jest.fn(),
|
2020-03-17 17:24:27 -05:00
|
|
|
onClose: jest.fn(),
|
2022-04-12 11:55:39 -05:00
|
|
|
richHistorySearchFilters: {
|
|
|
|
search: '',
|
|
|
|
sortOrder: SortOrder.Descending,
|
|
|
|
datasourceFilters: [],
|
|
|
|
from: 0,
|
|
|
|
to: 7,
|
|
|
|
},
|
|
|
|
richHistorySettings: {
|
|
|
|
retentionPeriod: 0,
|
|
|
|
starredTabAsFirstTab: false,
|
|
|
|
activeDatasourceOnly: true,
|
|
|
|
lastUsedDatasourceFilters: [],
|
|
|
|
},
|
2020-03-17 17:24:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
|
2022-04-06 06:49:25 -05:00
|
|
|
return render(<RichHistoryContainer {...props} />);
|
2020-03-17 17:24:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
describe('RichHistoryContainer', () => {
|
2022-04-12 11:55:39 -05:00
|
|
|
it('should show loading message when settings and filters are not ready', () => {
|
|
|
|
const { container } = setup({ richHistorySearchFilters: undefined, richHistorySettings: undefined });
|
|
|
|
expect(container).toHaveTextContent('Loading...');
|
|
|
|
});
|
2020-03-17 17:24:27 -05:00
|
|
|
it('should render component with correct width', () => {
|
2022-04-06 06:49:25 -05:00
|
|
|
const { container } = setup();
|
|
|
|
expect(container.firstElementChild!.getAttribute('style')).toContain('width: 531.5px');
|
2020-03-17 17:24:27 -05:00
|
|
|
});
|
|
|
|
it('should render component with correct height', () => {
|
2022-04-06 06:49:25 -05:00
|
|
|
const { container } = setup();
|
|
|
|
expect(container.firstElementChild!.getAttribute('style')).toContain('height: 400px');
|
|
|
|
});
|
|
|
|
it('should re-request rich history every time the component is mounted', () => {
|
2022-04-12 11:55:39 -05:00
|
|
|
const initRichHistory = jest.fn();
|
|
|
|
const { unmount } = setup({ initRichHistory });
|
|
|
|
expect(initRichHistory).toBeCalledTimes(1);
|
2022-04-06 06:49:25 -05:00
|
|
|
|
|
|
|
unmount();
|
2022-04-12 11:55:39 -05:00
|
|
|
expect(initRichHistory).toBeCalledTimes(1);
|
2022-04-06 06:49:25 -05:00
|
|
|
|
2022-04-12 11:55:39 -05:00
|
|
|
setup({ initRichHistory });
|
|
|
|
expect(initRichHistory).toBeCalledTimes(2);
|
2020-03-17 17:24:27 -05:00
|
|
|
});
|
|
|
|
});
|