grafana/public/app/features/variables/textbox/reducer.test.ts
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

75 lines
2.4 KiB
TypeScript

import { cloneDeep } from 'lodash';
import { reducerTester } from '../../../../test/core/redux/reducerTester';
import { getVariableTestContext } from '../state/helpers';
import { VariablesState } from '../state/types';
import { TextBoxVariableModel } from '../types';
import { toVariablePayload } from '../utils';
import { createTextBoxVariableAdapter } from './adapter';
import { createTextBoxOptions, textBoxVariableReducer } from './reducer';
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,
});
});
});
});