grafana/public/app/features/explore/RichHistory/RichHistory.test.tsx
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

62 lines
1.8 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import React from 'react';
import { GrafanaTheme } from '@grafana/data';
import { SortOrder } from '../../../core/utils/richHistoryTypes';
import { ExploreId } from '../../../types/explore';
import { RichHistory, RichHistoryProps, Tabs } from './RichHistory';
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(),
richHistorySearchFilters: {
search: '',
sortOrder: SortOrder.Descending,
datasourceFilters: [],
from: 0,
to: 7,
},
richHistorySettings: {
retentionPeriod: 0,
starredTabAsFirstTab: false,
activeDatasourceOnly: true,
lastUsedDatasourceFilters: [],
},
updateHistorySearchFilters: jest.fn(),
updateHistorySettings: jest.fn(),
};
Object.assign(props, propOverrides);
render(<RichHistory {...props} />);
};
describe('RichHistory', () => {
it('should render tabs as defined', () => {
setup();
const tabs = screen.getAllByLabelText(/Tab*/);
expect(tabs).toHaveLength(3);
expect(tabs[0]).toHaveTextContent('Query history');
expect(tabs[1]).toHaveTextContent('Starred');
expect(tabs[2]).toHaveTextContent('Settings');
});
it('should render defined default', () => {
setup();
const tabs = screen.getAllByLabelText(/Tab*/);
expect(tabs[0].className).toMatch(/-*activeTabStyle/);
expect(tabs[1].className).not.toMatch(/-*activeTabStyle/);
});
});