2020-04-20 00:37:38 -05:00
import { UrlQueryMap } from '@grafana/data' ;
2022-04-22 08:33:13 -05:00
import { setDataSourceSrv } from '@grafana/runtime' ;
2023-02-23 04:07:44 -06:00
import { DashboardModel } from 'app/features/dashboard/state' ;
import { DatasourceSrv } from 'app/features/plugins/datasource_srv' ;
2020-03-10 02:53:41 -05:00
2022-04-22 08:33:13 -05:00
import { reduxTester } from '../../../../test/core/redux/reduxTester' ;
2020-03-10 02:53:41 -05:00
import { variableAdapters } from '../adapters' ;
import { createCustomVariableAdapter } from '../custom/adapter' ;
2022-04-22 08:33:13 -05:00
import { setVariableQueryRunner , VariableQueryRunner } from '../query/VariableQueryRunner' ;
import { createQueryVariableAdapter } from '../query/adapter' ;
2020-03-10 02:53:41 -05:00
import { updateVariableOptions } from '../query/reducer' ;
2020-03-23 07:45:08 -05:00
import { customBuilder , queryBuilder } from '../shared/testing/builders' ;
2022-04-22 08:33:13 -05:00
import { VariableRefresh } from '../types' ;
2022-02-17 23:06:04 -06:00
import { toKeyedVariableIdentifier , toVariablePayload } from '../utils' ;
2020-03-23 07:45:08 -05:00
2022-04-22 08:33:13 -05:00
import { initDashboardTemplating , processVariable } from './actions' ;
import { getTemplatingRootReducer , TemplatingReducerType } from './helpers' ;
import { toKeyedAction } from './keyedVariablesReducer' ;
import { setCurrentVariableValue , variableStateCompleted , variableStateFetching } from './sharedReducer' ;
import { variablesInitTransaction } from './transactionReducer' ;
2020-03-10 02:53:41 -05:00
jest . mock ( 'app/features/dashboard/services/TimeSrv' , ( ) = > ( {
getTimeSrv : jest.fn ( ) . mockReturnValue ( {
timeRange : jest.fn ( ) . mockReturnValue ( {
from : '2001-01-01T01:00:00.000Z' ,
to : '2001-01-01T02:00:00.000Z' ,
raw : {
from : 'now-1h' ,
to : 'now' ,
} ,
} ) ,
} ) ,
} ) ) ;
2020-12-04 07:24:55 -06:00
setDataSourceSrv ( {
get : jest . fn ( ) . mockResolvedValue ( {
metricFindQuery : jest.fn ( ) . mockImplementation ( ( query , options ) = > {
if ( query === '$custom.*' ) {
return Promise . resolve ( [
{ value : 'AA' , text : 'AA' } ,
{ value : 'AB' , text : 'AB' } ,
{ value : 'AC' , text : 'AC' } ,
] ) ;
}
2020-03-10 02:53:41 -05:00
2020-12-04 07:24:55 -06:00
if ( query === '$custom.$queryDependsOnCustom.*' ) {
return Promise . resolve ( [
{ value : 'AAA' , text : 'AAA' } ,
{ value : 'AAB' , text : 'AAB' } ,
{ value : 'AAC' , text : 'AAC' } ,
] ) ;
}
2020-03-10 02:53:41 -05:00
2020-12-04 07:24:55 -06:00
if ( query === '*' ) {
return Promise . resolve ( [
{ value : 'A' , text : 'A' } ,
{ value : 'B' , text : 'B' } ,
{ value : 'C' , text : 'C' } ,
] ) ;
}
2020-03-10 02:53:41 -05:00
2020-12-04 07:24:55 -06:00
return Promise . resolve ( [ ] ) ;
2020-03-10 02:53:41 -05:00
} ) ,
} ) ,
2023-02-23 04:07:44 -06:00
} as unknown as DatasourceSrv ) ;
2020-03-10 02:53:41 -05:00
2020-03-23 09:33:17 -05:00
variableAdapters . setInit ( ( ) = > [ createCustomVariableAdapter ( ) , createQueryVariableAdapter ( ) ] ) ;
2020-03-10 02:53:41 -05:00
describe ( 'processVariable' , ( ) = > {
// these following processVariable tests will test the following base setup
// custom doesn't depend on any other variable
// queryDependsOnCustom depends on custom
// queryNoDepends doesn't depend on any other variable
2022-02-17 23:06:04 -06:00
const key = 'key' ;
const getTestContext = ( ) = > {
2020-03-23 07:45:08 -05:00
const custom = customBuilder ( )
. withId ( 'custom' )
2022-02-17 23:06:04 -06:00
. withRootStateKey ( key )
2020-03-23 07:45:08 -05:00
. withName ( 'custom' )
2020-03-10 02:53:41 -05:00
. withQuery ( 'A,B,C' )
. withOptions ( 'A' , 'B' , 'C' )
. withCurrent ( 'A' )
2020-03-23 03:00:36 -05:00
. build ( ) ;
2020-03-10 02:53:41 -05:00
2020-03-23 07:45:08 -05:00
const queryDependsOnCustom = queryBuilder ( )
. withId ( 'queryDependsOnCustom' )
2022-02-17 23:06:04 -06:00
. withRootStateKey ( key )
2020-03-10 02:53:41 -05:00
. withName ( 'queryDependsOnCustom' )
. withQuery ( '$custom.*' )
. withOptions ( 'AA' , 'AB' , 'AC' )
. withCurrent ( 'AA' )
2020-03-23 03:00:36 -05:00
. build ( ) ;
2020-03-10 02:53:41 -05:00
2020-03-23 07:45:08 -05:00
const queryNoDepends = queryBuilder ( )
. withId ( 'queryNoDepends' )
2022-02-17 23:06:04 -06:00
. withRootStateKey ( key )
2020-03-10 02:53:41 -05:00
. withName ( 'queryNoDepends' )
. withQuery ( '*' )
. withOptions ( 'A' , 'B' , 'C' )
. withCurrent ( 'A' )
2020-03-23 03:00:36 -05:00
. build ( ) ;
2020-03-10 02:53:41 -05:00
const list = [ custom , queryDependsOnCustom , queryNoDepends ] ;
2023-02-23 04:07:44 -06:00
const dashboard = { templating : { list } } as DashboardModel ;
2020-11-18 08:10:32 -06:00
setVariableQueryRunner ( new VariableQueryRunner ( ) ) ;
2020-03-10 02:53:41 -05:00
return {
2022-02-17 23:06:04 -06:00
key ,
2020-03-10 02:53:41 -05:00
custom ,
queryDependsOnCustom ,
queryNoDepends ,
2022-02-17 23:06:04 -06:00
dashboard ,
2020-03-10 02:53:41 -05:00
} ;
} ;
// testing processVariable for the custom variable from case described above
describe ( 'when processVariable is dispatched for a custom variable without dependencies' , ( ) = > {
describe ( 'and queryParams does not match variable' , ( ) = > {
it ( 'then correct actions are dispatched' , async ( ) = > {
2022-02-17 23:06:04 -06:00
const { key , dashboard , custom } = getTestContext ( ) ;
2020-03-10 02:53:41 -05:00
const queryParams : UrlQueryMap = { } ;
2022-02-17 23:06:04 -06:00
const tester = await reduxTester < TemplatingReducerType > ( )
2020-03-10 02:53:41 -05:00
. givenRootReducer ( getTemplatingRootReducer ( ) )
2022-02-17 23:06:04 -06:00
. whenActionIsDispatched ( toKeyedAction ( key , variablesInitTransaction ( { uid : key } ) ) )
. whenActionIsDispatched ( initDashboardTemplating ( key , dashboard ) )
. whenAsyncActionIsDispatched ( processVariable ( toKeyedVariableIdentifier ( custom ) , queryParams ) , true ) ;
2020-03-10 02:53:41 -05:00
2022-02-17 23:06:04 -06:00
await tester . thenDispatchedActionsShouldEqual (
toKeyedAction ( key , variableStateCompleted ( toVariablePayload ( custom ) ) )
) ;
2020-03-10 02:53:41 -05:00
} ) ;
} ) ;
describe ( 'and queryParams does match variable' , ( ) = > {
it ( 'then correct actions are dispatched' , async ( ) = > {
2022-02-17 23:06:04 -06:00
const { key , dashboard , custom } = getTestContext ( ) ;
2020-03-10 02:53:41 -05:00
const queryParams : UrlQueryMap = { 'var-custom' : 'B' } ;
2022-02-17 23:06:04 -06:00
const tester = await reduxTester < TemplatingReducerType > ( )
2020-03-10 02:53:41 -05:00
. givenRootReducer ( getTemplatingRootReducer ( ) )
2022-02-17 23:06:04 -06:00
. whenActionIsDispatched ( toKeyedAction ( key , variablesInitTransaction ( { uid : key } ) ) )
. whenActionIsDispatched ( initDashboardTemplating ( key , dashboard ) )
. whenAsyncActionIsDispatched ( processVariable ( toKeyedVariableIdentifier ( custom ) , queryParams ) , true ) ;
2020-03-10 02:53:41 -05:00
2020-03-16 07:45:51 -05:00
await tester . thenDispatchedActionsShouldEqual (
2022-02-17 23:06:04 -06:00
toKeyedAction (
key ,
setCurrentVariableValue (
toVariablePayload (
{ type : 'custom' , id : 'custom' } ,
{ option : { text : 'B' , value : 'B' , selected : false } }
)
)
2020-10-14 10:07:42 -05:00
) ,
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateCompleted ( toVariablePayload ( custom ) ) )
2020-03-10 02:53:41 -05:00
) ;
} ) ;
} ) ;
} ) ;
// testing processVariable for the queryNoDepends variable from case described above
describe ( 'when processVariable is dispatched for a query variable without dependencies' , ( ) = > {
describe ( 'and queryParams does not match variable' , ( ) = > {
const queryParams : UrlQueryMap = { } ;
describe ( 'and refresh is VariableRefresh.never' , ( ) = > {
const refresh = VariableRefresh . never ;
it ( 'then correct actions are dispatched' , async ( ) = > {
2022-02-17 23:06:04 -06:00
const { dashboard , key , queryNoDepends } = getTestContext ( ) ;
2020-03-10 02:53:41 -05:00
queryNoDepends . refresh = refresh ;
2022-02-17 23:06:04 -06:00
const tester = await reduxTester < TemplatingReducerType > ( )
2020-03-10 02:53:41 -05:00
. givenRootReducer ( getTemplatingRootReducer ( ) )
2022-02-17 23:06:04 -06:00
. whenActionIsDispatched ( toKeyedAction ( key , variablesInitTransaction ( { uid : key } ) ) )
. whenActionIsDispatched ( initDashboardTemplating ( key , dashboard ) )
. whenAsyncActionIsDispatched ( processVariable ( toKeyedVariableIdentifier ( queryNoDepends ) , queryParams ) , true ) ;
2020-03-10 02:53:41 -05:00
2022-02-17 23:06:04 -06:00
await tester . thenDispatchedActionsShouldEqual (
toKeyedAction ( key , variableStateCompleted ( toVariablePayload ( queryNoDepends ) ) )
) ;
2020-03-10 02:53:41 -05:00
} ) ;
} ) ;
2020-10-02 00:02:06 -05:00
it . each `
refresh
$ { VariableRefresh . onDashboardLoad }
$ { VariableRefresh . onTimeRangeChanged }
` ('and refresh is $ refresh then correct actions are dispatched', async ({ refresh }) => {
2022-02-17 23:06:04 -06:00
const { dashboard , key , queryNoDepends } = getTestContext ( ) ;
2020-10-02 00:02:06 -05:00
queryNoDepends . refresh = refresh ;
2022-02-17 23:06:04 -06:00
const tester = await reduxTester < TemplatingReducerType > ( )
2020-10-02 00:02:06 -05:00
. givenRootReducer ( getTemplatingRootReducer ( ) )
2022-02-17 23:06:04 -06:00
. whenActionIsDispatched ( toKeyedAction ( key , variablesInitTransaction ( { uid : key } ) ) )
. whenActionIsDispatched ( initDashboardTemplating ( key , dashboard ) )
. whenAsyncActionIsDispatched ( processVariable ( toKeyedVariableIdentifier ( queryNoDepends ) , queryParams ) , true ) ;
2020-10-02 00:02:06 -05:00
await tester . thenDispatchedActionsShouldEqual (
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateFetching ( toVariablePayload ( { type : 'query' , id : 'queryNoDepends' } ) ) ) ,
toKeyedAction (
key ,
updateVariableOptions (
toVariablePayload (
{ type : 'query' , id : 'queryNoDepends' } ,
{
results : [
{ value : 'A' , text : 'A' } ,
{ value : 'B' , text : 'B' } ,
{ value : 'C' , text : 'C' } ,
] ,
templatedRegex : '' ,
}
)
2020-10-02 00:02:06 -05:00
)
) ,
2022-02-17 23:06:04 -06:00
toKeyedAction (
key ,
setCurrentVariableValue (
toVariablePayload (
{ type : 'query' , id : 'queryNoDepends' } ,
{ option : { text : 'A' , value : 'A' , selected : false } }
)
2020-10-02 00:02:06 -05:00
)
) ,
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateCompleted ( toVariablePayload ( { type : 'query' , id : 'queryNoDepends' } ) ) )
2020-10-02 00:02:06 -05:00
) ;
2020-03-10 02:53:41 -05:00
} ) ;
} ) ;
describe ( 'and queryParams does match variable' , ( ) = > {
const queryParams : UrlQueryMap = { 'var-queryNoDepends' : 'B' } ;
describe ( 'and refresh is VariableRefresh.never' , ( ) = > {
const refresh = VariableRefresh . never ;
it ( 'then correct actions are dispatched' , async ( ) = > {
2022-02-17 23:06:04 -06:00
const { dashboard , key , queryNoDepends } = getTestContext ( ) ;
2020-03-10 02:53:41 -05:00
queryNoDepends . refresh = refresh ;
2022-02-17 23:06:04 -06:00
const tester = await reduxTester < TemplatingReducerType > ( )
2020-03-10 02:53:41 -05:00
. givenRootReducer ( getTemplatingRootReducer ( ) )
2022-02-17 23:06:04 -06:00
. whenActionIsDispatched ( toKeyedAction ( key , variablesInitTransaction ( { uid : key } ) ) )
. whenActionIsDispatched ( initDashboardTemplating ( key , dashboard ) )
. whenAsyncActionIsDispatched ( processVariable ( toKeyedVariableIdentifier ( queryNoDepends ) , queryParams ) , true ) ;
2020-03-10 02:53:41 -05:00
2020-03-16 07:45:51 -05:00
await tester . thenDispatchedActionsShouldEqual (
2022-02-17 23:06:04 -06:00
toKeyedAction (
key ,
setCurrentVariableValue (
toVariablePayload (
{ type : 'query' , id : 'queryNoDepends' } ,
{ option : { text : 'B' , value : 'B' , selected : false } }
)
2020-03-10 02:53:41 -05:00
)
2020-10-14 10:07:42 -05:00
) ,
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateCompleted ( toVariablePayload ( { type : 'query' , id : 'queryNoDepends' } ) ) )
2020-03-10 02:53:41 -05:00
) ;
} ) ;
} ) ;
2020-10-02 00:02:06 -05:00
it . each `
refresh
$ { VariableRefresh . onDashboardLoad }
$ { VariableRefresh . onTimeRangeChanged }
` ('and refresh is $ refresh then correct actions are dispatched', async ({ refresh }) => {
2022-02-17 23:06:04 -06:00
const { dashboard , key , queryNoDepends } = getTestContext ( ) ;
2020-10-02 00:02:06 -05:00
queryNoDepends . refresh = refresh ;
2022-02-17 23:06:04 -06:00
const tester = await reduxTester < TemplatingReducerType > ( )
2020-10-02 00:02:06 -05:00
. givenRootReducer ( getTemplatingRootReducer ( ) )
2022-02-17 23:06:04 -06:00
. whenActionIsDispatched ( toKeyedAction ( key , variablesInitTransaction ( { uid : key } ) ) )
. whenActionIsDispatched ( initDashboardTemplating ( key , dashboard ) )
. whenAsyncActionIsDispatched ( processVariable ( toKeyedVariableIdentifier ( queryNoDepends ) , queryParams ) , true ) ;
2020-10-02 00:02:06 -05:00
await tester . thenDispatchedActionsShouldEqual (
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateFetching ( toVariablePayload ( { type : 'query' , id : 'queryNoDepends' } ) ) ) ,
toKeyedAction (
key ,
updateVariableOptions (
toVariablePayload (
{ type : 'query' , id : 'queryNoDepends' } ,
{
results : [
{ value : 'A' , text : 'A' } ,
{ value : 'B' , text : 'B' } ,
{ value : 'C' , text : 'C' } ,
] ,
templatedRegex : '' ,
}
)
2020-10-02 00:02:06 -05:00
)
) ,
2022-02-17 23:06:04 -06:00
toKeyedAction (
key ,
setCurrentVariableValue (
toVariablePayload (
{ type : 'query' , id : 'queryNoDepends' } ,
{ option : { text : 'A' , value : 'A' , selected : false } }
)
2020-10-02 00:02:06 -05:00
)
) ,
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateCompleted ( toVariablePayload ( { type : 'query' , id : 'queryNoDepends' } ) ) ) ,
toKeyedAction (
key ,
setCurrentVariableValue (
toVariablePayload (
{ type : 'query' , id : 'queryNoDepends' } ,
{ option : { text : 'B' , value : 'B' , selected : false } }
)
2020-10-02 00:02:06 -05:00
)
)
) ;
2020-03-10 02:53:41 -05:00
} ) ;
} ) ;
} ) ;
// testing processVariable for the queryDependsOnCustom variable from case described above
describe ( 'when processVariable is dispatched for a query variable with one dependency' , ( ) = > {
describe ( 'and queryParams does not match variable' , ( ) = > {
const queryParams : UrlQueryMap = { } ;
describe ( 'and refresh is VariableRefresh.never' , ( ) = > {
const refresh = VariableRefresh . never ;
it ( 'then correct actions are dispatched' , async ( ) = > {
2022-02-17 23:06:04 -06:00
const { key , dashboard , custom , queryDependsOnCustom } = getTestContext ( ) ;
2020-03-10 02:53:41 -05:00
queryDependsOnCustom . refresh = refresh ;
2022-02-17 23:06:04 -06:00
const customProcessed = await reduxTester < TemplatingReducerType > ( )
2020-03-10 02:53:41 -05:00
. givenRootReducer ( getTemplatingRootReducer ( ) )
2022-02-17 23:06:04 -06:00
. whenActionIsDispatched ( toKeyedAction ( key , variablesInitTransaction ( { uid : key } ) ) )
. whenActionIsDispatched ( initDashboardTemplating ( key , dashboard ) )
. whenAsyncActionIsDispatched ( processVariable ( toKeyedVariableIdentifier ( custom ) , queryParams ) ) ; // Need to process this dependency otherwise we never complete the promise chain
2020-03-10 02:53:41 -05:00
const tester = await customProcessed . whenAsyncActionIsDispatched (
2022-02-17 23:06:04 -06:00
processVariable ( toKeyedVariableIdentifier ( queryDependsOnCustom ) , queryParams ) ,
2020-03-10 02:53:41 -05:00
true
) ;
2020-03-16 07:45:51 -05:00
await tester . thenDispatchedActionsShouldEqual (
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateCompleted ( toVariablePayload ( { type : 'query' , id : 'queryDependsOnCustom' } ) ) )
2020-03-10 02:53:41 -05:00
) ;
} ) ;
} ) ;
2020-10-02 00:02:06 -05:00
it . each `
refresh
$ { VariableRefresh . onDashboardLoad }
$ { VariableRefresh . onTimeRangeChanged }
` ('and refresh is $ refresh then correct actions are dispatched', async ({ refresh }) => {
2022-02-17 23:06:04 -06:00
const { key , dashboard , custom , queryDependsOnCustom } = getTestContext ( ) ;
2020-10-02 00:02:06 -05:00
queryDependsOnCustom . refresh = refresh ;
2022-02-17 23:06:04 -06:00
const customProcessed = await reduxTester < TemplatingReducerType > ( )
2020-10-02 00:02:06 -05:00
. givenRootReducer ( getTemplatingRootReducer ( ) )
2022-02-17 23:06:04 -06:00
. whenActionIsDispatched ( toKeyedAction ( key , variablesInitTransaction ( { uid : key } ) ) )
. whenActionIsDispatched ( initDashboardTemplating ( key , dashboard ) )
. whenAsyncActionIsDispatched ( processVariable ( toKeyedVariableIdentifier ( custom ) , queryParams ) ) ; // Need to process this dependency otherwise we never complete the promise chain
2020-10-02 00:02:06 -05:00
const tester = await customProcessed . whenAsyncActionIsDispatched (
2022-02-17 23:06:04 -06:00
processVariable ( toKeyedVariableIdentifier ( queryDependsOnCustom ) , queryParams ) ,
2020-10-02 00:02:06 -05:00
true
) ;
await tester . thenDispatchedActionsShouldEqual (
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateFetching ( toVariablePayload ( { type : 'query' , id : 'queryDependsOnCustom' } ) ) ) ,
toKeyedAction (
key ,
updateVariableOptions (
toVariablePayload (
{ type : 'query' , id : 'queryDependsOnCustom' } ,
{
results : [
{ value : 'AA' , text : 'AA' } ,
{ value : 'AB' , text : 'AB' } ,
{ value : 'AC' , text : 'AC' } ,
] ,
templatedRegex : '' ,
}
)
2020-10-02 00:02:06 -05:00
)
) ,
2022-02-17 23:06:04 -06:00
toKeyedAction (
key ,
setCurrentVariableValue (
toVariablePayload (
{ type : 'query' , id : 'queryDependsOnCustom' } ,
{ option : { text : 'AA' , value : 'AA' , selected : false } }
)
2020-10-02 00:02:06 -05:00
)
) ,
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateCompleted ( toVariablePayload ( { type : 'query' , id : 'queryDependsOnCustom' } ) ) )
2020-10-02 00:02:06 -05:00
) ;
2020-03-10 02:53:41 -05:00
} ) ;
} ) ;
describe ( 'and queryParams does match variable' , ( ) = > {
const queryParams : UrlQueryMap = { 'var-queryDependsOnCustom' : 'AB' } ;
describe ( 'and refresh is VariableRefresh.never' , ( ) = > {
const refresh = VariableRefresh . never ;
it ( 'then correct actions are dispatched' , async ( ) = > {
2022-02-17 23:06:04 -06:00
const { key , dashboard , custom , queryDependsOnCustom } = getTestContext ( ) ;
2020-03-10 02:53:41 -05:00
queryDependsOnCustom . refresh = refresh ;
2022-02-17 23:06:04 -06:00
const customProcessed = await reduxTester < TemplatingReducerType > ( )
2020-03-10 02:53:41 -05:00
. givenRootReducer ( getTemplatingRootReducer ( ) )
2022-02-17 23:06:04 -06:00
. whenActionIsDispatched ( toKeyedAction ( key , variablesInitTransaction ( { uid : key } ) ) )
. whenActionIsDispatched ( initDashboardTemplating ( key , dashboard ) )
. whenAsyncActionIsDispatched ( processVariable ( toKeyedVariableIdentifier ( custom ) , queryParams ) ) ; // Need to process this dependency otherwise we never complete the promise chain
2020-03-10 02:53:41 -05:00
const tester = await customProcessed . whenAsyncActionIsDispatched (
2022-02-17 23:06:04 -06:00
processVariable ( toKeyedVariableIdentifier ( queryDependsOnCustom ) , queryParams ) ,
2020-03-10 02:53:41 -05:00
true
) ;
2020-03-16 07:45:51 -05:00
await tester . thenDispatchedActionsShouldEqual (
2022-02-17 23:06:04 -06:00
toKeyedAction (
key ,
setCurrentVariableValue (
toVariablePayload (
{ type : 'query' , id : 'queryDependsOnCustom' } ,
{ option : { text : 'AB' , value : 'AB' , selected : false } }
)
2020-03-10 02:53:41 -05:00
)
2020-10-14 10:07:42 -05:00
) ,
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateCompleted ( toVariablePayload ( { type : 'query' , id : 'queryDependsOnCustom' } ) ) )
2020-03-10 02:53:41 -05:00
) ;
} ) ;
} ) ;
2020-10-02 00:02:06 -05:00
it . each `
refresh
$ { VariableRefresh . onDashboardLoad }
$ { VariableRefresh . onTimeRangeChanged }
` ('and refresh is $ refresh then correct actions are dispatched', async ({ refresh }) => {
2022-02-17 23:06:04 -06:00
const { key , dashboard , custom , queryDependsOnCustom } = getTestContext ( ) ;
2020-10-02 00:02:06 -05:00
queryDependsOnCustom . refresh = refresh ;
2022-02-17 23:06:04 -06:00
const customProcessed = await reduxTester < TemplatingReducerType > ( )
2020-10-02 00:02:06 -05:00
. givenRootReducer ( getTemplatingRootReducer ( ) )
2022-02-17 23:06:04 -06:00
. whenActionIsDispatched ( toKeyedAction ( key , variablesInitTransaction ( { uid : key } ) ) )
. whenActionIsDispatched ( initDashboardTemplating ( key , dashboard ) )
. whenAsyncActionIsDispatched ( processVariable ( toKeyedVariableIdentifier ( custom ) , queryParams ) ) ; // Need to process this dependency otherwise we never complete the promise chain
2020-10-02 00:02:06 -05:00
const tester = await customProcessed . whenAsyncActionIsDispatched (
2022-02-17 23:06:04 -06:00
processVariable ( toKeyedVariableIdentifier ( queryDependsOnCustom ) , queryParams ) ,
2020-10-02 00:02:06 -05:00
true
) ;
await tester . thenDispatchedActionsShouldEqual (
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateFetching ( toVariablePayload ( { type : 'query' , id : 'queryDependsOnCustom' } ) ) ) ,
toKeyedAction (
key ,
updateVariableOptions (
toVariablePayload (
{ type : 'query' , id : 'queryDependsOnCustom' } ,
{
results : [
{ value : 'AA' , text : 'AA' } ,
{ value : 'AB' , text : 'AB' } ,
{ value : 'AC' , text : 'AC' } ,
] ,
templatedRegex : '' ,
}
)
2020-10-02 00:02:06 -05:00
)
) ,
2022-02-17 23:06:04 -06:00
toKeyedAction (
key ,
setCurrentVariableValue (
toVariablePayload (
{ type : 'query' , id : 'queryDependsOnCustom' } ,
{ option : { text : 'AA' , value : 'AA' , selected : false } }
)
2020-10-02 00:02:06 -05:00
)
) ,
2022-02-17 23:06:04 -06:00
toKeyedAction ( key , variableStateCompleted ( toVariablePayload ( { type : 'query' , id : 'queryDependsOnCustom' } ) ) ) ,
toKeyedAction (
key ,
setCurrentVariableValue (
toVariablePayload (
{ type : 'query' , id : 'queryDependsOnCustom' } ,
{ option : { text : 'AB' , value : 'AB' , selected : false } }
)
2020-10-02 00:02:06 -05:00
)
)
) ;
2020-03-10 02:53:41 -05:00
} ) ;
} ) ;
} ) ;
} ) ;