mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* WIP * Use splitpanewrapper for drawer * Get rich history pulling from multiple datasources * highlight pane * Fix datasource data handling * create ds/explore map, move around ds lookup * Handle no filters * Fix tests and some errors * Fix context menu issue * (Poorly) enable scrolling, fix onClose to function * Remove highlighting, use legacy key, fix casing * fix filtering to handle non-simple data * Fix linter, add translations * Fixing tests~~ * Move to explore drawer and fix some more tests * Kinda fix drawer stuff? * Fix remaining card tests * Fix test * Fix tests * Partially fix starred tab tests * Fix integration tests * Fix remaining tests 🤞 * Add a test and a clarifying comment behind a couple hooks * Remove unused code * Fix button styling and fix animation (but break width) * Make Drawer using parent width (100%) * Fix tests and some small catches * Add tests for selectExploreDSMaps selector --------- Co-authored-by: Piotr Jamroz <pm.jamroz@gmail.com>
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import React from 'react';
|
|
import { TestProvider } from 'test/helpers/TestProvider';
|
|
|
|
import { SortOrder } from 'app/core/utils/richHistory';
|
|
|
|
import { RichHistory, RichHistoryProps, Tabs } from './RichHistory';
|
|
|
|
jest.mock('../state/selectors', () => ({ selectExploreDSMaps: jest.fn().mockReturnValue({ dsToExplore: [] }) }));
|
|
|
|
jest.mock('@grafana/runtime', () => ({
|
|
...jest.requireActual('@grafana/runtime'),
|
|
getDataSourceSrv: () => {
|
|
return {
|
|
getList: () => {
|
|
return [];
|
|
},
|
|
};
|
|
},
|
|
}));
|
|
|
|
jest.mock('react-use', () => ({
|
|
...jest.requireActual('react-use'),
|
|
useAsync: () => ({ loading: false, value: [] }),
|
|
}));
|
|
|
|
const setup = (propOverrides?: Partial<RichHistoryProps>) => {
|
|
const props: RichHistoryProps = {
|
|
height: 100,
|
|
richHistory: [],
|
|
richHistoryTotal: 0,
|
|
firstTab: Tabs.RichHistory,
|
|
deleteRichHistory: jest.fn(),
|
|
loadRichHistory: jest.fn(),
|
|
loadMoreRichHistory: jest.fn(),
|
|
clearRichHistoryResults: jest.fn(),
|
|
onClose: jest.fn(),
|
|
richHistorySearchFilters: {
|
|
search: '',
|
|
sortOrder: SortOrder.Descending,
|
|
datasourceFilters: [],
|
|
from: 0,
|
|
to: 7,
|
|
starred: false,
|
|
},
|
|
richHistorySettings: {
|
|
retentionPeriod: 0,
|
|
starredTabAsFirstTab: false,
|
|
activeDatasourcesOnly: true,
|
|
lastUsedDatasourceFilters: [],
|
|
},
|
|
updateHistorySearchFilters: jest.fn(),
|
|
updateHistorySettings: jest.fn(),
|
|
};
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
render(
|
|
<TestProvider>
|
|
<RichHistory {...props} />
|
|
</TestProvider>
|
|
);
|
|
};
|
|
|
|
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/);
|
|
});
|
|
});
|