The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/explore/hooks/useTimeSrvFix.test.tsx

38 lines
1.1 KiB

import { renderHook, waitFor } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import { stringify } from 'querystring';
import { TestProvider } from 'test/helpers/TestProvider';
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
import { HistoryWrapper } from '@grafana/runtime';
import { useTimeSrvFix } from './useTimeSrvFix';
describe('useTimeSrvFix', () => {
it('removes `from` and `to` parameters from url when first mounted', async () => {
const history = createMemoryHistory({
initialEntries: [{ pathname: '/explore', search: stringify({ from: '1', to: '2' }) }],
});
const location = new HistoryWrapper(history);
const context = getGrafanaContextMock();
renderHook(() => useTimeSrvFix(), {
wrapper: ({ children }) => (
<TestProvider
grafanaContext={{
...context,
location,
}}
>
{children}
</TestProvider>
),
});
await waitFor(() => {
expect(location.getSearchObject()).toEqual(expect.not.objectContaining({ from: '1', to: '2' }));
});
});
});