mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 09:05:45 -06:00
* Performance: Standardize lodash imports to use destructured members Changes lodash imports of the form `import x from 'lodash/x'` to `import { x } from 'lodash'` to reduce bundle size. * Remove unnecessary _ import from Graph component * Enforce lodash import style * Fix remaining lodash imports
62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
|
import { cloneDeep } from 'lodash';
|
|
import { getVariableTestContext } from '../state/helpers';
|
|
import { toVariablePayload, VariablesState } from '../state/types';
|
|
import { constantVariableReducer, createConstantOptionsFromQuery } from './reducer';
|
|
import { ConstantVariableModel } from '../types';
|
|
import { createConstantVariableAdapter } from './adapter';
|
|
|
|
describe('constantVariableReducer', () => {
|
|
const adapter = createConstantVariableAdapter();
|
|
|
|
describe('when createConstantOptionsFromQuery 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: 'constant' });
|
|
|
|
reducerTester<VariablesState>()
|
|
.givenReducer(constantVariableReducer, cloneDeep(initialState))
|
|
.whenActionIsDispatched(createConstantOptionsFromQuery(payload))
|
|
.thenStateShouldEqual({
|
|
[id]: {
|
|
...initialState[id],
|
|
options: [
|
|
{
|
|
text: query,
|
|
value: query,
|
|
selected: false,
|
|
},
|
|
],
|
|
} as ConstantVariableModel,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when createConstantOptionsFromQuery 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: 'constant' });
|
|
|
|
reducerTester<VariablesState>()
|
|
.givenReducer(constantVariableReducer, cloneDeep(initialState))
|
|
.whenActionIsDispatched(createConstantOptionsFromQuery(payload))
|
|
.thenStateShouldEqual({
|
|
[id]: {
|
|
...initialState[id],
|
|
options: [
|
|
{
|
|
text: query.trim(),
|
|
value: query.trim(),
|
|
selected: false,
|
|
},
|
|
],
|
|
} as ConstantVariableModel,
|
|
});
|
|
});
|
|
});
|
|
});
|