mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* Add pagination params and apply to sql * Create getCorrelationsResponse that returns metadata * Set up pagination, change correlations fetch to only get source datasource correlations * Move correlations from root to pane, only fetch correlations for one datasource when initialized or datasource is changed * Fix tests * Fix remaining tests * Use functional component to handle state * Remove unneeded mocks, fix tests * Change perPage to limit * Fix Go Tests * Fix linter * Remove parameter * Account for mixed datasources * Delete unused hook * add source UID filter to API, start backing out front end hook changes * add source IDs to API, use when loading or changing datasource * Fix prettier * Mock correlations response * Get correlations for all datasources in mixed scenario * Add documentation for new parameters * Attempt to fix swagger * Fix correlations page * add swagger and openapi docs * Add mocks to failing test * Change API for consistency, remove extra hooks and unused function * Add max to limit and re-gen api docs * Move the page to the previous page if deleting all the rows on the page * Only fetch if remove does not have value * Change page to a reference hook * Fix documentation, a test and some logic thinking page could be 0
95 lines
2.5 KiB
TypeScript
95 lines
2.5 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react';
|
|
import React from 'react';
|
|
import { Provider } from 'react-redux';
|
|
|
|
import { DataSourceSrv, setDataSourceSrv } from '@grafana/runtime';
|
|
import { DataQuery } from '@grafana/schema';
|
|
import { configureStore } from 'app/store/configureStore';
|
|
import { ExploreState } from 'app/types';
|
|
|
|
import { UserState } from '../profile/state/reducers';
|
|
|
|
import { QueryRows } from './QueryRows';
|
|
import { makeExplorePaneState } from './state/utils';
|
|
|
|
jest.mock('@grafana/runtime', () => ({
|
|
...jest.requireActual('@grafana/runtime'),
|
|
reportInteraction: () => null,
|
|
}));
|
|
|
|
function setup(queries: DataQuery[]) {
|
|
const defaultDs = {
|
|
name: 'newDs',
|
|
uid: 'newDs-uid',
|
|
meta: { id: 'newDs' },
|
|
};
|
|
|
|
const datasources: Record<string, any> = {
|
|
'newDs-uid': defaultDs,
|
|
'someDs-uid': {
|
|
name: 'someDs',
|
|
uid: 'someDs-uid',
|
|
meta: { id: 'someDs' },
|
|
components: {
|
|
QueryEditor: () => 'someDs query editor',
|
|
},
|
|
},
|
|
};
|
|
|
|
setDataSourceSrv({
|
|
getList() {
|
|
return Object.values(datasources).map((d) => ({ name: d.name }));
|
|
},
|
|
getInstanceSettings(uid: string) {
|
|
return datasources[uid] || defaultDs;
|
|
},
|
|
get(uid?: string) {
|
|
return Promise.resolve(uid ? datasources[uid] || defaultDs : defaultDs);
|
|
},
|
|
} as DataSourceSrv);
|
|
|
|
const leftState = makeExplorePaneState();
|
|
const initialState: ExploreState = {
|
|
panes: {
|
|
left: {
|
|
...leftState,
|
|
richHistory: [],
|
|
datasourceInstance: datasources['someDs-uid'],
|
|
queries,
|
|
correlations: [],
|
|
},
|
|
},
|
|
syncedTimes: false,
|
|
richHistoryStorageFull: false,
|
|
richHistoryLimitExceededWarningShown: false,
|
|
};
|
|
const store = configureStore({ explore: initialState, user: { orgId: 1 } as UserState });
|
|
|
|
return {
|
|
store,
|
|
datasources,
|
|
};
|
|
}
|
|
|
|
describe('Explore QueryRows', () => {
|
|
it('Should duplicate a query and generate a valid refId', async () => {
|
|
const { store } = setup([{ refId: 'A' }]);
|
|
|
|
render(
|
|
<Provider store={store}>
|
|
<QueryRows exploreId={'left'} />
|
|
</Provider>
|
|
);
|
|
|
|
// waiting for the d&d component to fully render.
|
|
await screen.findAllByText('someDs query editor');
|
|
|
|
let duplicateButton = screen.getByLabelText(/Duplicate query/i);
|
|
|
|
fireEvent.click(duplicateButton);
|
|
|
|
// We should have another row with refId B
|
|
expect(await screen.findByLabelText('Query editor row title B')).toBeInTheDocument();
|
|
});
|
|
});
|