mirror of
https://github.com/grafana/grafana.git
synced 2025-09-25 17:44:33 +08: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
67 lines
2.4 KiB
TypeScript
67 lines
2.4 KiB
TypeScript
import { reducerTester } from 'test/core/redux/reducerTester';
|
|
|
|
import { ElasticsearchQuery } from '../../types';
|
|
|
|
import { aliasPatternReducer, changeAliasPattern, changeQuery, initQuery, queryReducer } from './state';
|
|
|
|
describe('Query Reducer', () => {
|
|
describe('On Init', () => {
|
|
it('Should maintain the previous `query` if present', () => {
|
|
const initialQuery: ElasticsearchQuery['query'] = 'Some lucene query';
|
|
|
|
reducerTester<ElasticsearchQuery['query']>()
|
|
.givenReducer(queryReducer, initialQuery)
|
|
.whenActionIsDispatched(initQuery())
|
|
.thenStateShouldEqual(initialQuery);
|
|
});
|
|
|
|
it('Should set an empty `query` if it is not already set', () => {
|
|
const initialQuery: ElasticsearchQuery['query'] = undefined;
|
|
const expectedQuery = '';
|
|
|
|
reducerTester<ElasticsearchQuery['query']>()
|
|
.givenReducer(queryReducer, initialQuery)
|
|
.whenActionIsDispatched(initQuery())
|
|
.thenStateShouldEqual(expectedQuery);
|
|
});
|
|
});
|
|
|
|
it('Should correctly set `query`', () => {
|
|
const expectedQuery: ElasticsearchQuery['query'] = 'Some lucene query';
|
|
|
|
reducerTester<ElasticsearchQuery['query']>()
|
|
.givenReducer(queryReducer, '')
|
|
.whenActionIsDispatched(changeQuery(expectedQuery))
|
|
.thenStateShouldEqual(expectedQuery);
|
|
});
|
|
|
|
it('Should not change state with other action types', () => {
|
|
const initialState: ElasticsearchQuery['query'] = 'Some lucene query';
|
|
|
|
reducerTester<ElasticsearchQuery['query']>()
|
|
.givenReducer(queryReducer, initialState)
|
|
.whenActionIsDispatched({ type: 'THIS ACTION SHOULD NOT HAVE ANY EFFECT IN THIS REDUCER' })
|
|
.thenStateShouldEqual(initialState);
|
|
});
|
|
});
|
|
|
|
describe('Alias Pattern Reducer', () => {
|
|
it('Should correctly set `alias`', () => {
|
|
const expectedAlias: ElasticsearchQuery['alias'] = 'Some alias pattern';
|
|
|
|
reducerTester<ElasticsearchQuery['query']>()
|
|
.givenReducer(aliasPatternReducer, '')
|
|
.whenActionIsDispatched(changeAliasPattern(expectedAlias))
|
|
.thenStateShouldEqual(expectedAlias);
|
|
});
|
|
|
|
it('Should not change state with other action types', () => {
|
|
const initialState: ElasticsearchQuery['alias'] = 'Some alias pattern';
|
|
|
|
reducerTester<ElasticsearchQuery['query']>()
|
|
.givenReducer(aliasPatternReducer, initialState)
|
|
.whenActionIsDispatched({ type: 'THIS ACTION SHOULD NOT HAVE ANY EFFECT IN THIS REDUCER' })
|
|
.thenStateShouldEqual(initialState);
|
|
});
|
|
});
|