mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Chore: initial commit * Tests: fixes MetricsQueryEditor.test.tsx * Tests: fixes cloudwatch/specs/datasource.test.ts * Tests: fixes stackdriver/specs/datasource.test.ts * Tests: remove refrences to CustomVariable * Refactor: moves DefaultVariableQueryEditor * Refactor: moves utils * Refactor: moves types * Refactor: removes variableSrv * Refactor: removes feature toggle newVariables * Refactor: removes valueSelectDropDown * Chore: removes GeneralTabCtrl * Chore: migrates RowOptions * Refactor: adds RowOptionsButton * Refactor: makes the interface more explicit * Refactor: small changes * Refactor: changed type as it can be any variable type * Tests: fixes broken test * Refactor: changes after PR comments * Refactor: adds loading state and call to onChange in componentDidMount
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
import { variableAdapters } from '../adapters';
|
|
import { updateCustomVariableOptions } from './actions';
|
|
import { createCustomVariableAdapter } from './adapter';
|
|
import { reduxTester } from '../../../../test/core/redux/reduxTester';
|
|
import { getRootReducer } from '../state/helpers';
|
|
import { CustomVariableModel, VariableHide, VariableOption } from '../types';
|
|
import { toVariablePayload } from '../state/types';
|
|
import { addVariable, setCurrentVariableValue } from '../state/sharedReducer';
|
|
import { TemplatingState } from '../state/reducers';
|
|
import { createCustomOptionsFromQuery } from './reducer';
|
|
|
|
describe('custom actions', () => {
|
|
variableAdapters.setInit(() => [createCustomVariableAdapter()]);
|
|
|
|
describe('when updateCustomVariableOptions is dispatched', () => {
|
|
it('then correct actions are dispatched', async () => {
|
|
const option: VariableOption = {
|
|
value: 'A',
|
|
text: 'A',
|
|
selected: false,
|
|
};
|
|
|
|
const variable: CustomVariableModel = {
|
|
type: 'custom',
|
|
id: '0',
|
|
global: false,
|
|
current: {
|
|
value: '',
|
|
text: '',
|
|
selected: false,
|
|
},
|
|
options: [
|
|
{
|
|
text: 'A',
|
|
value: 'A',
|
|
selected: false,
|
|
},
|
|
{
|
|
text: 'B',
|
|
value: 'B',
|
|
selected: false,
|
|
},
|
|
],
|
|
query: 'A,B',
|
|
name: 'Custom',
|
|
label: '',
|
|
hide: VariableHide.dontHide,
|
|
skipUrlSync: false,
|
|
index: 0,
|
|
multi: true,
|
|
includeAll: false,
|
|
};
|
|
|
|
const tester = await reduxTester<{ templating: TemplatingState }>()
|
|
.givenRootReducer(getRootReducer())
|
|
.whenActionIsDispatched(addVariable(toVariablePayload(variable, { global: false, index: 0, model: variable })))
|
|
.whenAsyncActionIsDispatched(updateCustomVariableOptions(toVariablePayload(variable)), true);
|
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => {
|
|
const [createAction, setCurrentAction] = actions;
|
|
const expectedNumberOfActions = 2;
|
|
|
|
expect(createAction).toEqual(createCustomOptionsFromQuery(toVariablePayload(variable)));
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option })));
|
|
return actions.length === expectedNumberOfActions;
|
|
});
|
|
});
|
|
});
|
|
});
|