|
|
|
@ -1,18 +1,21 @@ |
|
|
|
|
import { refreshExplore, loadDatasource } from './actions'; |
|
|
|
|
import { ExploreId, ExploreUrlState, ExploreUpdateState, ExploreMode } from 'app/types'; |
|
|
|
|
import { loadDatasource, navigateToExplore, refreshExplore } from './actions'; |
|
|
|
|
import { ExploreId, ExploreMode, ExploreUpdateState, ExploreUrlState } from 'app/types'; |
|
|
|
|
import { thunkTester } from 'test/core/thunk/thunkTester'; |
|
|
|
|
import { |
|
|
|
|
initializeExploreAction, |
|
|
|
|
InitializeExplorePayload, |
|
|
|
|
updateUIStateAction, |
|
|
|
|
setQueriesAction, |
|
|
|
|
loadDatasourcePendingAction, |
|
|
|
|
loadDatasourceReadyAction, |
|
|
|
|
setQueriesAction, |
|
|
|
|
updateUIStateAction, |
|
|
|
|
} from './actionTypes'; |
|
|
|
|
import { Emitter } from 'app/core/core'; |
|
|
|
|
import { ActionOf } from 'app/core/redux/actionCreatorFactory'; |
|
|
|
|
import { makeInitialUpdateState } from './reducers'; |
|
|
|
|
import { DataQuery, DefaultTimeZone, RawTimeRange, LogsDedupStrategy, toUtc } from '@grafana/data'; |
|
|
|
|
import { DataQuery, DefaultTimeZone, LogsDedupStrategy, RawTimeRange, toUtc } from '@grafana/data'; |
|
|
|
|
import { PanelModel } from 'app/features/dashboard/state'; |
|
|
|
|
import { updateLocation } from '../../../core/actions'; |
|
|
|
|
import { MockDataSourceApi } from '../../../../test/mocks/datasource_srv'; |
|
|
|
|
|
|
|
|
|
jest.mock('app/features/plugins/datasource_srv', () => ({ |
|
|
|
|
getDatasourceSrv: () => ({ |
|
|
|
@ -218,3 +221,129 @@ describe('loading datasource', () => { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const getNavigateToExploreContext = async (openInNewWindow: (url: string) => void = undefined) => { |
|
|
|
|
const url = 'http://www.someurl.com'; |
|
|
|
|
const panel: Partial<PanelModel> = { |
|
|
|
|
datasource: 'mocked datasource', |
|
|
|
|
targets: [{ refId: 'A' }], |
|
|
|
|
}; |
|
|
|
|
const datasource = new MockDataSourceApi(panel.datasource); |
|
|
|
|
const get = jest.fn().mockResolvedValue(datasource); |
|
|
|
|
const getDataSourceSrv = jest.fn().mockReturnValue({ get }); |
|
|
|
|
const getTimeSrv = jest.fn(); |
|
|
|
|
const getExploreUrl = jest.fn().mockResolvedValue(url); |
|
|
|
|
|
|
|
|
|
const dispatchedActions = await thunkTester({}) |
|
|
|
|
.givenThunk(navigateToExplore) |
|
|
|
|
.whenThunkIsDispatched(panel, { getDataSourceSrv, getTimeSrv, getExploreUrl, openInNewWindow }); |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
url, |
|
|
|
|
panel, |
|
|
|
|
datasource, |
|
|
|
|
get, |
|
|
|
|
getDataSourceSrv, |
|
|
|
|
getTimeSrv, |
|
|
|
|
getExploreUrl, |
|
|
|
|
dispatchedActions, |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
describe('navigateToExplore', () => { |
|
|
|
|
describe('when navigateToExplore thunk is dispatched', () => { |
|
|
|
|
describe('and openInNewWindow is undefined', () => { |
|
|
|
|
const openInNewWindow: (url: string) => void = undefined; |
|
|
|
|
it('then it should dispatch correct actions', async () => { |
|
|
|
|
const { dispatchedActions, url } = await getNavigateToExploreContext(openInNewWindow); |
|
|
|
|
|
|
|
|
|
expect(dispatchedActions).toEqual([updateLocation({ path: url, query: {} })]); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('then getDataSourceSrv should have been once', async () => { |
|
|
|
|
const { getDataSourceSrv } = await getNavigateToExploreContext(openInNewWindow); |
|
|
|
|
|
|
|
|
|
expect(getDataSourceSrv).toHaveBeenCalledTimes(1); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('then getDataSourceSrv.get should have been called with correct arguments', async () => { |
|
|
|
|
const { get, panel } = await getNavigateToExploreContext(openInNewWindow); |
|
|
|
|
|
|
|
|
|
expect(get).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(get).toHaveBeenCalledWith(panel.datasource); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('then getTimeSrv should have been called once', async () => { |
|
|
|
|
const { getTimeSrv } = await getNavigateToExploreContext(openInNewWindow); |
|
|
|
|
|
|
|
|
|
expect(getTimeSrv).toHaveBeenCalledTimes(1); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('then getExploreUrl should have been called with correct arguments', async () => { |
|
|
|
|
const { getExploreUrl, panel, datasource, getDataSourceSrv, getTimeSrv } = await getNavigateToExploreContext( |
|
|
|
|
openInNewWindow |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
expect(getExploreUrl).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(getExploreUrl).toHaveBeenCalledWith({ |
|
|
|
|
panel, |
|
|
|
|
panelTargets: panel.targets, |
|
|
|
|
panelDatasource: datasource, |
|
|
|
|
datasourceSrv: getDataSourceSrv(), |
|
|
|
|
timeSrv: getTimeSrv(), |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('and openInNewWindow is defined', () => { |
|
|
|
|
const openInNewWindow: (url: string) => void = jest.fn(); |
|
|
|
|
it('then it should dispatch no actions', async () => { |
|
|
|
|
const { dispatchedActions } = await getNavigateToExploreContext(openInNewWindow); |
|
|
|
|
|
|
|
|
|
expect(dispatchedActions).toEqual([]); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('then getDataSourceSrv should have been once', async () => { |
|
|
|
|
const { getDataSourceSrv } = await getNavigateToExploreContext(openInNewWindow); |
|
|
|
|
|
|
|
|
|
expect(getDataSourceSrv).toHaveBeenCalledTimes(1); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('then getDataSourceSrv.get should have been called with correct arguments', async () => { |
|
|
|
|
const { get, panel } = await getNavigateToExploreContext(openInNewWindow); |
|
|
|
|
|
|
|
|
|
expect(get).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(get).toHaveBeenCalledWith(panel.datasource); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('then getTimeSrv should have been called once', async () => { |
|
|
|
|
const { getTimeSrv } = await getNavigateToExploreContext(openInNewWindow); |
|
|
|
|
|
|
|
|
|
expect(getTimeSrv).toHaveBeenCalledTimes(1); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('then getExploreUrl should have been called with correct arguments', async () => { |
|
|
|
|
const { getExploreUrl, panel, datasource, getDataSourceSrv, getTimeSrv } = await getNavigateToExploreContext( |
|
|
|
|
openInNewWindow |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
expect(getExploreUrl).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(getExploreUrl).toHaveBeenCalledWith({ |
|
|
|
|
panel, |
|
|
|
|
panelTargets: panel.targets, |
|
|
|
|
panelDatasource: datasource, |
|
|
|
|
datasourceSrv: getDataSourceSrv(), |
|
|
|
|
timeSrv: getTimeSrv(), |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('then openInNewWindow should have been called with correct arguments', async () => { |
|
|
|
|
const openInNewWindowFunc = jest.fn(); |
|
|
|
|
const { url } = await getNavigateToExploreContext(openInNewWindowFunc); |
|
|
|
|
|
|
|
|
|
expect(openInNewWindowFunc).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(openInNewWindowFunc).toHaveBeenCalledWith(url); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|