grafana/public/app/features/explore/spec/queryHistory.test.tsx

297 lines
9.3 KiB
TypeScript
Raw Normal View History

import React from 'react';
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
import { of } from 'rxjs';
import { serializeStateToUrlParam } from '@grafana/data';
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
import { config } from '@grafana/runtime';
import { silenceConsoleOutput } from '../../../../test/core/utils/silenceConsoleOutput';
import { ExploreId } from '../../../types';
import {
assertDataSourceFilterVisibility,
Query History: Results pagination (#49217) * 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 * Basic pagination * Show load more only if there are items to load * Post-merge fixes * Change initial page limit to 100 * Fix unit tests * Fix linting errors * Test pagination * Fix query migration * Fix unit tests * Fix prettier * Remove full stop * Do not show number of queries with partial results to avoid confusion * Show number of displayed results when partial results are shown
2022-05-23 07:43:38 -05:00
assertLoadMoreQueryHistoryNotVisible,
assertQueryHistory,
2022-06-02 08:48:04 -05:00
assertQueryHistoryComment,
Query History: Results pagination (#49217) * 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 * Basic pagination * Show load more only if there are items to load * Post-merge fixes * Change initial page limit to 100 * Fix unit tests * Fix linting errors * Test pagination * Fix query migration * Fix unit tests * Fix prettier * Remove full stop * Do not show number of queries with partial results to avoid confusion * Show number of displayed results when partial results are shown
2022-05-23 07:43:38 -05:00
assertQueryHistoryElementsShown,
assertQueryHistoryExists,
assertQueryHistoryIsStarred,
assertQueryHistoryTabIsSelected,
} from './helper/assert';
Query History: Move local storage specific settings to persistence layer (#47500) * 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
2022-04-12 11:55:39 -05:00
import {
2022-06-02 08:48:04 -05:00
commentQueryHistory,
Query History: Move local storage specific settings to persistence layer (#47500) * 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
2022-04-12 11:55:39 -05:00
closeQueryHistory,
deleteQueryHistory,
inputQuery,
Query History: Results pagination (#49217) * 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 * Basic pagination * Show load more only if there are items to load * Post-merge fixes * Change initial page limit to 100 * Fix unit tests * Fix linting errors * Test pagination * Fix query migration * Fix unit tests * Fix prettier * Remove full stop * Do not show number of queries with partial results to avoid confusion * Show number of displayed results when partial results are shown
2022-05-23 07:43:38 -05:00
loadMoreQueryHistory,
Query History: Move local storage specific settings to persistence layer (#47500) * 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
2022-04-12 11:55:39 -05:00
openQueryHistory,
runQuery,
selectOnlyActiveDataSource,
selectStarredTabFirst,
starQueryHistory,
switchToQueryHistoryTab,
} from './helper/interactions';
import { makeLogsQueryResponse } from './helper/query';
Query History: Results pagination (#49217) * 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 * Basic pagination * Show load more only if there are items to load * Post-merge fixes * Change initial page limit to 100 * Fix unit tests * Fix linting errors * Test pagination * Fix query migration * Fix unit tests * Fix prettier * Remove full stop * Do not show number of queries with partial results to avoid confusion * Show number of displayed results when partial results are shown
2022-05-23 07:43:38 -05:00
import {
localStorageHasAlreadyBeenMigrated,
setupExplore,
setupLocalStorageRichHistory,
tearDown,
waitForExplore,
} from './helper/setup';
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
const fetchMock = jest.fn();
const postMock = jest.fn();
const getMock = jest.fn();
const reportInteractionMock = jest.fn();
Query History: Move filtering to service layer (#48008) * 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) * Fix betterer conflicts * Fix imports * Fix imports * Simplify test setup * Simplify assertion * Improve readability * Remove unnecessary casting * Mock backend in integration tests
2022-04-27 08:07:44 -05:00
jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
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
getBackendSrv: () => ({ fetch: fetchMock, post: postMock, get: getMock }),
reportInteraction: (...args: object[]) => {
reportInteractionMock(...args);
},
Query History: Move filtering to service layer (#48008) * 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) * Fix betterer conflicts * Fix imports * Fix imports * Simplify test setup * Simplify assertion * Improve readability * Remove unnecessary casting * Mock backend in integration tests
2022-04-27 08:07:44 -05:00
}));
jest.mock('app/core/core', () => ({
contextSrv: {
hasAccess: () => true,
isSignedIn: true,
},
}));
jest.mock('app/core/services/PreferencesService', () => ({
PreferencesService: function () {
return {
patch: jest.fn(),
load: jest.fn().mockResolvedValue({
queryHistory: {
homeTab: 'query',
},
}),
};
},
}));
jest.mock('react-virtualized-auto-sizer', () => {
return {
__esModule: true,
default(props: any) {
return <div>{props.children({ width: 1000 })}</div>;
},
};
});
describe('Explore: Query History', () => {
const USER_INPUT = 'my query';
const RAW_QUERY = `{"expr":"${USER_INPUT}"}`;
silenceConsoleOutput();
afterEach(() => {
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
config.queryHistoryEnabled = false;
fetchMock.mockClear();
postMock.mockClear();
getMock.mockClear();
reportInteractionMock.mockClear();
tearDown();
});
it('adds new query history items after the query is run.', async () => {
// when Explore is opened
const { datasources, unmount } = setupExplore();
(datasources.loki.query as jest.Mock).mockReturnValueOnce(makeLogsQueryResponse());
await waitForExplore();
// and a user runs a query and opens query history
await inputQuery(USER_INPUT);
await runQuery();
await openQueryHistory();
// the query that was run is in query history
await assertQueryHistoryExists(RAW_QUERY);
// when Explore is opened again
unmount();
setupExplore({ clearLocalStorage: false });
await waitForExplore();
// previously added query is in query history
await openQueryHistory();
await assertQueryHistoryExists(RAW_QUERY);
expect(reportInteractionMock).toBeCalledWith('grafana_explore_query_history_opened', {
queryHistoryEnabled: false,
});
});
it('adds recently added query if the query history panel is already open', async () => {
const urlParams = {
left: serializeStateToUrlParam({
datasource: 'loki',
queries: [{ refId: 'A', expr: 'query #1' }],
range: { from: 'now-1h', to: 'now' },
}),
};
const { datasources } = setupExplore({ urlParams });
(datasources.loki.query as jest.Mock).mockReturnValueOnce(makeLogsQueryResponse());
await waitForExplore();
await openQueryHistory();
await inputQuery('query #2');
await runQuery();
await assertQueryHistory(['{"expr":"query #2"}', '{"expr":"query #1"}']);
});
it.skip('updates the state in both Explore panes', async () => {
const urlParams = {
left: serializeStateToUrlParam({
datasource: 'loki',
queries: [{ refId: 'A', expr: 'query #1' }],
range: { from: 'now-1h', to: 'now' },
}),
right: serializeStateToUrlParam({
datasource: 'loki',
queries: [{ refId: 'A', expr: 'query #2' }],
range: { from: 'now-1h', to: 'now' },
}),
};
const { datasources } = setupExplore({ urlParams });
(datasources.loki.query as jest.Mock).mockReturnValue(makeLogsQueryResponse());
await waitForExplore();
await waitForExplore(ExploreId.right);
// queries in history
await openQueryHistory(ExploreId.left);
await assertQueryHistory(['{"expr":"query #2"}', '{"expr":"query #1"}'], ExploreId.left);
await openQueryHistory(ExploreId.right);
await assertQueryHistory(['{"expr":"query #2"}', '{"expr":"query #1"}'], ExploreId.right);
// star one one query
await starQueryHistory(1, ExploreId.left);
await assertQueryHistoryIsStarred([false, true], ExploreId.left);
await assertQueryHistoryIsStarred([false, true], ExploreId.right);
expect(reportInteractionMock).toBeCalledWith('grafana_explore_query_history_starred', {
queryHistoryEnabled: false,
newValue: true,
});
await deleteQueryHistory(0, ExploreId.left);
await assertQueryHistory(['{"expr":"query #1"}'], ExploreId.left);
await assertQueryHistory(['{"expr":"query #1"}'], ExploreId.right);
expect(reportInteractionMock).toBeCalledWith('grafana_explore_query_history_deleted', {
queryHistoryEnabled: false,
});
});
Query History: Move local storage specific settings to persistence layer (#47500) * 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
2022-04-12 11:55:39 -05:00
2022-06-02 08:48:04 -05:00
it('add comments to query history', async () => {
const urlParams = {
left: serializeStateToUrlParam({
datasource: 'loki',
queries: [{ refId: 'A', expr: 'query #1' }],
range: { from: 'now-1h', to: 'now' },
}),
};
const { datasources } = setupExplore({ urlParams });
(datasources.loki.query as jest.Mock).mockReturnValueOnce(makeLogsQueryResponse());
await waitForExplore();
await openQueryHistory();
await assertQueryHistory(['{"expr":"query #1"}'], ExploreId.left);
await commentQueryHistory(0, 'test comment');
await assertQueryHistoryComment(['test comment'], ExploreId.left);
});
Query History: Move local storage specific settings to persistence layer (#47500) * 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
2022-04-12 11:55:39 -05:00
it('updates query history settings', async () => {
// open settings page
setupExplore();
await waitForExplore();
await openQueryHistory();
// assert default values
assertQueryHistoryTabIsSelected('Query history');
assertDataSourceFilterVisibility(true);
await switchToQueryHistoryTab('Settings');
// change settings
await selectStarredTabFirst();
await selectOnlyActiveDataSource();
Query History: Move local storage specific settings to persistence layer (#47500) * 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
2022-04-12 11:55:39 -05:00
await closeQueryHistory();
await openQueryHistory();
// assert new settings
assertQueryHistoryTabIsSelected('Starred');
assertDataSourceFilterVisibility(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
describe('local storage migration', () => {
it('does not migrate if query history is not enabled', async () => {
config.queryHistoryEnabled = false;
const { datasources } = setupExplore();
setupLocalStorageRichHistory('loki');
(datasources.loki.query as jest.Mock).mockReturnValueOnce(makeLogsQueryResponse());
getMock.mockReturnValue({ result: { queryHistory: [] } });
await waitForExplore();
await openQueryHistory();
expect(postMock).not.toBeCalledWith('/api/query-history/migrate', { queries: [] });
expect(reportInteractionMock).toBeCalledWith('grafana_explore_query_history_opened', {
queryHistoryEnabled: 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
});
it('migrates query history from local storage', async () => {
config.queryHistoryEnabled = true;
const { datasources } = setupExplore();
setupLocalStorageRichHistory('loki');
(datasources.loki.query as jest.Mock).mockReturnValueOnce(makeLogsQueryResponse());
fetchMock.mockReturnValue(of({ data: { result: { queryHistory: [] } } }));
await waitForExplore();
await openQueryHistory();
expect(fetchMock).toBeCalledWith(
expect.objectContaining({
url: expect.stringMatching('/api/query-history/migrate'),
data: { queries: [expect.objectContaining({ datasourceUid: 'loki-uid' })] },
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
})
);
fetchMock.mockReset();
fetchMock.mockReturnValue(of({ data: { result: { queryHistory: [] } } }));
await closeQueryHistory();
await openQueryHistory();
expect(fetchMock).not.toBeCalledWith(
expect.objectContaining({
url: expect.stringMatching('/api/query-history/migrate'),
})
);
expect(reportInteractionMock).toBeCalledWith('grafana_explore_query_history_opened', {
queryHistoryEnabled: true,
});
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
});
});
Query History: Results pagination (#49217) * 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 * Basic pagination * Show load more only if there are items to load * Post-merge fixes * Change initial page limit to 100 * Fix unit tests * Fix linting errors * Test pagination * Fix query migration * Fix unit tests * Fix prettier * Remove full stop * Do not show number of queries with partial results to avoid confusion * Show number of displayed results when partial results are shown
2022-05-23 07:43:38 -05:00
it('pagination', async () => {
config.queryHistoryEnabled = true;
localStorageHasAlreadyBeenMigrated();
const { datasources } = setupExplore();
(datasources.loki.query as jest.Mock).mockReturnValueOnce(makeLogsQueryResponse());
fetchMock.mockReturnValue(
of({
data: { result: { queryHistory: [{ datasourceUid: 'loki', queries: [{ expr: 'query' }] }], totalCount: 2 } },
})
);
await waitForExplore();
await openQueryHistory();
await assertQueryHistory(['{"expr":"query"}']);
assertQueryHistoryElementsShown(1, 2);
await loadMoreQueryHistory();
await assertQueryHistory(['{"expr":"query"}', '{"expr":"query"}']);
assertLoadMoreQueryHistoryNotVisible();
});
});