@ -3,11 +3,11 @@ import { thunkTester } from 'test/core/thunk/thunkTester';
import { DataSourceInstanceSettings , ThresholdsMode } from '@grafana/data' ;
import { DataSourceInstanceSettings , ThresholdsMode } from '@grafana/data' ;
import { defaultDashboard , FieldColorModeId } from '@grafana/schema' ;
import { defaultDashboard , FieldColorModeId } from '@grafana/schema' ;
import {
import {
DashboardV2Spec ,
Spec as DashboardV2Spec ,
defaultDashboardV2Spec ,
defaultSpec as default DashboardV2Spec ,
defaultPanelSpec ,
defaultPanelSpec ,
defaultQueryVariableSpec ,
defaultQueryVariableSpec ,
} from '@grafana/schema/dist/esm/schema/dashboard/v2alpha0 ' ;
} from '@grafana/schema/dist/esm/schema/dashboard/v2alpha1/types.spec.gen ' ;
import { browseDashboardsAPI } from 'app/features/browse-dashboards/api/browseDashboardsAPI' ;
import { browseDashboardsAPI } from 'app/features/browse-dashboards/api/browseDashboardsAPI' ;
import { getLibraryPanel } from 'app/features/library-panels/state/api' ;
import { getLibraryPanel } from 'app/features/library-panels/state/api' ;
@ -16,7 +16,13 @@ import { LibraryElementDTO } from '../../library-panels/types';
import { DashboardJson } from '../types' ;
import { DashboardJson } from '../types' ;
import { validateDashboardJson } from '../utils/validation' ;
import { validateDashboardJson } from '../utils/validation' ;
import { getLibraryPanelInputs , importDashboard , processDashboard , processV2Datasources } from './actions' ;
import {
getLibraryPanelInputs ,
importDashboard ,
processDashboard ,
processV2DatasourceInput ,
processV2Datasources ,
} from './actions' ;
import { DataSourceInput , ImportDashboardDTO , initialImportDashboardState , InputType } from './reducers' ;
import { DataSourceInput , ImportDashboardDTO , initialImportDashboardState , InputType } from './reducers' ;
jest . mock ( 'app/features/library-panels/state/api' ) ;
jest . mock ( 'app/features/library-panels/state/api' ) ;
@ -29,7 +35,7 @@ jest.mock('@grafana/runtime', () => ({
getDataSourceSrv : ( ) = > ( {
getDataSourceSrv : ( ) = > ( {
. . . jest . requireActual ( '@grafana/runtime' ) . getDataSourceSrv ( ) ,
. . . jest . requireActual ( '@grafana/runtime' ) . getDataSourceSrv ( ) ,
get : jest . fn ( ) . mockImplementation ( ( dsType : { type : string } ) = > {
get : jest . fn ( ) . mockImplementation ( ( dsType : { type : string } ) = > {
const dsList : {
const dsListTypeDSMock : {
[ key : string ] : {
[ key : string ] : {
uid : string ;
uid : string ;
name : string ;
name : string ;
@ -55,8 +61,15 @@ jest.mock('@grafana/runtime', () => ({
type : 'grafana' ,
type : 'grafana' ,
meta : { id : 'grafana' } ,
meta : { id : 'grafana' } ,
} ,
} ,
// "datasource" type is what we call "--Dashboard--" datasource
datasource : {
uid : '--Dashboard--' ,
name : '--Dashboard--' ,
type : 'datasource' ,
meta : { id : 'dashboard' } ,
} ,
} ;
} ;
return dsList [ dsType . type ] ;
return dsListTypeDSMock [ dsType . type ] ;
} ) ,
} ) ,
} ) ,
} ) ,
} ) ) ;
} ) ) ;
@ -959,3 +972,43 @@ describe('processV2Datasources', () => {
) ;
) ;
} ) ;
} ) ;
} ) ;
} ) ;
describe ( 'processV2DatasourceInput' , ( ) = > {
// should not map grafana datasource input or dashboard datasource input
it ( 'Should not map grafana datasource input' , async ( ) = > {
const queryVariable = {
kind : 'QueryVariable' ,
spec : {
. . . defaultQueryVariableSpec ( ) ,
name : 'var2WithGrafanaDs' ,
query : {
kind : 'grafana' ,
spec : {
panelId : 2 ,
} ,
} ,
} ,
} ;
const result = await processV2DatasourceInput ( queryVariable . spec , { } ) ;
expect ( result ) . toEqual ( { } ) ;
} ) ;
it ( 'Should not map dashboard datasource input' , async ( ) = > {
// create a panel with dashboard datasource input
const panelQuery = {
kind : 'PanelQuery' ,
spec : {
refId : 'A' ,
hidden : false ,
query : {
kind : 'datasource' ,
spec : {
panelId : 2 ,
} ,
} ,
} ,
} ;
const result = await processV2DatasourceInput ( panelQuery . spec , { } ) ;
expect ( result ) . toEqual ( { } ) ;
} ) ;
} ) ;