Add tests for the reducers & selectors for API keys #13411

This commit is contained in:
Johannes Schill 2018-09-27 09:31:05 +02:00
parent 32fb24f248
commit a94662c8c7
3 changed files with 56 additions and 1 deletions

View File

@ -170,7 +170,6 @@ export class ApiKeysPage extends PureComponent<Props, any> {
{apiKeys.length > 0 ? (
<tbody>
{apiKeys.map(key => {
// id, name, role
return (
<tr key={key.id}>
<td>{key.name}</td>

View File

@ -0,0 +1,31 @@
import { Action, ActionTypes } from './actions';
import { initialApiKeysState, apiKeysReducer } from './reducers';
import { getMultipleMockKeys } from '../__mocks__/apiKeysMock';
describe('API Keys reducer', () => {
it('should set keys', () => {
const payload = getMultipleMockKeys(4);
const action: Action = {
type: ActionTypes.LoadApiKeys,
payload,
};
const result = apiKeysReducer(initialApiKeysState, action);
expect(result.keys).toEqual(payload);
});
it('should set search query', () => {
const payload = 'test query';
const action: Action = {
type: ActionTypes.SetApiKeysSearchQuery,
payload,
};
const result = apiKeysReducer(initialApiKeysState, action);
expect(result.searchQuery).toEqual('test query');
});
});

View File

@ -0,0 +1,25 @@
import { getApiKeys } from './selectors';
import { getMultipleMockKeys } from '../__mocks__/apiKeysMock';
import { ApiKeysState } from 'app/types';
describe('API Keys selectors', () => {
describe('Get API Keys', () => {
const mockKeys = getMultipleMockKeys(5);
it('should return all keys if no search query', () => {
const mockState: ApiKeysState = { keys: mockKeys, searchQuery: '' };
const keys = getApiKeys(mockState);
expect(keys).toEqual(mockKeys);
});
it('should filter keys if search query exists', () => {
const mockState: ApiKeysState = { keys: mockKeys, searchQuery: '5' };
const keys = getApiKeys(mockState);
expect(keys.length).toEqual(1);
});
});
});