grafana/public/app/features/variables/textbox/reducer.test.ts
Hugo Häggmark dbec2b02fd
Variables: move state tree into a keyed state (#44642)
* Variables: move state tree into a keyed state

* Update public/app/features/variables/state/transactionReducer.ts

Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com>

* Chore: fix prettier error

* Chore: renamed slices and lastUid

* Chore: rename toUidAction

* Chore: rename dashboardVariableReducer

* Chore: rename state prop back to templating

* Chore renames variable.dashboardUid

* Chore: rename toDashboardVariableIdentifier

* Chore: rename getDashboardVariable

* Chore: rename getDashboardVariablesState

* Chore: rename getDashboardVariables

* Chore: some more renames

* Chore: small clean up

* Chore: small rename

* Chore: removes unused function

* Chore: rename VariableModel.stateKey

* Chore: rename KeyedVariableIdentifier.stateKey

* user essentials mob! 🔱

* user essentials mob! 🔱

* user essentials mob! 🔱

* user essentials mob! 🔱

Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com>
Co-authored-by: kay delaney <kay@grafana.com>
Co-authored-by: Alexandra Vargas <alexa1866@gmail.com>
Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
2022-02-18 06:06:04 +01:00

73 lines
2.4 KiB
TypeScript

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