grafana/public/app/features/explore/QueryRows.test.tsx

95 lines
2.5 KiB
TypeScript
Raw Normal View History

import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { Provider } from 'react-redux';
Build: Introduce ESM and Treeshaking to NPM package builds (#51517) * Revert "Chore: Bump terser to fix security vulnerability (#53052)" This reverts commit 7ae74d2a18f961dfc868bcab4c380ef910e36884. * feat: use tsc and rollup directly with esbuild and publishConfig, files props * refactor(grafana-data): fix isolatedModules re-export type error * refactor(grafana-data): import paths from src not package name * refactor(rollup): fix dts output.file * chore(grafana-schema): delete dashboard_experimental.gen.ts - cannot work with isolatedModules * refactor(grafana-e2e-selectors): fix export types isolatedModules error * refactor(grafana-runtime): fix isolatedModules re-export type error * refactor(grafana-ui): fix isolatedModules re-export type error * feat(grafana-ui): use named imports for treeshaking * refactor(grafana-ui): use named imports for treeshaking * feat: react and react-dom as peerDeps for packages * feat(grafana-ui): emotion packages as peerDeps * feat(grafana-e2e): use tsc, rollup, esbuild for bundling * chore(packages): clean up redundant dependencies * chore(toolkit): deprecate unused package:build task * chore(schema): put back dashboard_experimental and exclude to prevent isolatedModules error * docs(packages): update readme * chore(storybook): disable isolatedModules for builds * chore: relax peerDeps for emotion and react * revert(grafana-ui): put @emotion dependencies back * refactor: replace relative package imports with package name * build(packages): set emitDeclaration false for typecheck scripts to work * test(publicdashboarddatasource): move test next to implementation. try to appease the betterer gods * chore(storybook): override ts-node config for storybook compilation * refactor(grafana-data): use ternary so babel doesnt complain about expecting flow types * chore(toolkit): prefer files and publishConfig package.json props over copying * build(npm): remove --contents dist arg from publishing commands * chore(packages): introduce sideEffects prop to package.json to hint package can be treeshaken * chore(packages): remove redundant index.js files * feat(packages): set publishConfig.access to public * feat(packages): use yarn berry and npm for packaging and publishing * refactor(packages): simplify rollup configs * chore(schema): add comment explaining need to exclude dashboard_experimental * revert(toolkit): put back clean to prevent cli failures * ci(packages): run packages:pack before a canary publish * chore(gitignore): add npm-artifacts directory to ignore list * test(publicdashboarddatasource): fix module mocking * chore(packages): delete package.tgz when running clean * chore(grafana-data): move dependencies from devDeps to prevent build resolution errors
2022-08-03 08:47:09 -05:00
import { DataQuery } from '@grafana/data';
import { setDataSourceSrv } from '@grafana/runtime';
import { configureStore } from 'app/store/configureStore';
import { ExploreId, 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 any);
const leftState = makeExplorePaneState();
const initialState: ExploreState = {
left: {
...leftState,
richHistory: [],
datasourceInstance: datasources['someDs-uid'],
queries,
},
syncedTimes: false,
correlations: [],
right: undefined,
richHistoryStorageFull: false,
richHistoryLimitExceededWarningShown: false,
Query History: Migrate local storage to remote storage (#48572) * 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 * Move query history settings to persistence layer * Fix test import * Fix unit test * Fix unit test * Test local storage settings API * Code formatting * Fix linting errors * Add an integration test * Add missing aria role * Fix a11y issues * Fix a11y issues * Use divs instead of ul/li Otherwis,e pa11y-ci reports the error below claiming there are no children with role=tab: Certain ARIA roles must contain particular children (https://dequeuniversity.com/rules/axe/4.3/aria-required-children?application=axeAPI) (#reactRoot > div > main > div:nth-child(3) > div > div:nth-child(1) > div > div:nth-child(1) > div > div > nav > div:nth-child(2) > ul) <ul class="css-af3vye" role="tablist"><li class="css-1ciwanz"><a href...</ul> * Clean up settings tab * Remove redundant aria label * Remove redundant container * Clean up test assertions * Move filtering to persistence layer * Move filtering to persistence layer * Simplify applying filters * Split applying filters and reloading the history * Debounce updating filters * Update tests * Fix waiting for debounced results * Clear results when switching tabs * Improve test coverage * Update docs * Revert extra handling for uid (will be added when we introduce remote storage) * Create basic plan * Rename query history toggle * Add list of supported features and add ds name to RichHistoryQuery object * Clean up Removed planned items will be addressed in upcoming prs (filtering and pagination) * Handle data source filters * Simplify DTO conversion * Clean up * Fix betterer conflicts * Fix imports * Fix imports * Post-merge fixes * Use config instead of a feature flag * Use config instead of a feature flag * Update converter tests * Add tests for RichHistoryRemoteStorage * Simplify test setup * Simplify assertion * Add e2e test for query history * Remove duplicated entry * Fix unit tests * Improve readability * Remove unnecessary casting * Mock backend in integration tests * Remove unnecessary casting * Fix integration test * Update betterer results * Fix unit tests * Simplify testing with DataSourceSrv * Fix sorting and add to/from filtering * Add migration for local storage query history * Test query history migration * Simplify testing DataSourceSettings * Skip redundant migrations * Revert error logging test * Fix tests * Update betterer results * Change notification message after migration * Ensure previous request is canceled when getting search results * Add loading message when results are being loaded * Show info message only if local storage is enabled * Fix unit test * Post-merge fixes * Fix intergration tests * Fix incorrect filtering
2022-05-19 06:45:32 -05:00
richHistoryMigrationFailed: 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.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();
});
});