diff --git a/public/app/features/explore/ExplorePage.test.tsx b/public/app/features/explore/ExplorePage.test.tsx index bd16ed3546d..79fb6bcf86c 100644 --- a/public/app/features/explore/ExplorePage.test.tsx +++ b/public/app/features/explore/ExplorePage.test.tsx @@ -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(); diff --git a/public/app/features/explore/spec/datasourceState.test.tsx b/public/app/features/explore/spec/datasourceState.test.tsx new file mode 100644 index 00000000000..e5d00751ca6 --- /dev/null +++ b/public/app/features/explore/spec/datasourceState.test.tsx @@ -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' }, + }), + }); + }); +});