mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
* Refactor: moves all the newVariables part to features/variables directory * Feature: adds datasource type * Tests: adds reducer tests * Tests: covers data source actions with tests * Chore: reduces strict null errors
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 '../../templating/variable';
|
|
import { createTextBoxVariableAdapter } from './adapter';
|
|
|
|
describe('textBoxVariableReducer', () => {
|
|
const adapter = createTextBoxVariableAdapter();
|
|
|
|
describe('when createTextBoxOptions is dispatched', () => {
|
|
it('then state should be correct', () => {
|
|
const query = 'ABC';
|
|
const uuid = '0';
|
|
const { initialState } = getVariableTestContext(adapter, { uuid, query });
|
|
const payload = toVariablePayload({ uuid: '0', type: 'textbox' });
|
|
|
|
reducerTester<VariablesState>()
|
|
.givenReducer(textBoxVariableReducer, cloneDeep(initialState))
|
|
.whenActionIsDispatched(createTextBoxOptions(payload))
|
|
.thenStateShouldEqual({
|
|
[uuid]: {
|
|
...initialState[uuid],
|
|
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 uuid = '0';
|
|
const { initialState } = getVariableTestContext(adapter, { uuid, query });
|
|
const payload = toVariablePayload({ uuid: '0', type: 'textbox' });
|
|
|
|
reducerTester<VariablesState>()
|
|
.givenReducer(textBoxVariableReducer, cloneDeep(initialState))
|
|
.whenActionIsDispatched(createTextBoxOptions(payload))
|
|
.thenStateShouldEqual({
|
|
[uuid]: {
|
|
...initialState[uuid],
|
|
options: [
|
|
{
|
|
text: query.trim(),
|
|
value: query.trim(),
|
|
selected: false,
|
|
},
|
|
],
|
|
current: {
|
|
text: query.trim(),
|
|
value: query.trim(),
|
|
selected: false,
|
|
},
|
|
} as TextBoxVariableModel,
|
|
});
|
|
});
|
|
});
|
|
});
|