mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 09:33:34 -06:00
* 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
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import { cloneDeep } from 'lodash';
|
|
|
|
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
|
import { getVariableTestContext } from '../state/helpers';
|
|
import { VariablesState } from '../state/types';
|
|
import { ConstantVariableModel } from '../types';
|
|
import { toVariablePayload } from '../utils';
|
|
|
|
import { createConstantVariableAdapter } from './adapter';
|
|
import { constantVariableReducer, createConstantOptionsFromQuery } from './reducer';
|
|
|
|
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,
|
|
});
|
|
});
|
|
});
|
|
});
|