mirror of
https://github.com/grafana/grafana.git
synced 2025-02-03 12:11:09 -06:00
00a9af00fc
* 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
73 lines
2.4 KiB
TypeScript
73 lines
2.4 KiB
TypeScript
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
|
import cloneDeep from 'lodash/cloneDeep';
|
|
import { getVariableTestContext } from '../state/helpers';
|
|
import { toVariablePayload } from '../state/types';
|
|
import { createTextBoxOptions, textBoxVariableReducer } from './reducer';
|
|
import { VariablesState } from '../state/variablesReducer';
|
|
import { TextBoxVariableModel } from '../types';
|
|
import { createTextBoxVariableAdapter } from './adapter';
|
|
|
|
describe('textBoxVariableReducer', () => {
|
|
const adapter = createTextBoxVariableAdapter();
|
|
|
|
describe('when createTextBoxOptions is dispatched', () => {
|
|
it('then state should be correct', () => {
|
|
const query = 'ABC';
|
|
const id = '0';
|
|
const { initialState } = getVariableTestContext(adapter, { id, query });
|
|
const payload = toVariablePayload({ id: '0', type: 'textbox' });
|
|
|
|
reducerTester<VariablesState>()
|
|
.givenReducer(textBoxVariableReducer, cloneDeep(initialState))
|
|
.whenActionIsDispatched(createTextBoxOptions(payload))
|
|
.thenStateShouldEqual({
|
|
[id]: {
|
|
...initialState[id],
|
|
options: [
|
|
{
|
|
text: query,
|
|
value: query,
|
|
selected: false,
|
|
},
|
|
],
|
|
current: {
|
|
text: query,
|
|
value: query,
|
|
selected: false,
|
|
},
|
|
} as TextBoxVariableModel,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when createTextBoxOptions is dispatched and query contains spaces', () => {
|
|
it('then state should be correct', () => {
|
|
const query = ' ABC ';
|
|
const id = '0';
|
|
const { initialState } = getVariableTestContext(adapter, { id, query });
|
|
const payload = toVariablePayload({ id: '0', type: 'textbox' });
|
|
|
|
reducerTester<VariablesState>()
|
|
.givenReducer(textBoxVariableReducer, cloneDeep(initialState))
|
|
.whenActionIsDispatched(createTextBoxOptions(payload))
|
|
.thenStateShouldEqual({
|
|
[id]: {
|
|
...initialState[id],
|
|
options: [
|
|
{
|
|
text: query.trim(),
|
|
value: query.trim(),
|
|
selected: false,
|
|
},
|
|
],
|
|
current: {
|
|
text: query.trim(),
|
|
value: query.trim(),
|
|
selected: false,
|
|
},
|
|
} as TextBoxVariableModel,
|
|
});
|
|
});
|
|
});
|
|
});
|