mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add tests for the reducers & selectors for API keys #13411
This commit is contained in:
parent
32fb24f248
commit
a94662c8c7
@ -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>
|
||||
|
31
public/app/features/api-keys/state/reducers.test.ts
Normal file
31
public/app/features/api-keys/state/reducers.test.ts
Normal 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');
|
||||
});
|
||||
});
|
25
public/app/features/api-keys/state/selectors.test.ts
Normal file
25
public/app/features/api-keys/state/selectors.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user