Laura/refactor/move tests for handling datasource states (#63638)
refactor: move tests to a new file and clean up original file
This commit is contained in:
@@ -6,7 +6,6 @@ import AutoSizer from 'react-virtualized-auto-sizer';
|
||||
import { serializeStateToUrlParam } from '@grafana/data';
|
||||
import { locationService, config } from '@grafana/runtime';
|
||||
|
||||
import { changeDatasource } from './spec/helper/interactions';
|
||||
import { makeLogsQueryResponse } from './spec/helper/query';
|
||||
import { setupExplore, tearDown, waitForExplore } from './spec/helper/setup';
|
||||
import * as mainState from './state/main';
|
||||
@@ -39,32 +38,6 @@ describe('ExplorePage', () => {
|
||||
tearDown();
|
||||
});
|
||||
|
||||
describe('Handles datasource states', () => {
|
||||
it('shows warning if there are no data sources', async () => {
|
||||
setupExplore({ datasources: [] });
|
||||
await waitFor(() => screen.getByText(/Explore requires at least one data source/i));
|
||||
});
|
||||
|
||||
it('handles changing the datasource manually', async () => {
|
||||
const urlParams = { left: JSON.stringify(['now-1h', 'now', 'loki', { expr: '{ label="value"}', refId: 'A' }]) };
|
||||
const { datasources } = setupExplore({ urlParams });
|
||||
jest.mocked(datasources.loki.query).mockReturnValueOnce(makeLogsQueryResponse());
|
||||
await waitForExplore();
|
||||
await changeDatasource('elastic');
|
||||
|
||||
await screen.findByText('elastic Editor input:');
|
||||
expect(datasources.elastic.query).not.toBeCalled();
|
||||
expect(locationService.getSearchObject()).toEqual({
|
||||
orgId: '1',
|
||||
left: serializeStateToUrlParam({
|
||||
datasource: 'elastic-uid',
|
||||
queries: [{ refId: 'A', datasource: { type: 'logs', uid: 'elastic-uid' } }],
|
||||
range: { from: 'now-1h', to: 'now' },
|
||||
}),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Handles open/close splits and related events in UI and URL', () => {
|
||||
it('opens the split pane when split button is clicked', async () => {
|
||||
setupExplore();
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { screen, waitFor } from '@testing-library/react';
|
||||
|
||||
import { serializeStateToUrlParam } from '@grafana/data';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
|
||||
import { changeDatasource } from './helper/interactions';
|
||||
import { makeLogsQueryResponse } from './helper/query';
|
||||
import { setupExplore, tearDown, waitForExplore } from './helper/setup';
|
||||
|
||||
describe('Explore: handle datasource states', () => {
|
||||
afterEach(() => {
|
||||
tearDown();
|
||||
});
|
||||
it('shows warning if there are no data sources', async () => {
|
||||
setupExplore({ datasources: [] });
|
||||
await waitFor(() => screen.getByText(/Explore requires at least one data source/i));
|
||||
});
|
||||
|
||||
it('handles changing the datasource manually', async () => {
|
||||
const urlParams = { left: JSON.stringify(['now-1h', 'now', 'loki', { expr: '{ label="value"}', refId: 'A' }]) };
|
||||
const { datasources } = setupExplore({ urlParams });
|
||||
jest.mocked(datasources.loki.query).mockReturnValueOnce(makeLogsQueryResponse());
|
||||
await waitForExplore();
|
||||
await changeDatasource('elastic');
|
||||
|
||||
await screen.findByText('elastic Editor input:');
|
||||
expect(datasources.elastic.query).not.toBeCalled();
|
||||
expect(locationService.getSearchObject()).toEqual({
|
||||
orgId: '1',
|
||||
left: serializeStateToUrlParam({
|
||||
datasource: 'elastic-uid',
|
||||
queries: [{ refId: 'A', datasource: { type: 'logs', uid: 'elastic-uid' } }],
|
||||
range: { from: 'now-1h', to: 'now' },
|
||||
}),
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user