grafana/public/app/features/api-keys/state/reducers.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

59 lines
1.7 KiB
TypeScript

import { reducerTester } from '../../../../test/core/redux/reducerTester';
import { ApiKeysState } from '../../../types';
import { getMultipleMockKeys } from '../__mocks__/apiKeysMock';
import {
apiKeysLoaded,
apiKeysReducer,
includeExpiredToggled,
initialApiKeysState,
isFetching,
setSearchQuery,
} from './reducers';
describe('API Keys reducer', () => {
it('should set keys', () => {
reducerTester<ApiKeysState>()
.givenReducer(apiKeysReducer, { ...initialApiKeysState })
.whenActionIsDispatched(
apiKeysLoaded({ keys: getMultipleMockKeys(4), keysIncludingExpired: getMultipleMockKeys(6) })
)
.thenStateShouldEqual({
...initialApiKeysState,
keys: getMultipleMockKeys(4),
keysIncludingExpired: getMultipleMockKeys(6),
hasFetched: true,
});
});
it('should set search query', () => {
reducerTester<ApiKeysState>()
.givenReducer(apiKeysReducer, { ...initialApiKeysState })
.whenActionIsDispatched(setSearchQuery('test query'))
.thenStateShouldEqual({
...initialApiKeysState,
searchQuery: 'test query',
});
});
it('should toggle the includeExpired state', () => {
reducerTester<ApiKeysState>()
.givenReducer(apiKeysReducer, { ...initialApiKeysState })
.whenActionIsDispatched(includeExpiredToggled())
.thenStateShouldEqual({
...initialApiKeysState,
includeExpired: true,
});
});
it('should set state when fetching', () => {
reducerTester<ApiKeysState>()
.givenReducer(apiKeysReducer, { ...initialApiKeysState })
.whenActionIsDispatched(isFetching())
.thenStateShouldEqual({
...initialApiKeysState,
hasFetched: false,
});
});
});