mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
* 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
85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
import React from 'react';
|
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
import { configureStore } from 'app/store/configureStore';
|
|
import { Provider } from 'react-redux';
|
|
import { QueryRows } from './QueryRows';
|
|
import { ExploreId, ExploreState } from 'app/types';
|
|
import { makeExplorePaneState } from './state/utils';
|
|
import { setDataSourceSrv } from '@grafana/runtime';
|
|
import { UserState } from '../profile/state/reducers';
|
|
import { DataQuery } from '../../../../packages/grafana-data/src';
|
|
|
|
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 any);
|
|
|
|
const leftState = makeExplorePaneState();
|
|
const initialState: ExploreState = {
|
|
left: {
|
|
...leftState,
|
|
richHistory: [],
|
|
datasourceInstance: datasources['someDs-uid'],
|
|
queries,
|
|
},
|
|
syncedTimes: false,
|
|
right: undefined,
|
|
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={ExploreId.left} />
|
|
</Provider>
|
|
);
|
|
|
|
// waiting for the d&d component to fully render.
|
|
await screen.findAllByText('someDs query editor');
|
|
|
|
let duplicateButton = screen.getByTitle('Duplicate query');
|
|
|
|
fireEvent.click(duplicateButton);
|
|
|
|
// We should have another row with refId B
|
|
expect(await screen.findByLabelText('Query editor row title B')).toBeInTheDocument();
|
|
});
|
|
});
|