grafana/public/app/features/explore/RichHistory/RichHistoryContainer.test.tsx
Piotr Jamróz 88ec750728
Query History: Load history when QueryHistoryContainer is opened (#46457)
* Load Rich History when the container is opened

* Store rich history for each pane separately

* Do not update currently opened query history when an item is added

It's impossible to figure out if the item should be added or not, because filters are applied in the backend. We don't want to replicate that filtering logic in frontend. One way to make it work could be by refreshing both panes.

* Test starring and deleting query history items when both panes are open

* Remove e2e dependency on ExploreId

* Fix unit test

* Assert exact queries

* Simplify test

* Fix e2e tests

* Fix toolbar a11y

* Reload the history after an item is added

* Fix unit test

* Remove references to Explore from generic PageToolbar component

* Update test name

* Fix test assertion

* Add issue item to TODO

* Improve test assertion

* Simplify test setup
2022-04-06 13:49:25 +02:00

48 lines
1.5 KiB
TypeScript

import React from 'react';
import { render } from '@testing-library/react';
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(),
loadRichHistory: jest.fn(),
onClose: jest.fn(),
};
Object.assign(props, propOverrides);
return render(<RichHistoryContainer {...props} />);
};
describe('RichHistoryContainer', () => {
it('should render component with correct width', () => {
const { container } = setup();
expect(container.firstElementChild!.getAttribute('style')).toContain('width: 531.5px');
});
it('should render component with correct height', () => {
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);
});
});