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';
|
|
|
|
|
|
|
|
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-06 06:49:25 -05:00
|
|
|
loadRichHistory: jest.fn(),
|
2020-03-17 17:24:27 -05:00
|
|
|
onClose: jest.fn(),
|
|
|
|
};
|
|
|
|
|
|
|
|
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', () => {
|
|
|
|
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', () => {
|
|
|
|
const loadRichHistory = jest.fn();
|
|
|
|
const { unmount } = setup({ loadRichHistory });
|
|
|
|
expect(loadRichHistory).toBeCalledTimes(1);
|
|
|
|
|
|
|
|
unmount();
|
|
|
|
expect(loadRichHistory).toBeCalledTimes(1);
|
|
|
|
|
|
|
|
setup({ loadRichHistory });
|
|
|
|
expect(loadRichHistory).toBeCalledTimes(2);
|
2020-03-17 17:24:27 -05:00
|
|
|
});
|
|
|
|
});
|