mirror of
https://github.com/grafana/grafana.git
synced 2025-01-15 19:22:34 -06:00
4f0fa776be
* Refactor: Adds Redux Toolkit package * Refactor: Uses configureStore from Redux Toolkit * Refactor: Migrates applicationReducer * Refactor: Migrates appNotificationsReducer * Refactor: Migrates locationReducer * Refactor: Migrates navModelReducer * Refactor: Migrates teamsReducer and teamReducer * Refactor: Migrates cleanUpAction * Refactor: Migrates alertRulesReducer * Refactor: Cleans up recursiveCleanState * Refactor: Switched to Angular compatible reducers * Refactor: Migrates folderReducer * Refactor: Migrates dashboardReducer * Migrates panelEditorReducer * Refactor: Migrates dataSourcesReducer * Refactor: Migrates usersReducer * Refactor: Migrates organizationReducer * Refactor: Migrates pluginsReducer * Refactor: Migrates ldapReducer and ldapUserReducer * Refactor: Migrates apiKeysReducer * Refactor: Migrates exploreReducer and itemReducer * Refactor: Removes actionCreatorFactory and reducerFactory * Refactor: Moves mocks to test section * Docs: Removes sections about home grown framework * Update contribute/style-guides/redux.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Refactor: Cleans up some code * Refactor: Adds state typings * Refactor: Cleans up typings * Refactor: Adds comment about ImmerJs autoFreeze Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
import React from 'react';
|
|
import { shallow } from 'enzyme';
|
|
import { ApiKeysPage, Props } from './ApiKeysPage';
|
|
import { ApiKey } from 'app/types';
|
|
import { getMockKey, getMultipleMockKeys } from './__mocks__/apiKeysMock';
|
|
import { NavModel } from '@grafana/data';
|
|
import { setSearchQuery } from './state/reducers';
|
|
import { mockToolkitActionCreator } from '../../../test/core/redux/mocks';
|
|
|
|
const setup = (propOverrides?: object) => {
|
|
const props: Props = {
|
|
navModel: {
|
|
main: {
|
|
text: 'Configuration',
|
|
},
|
|
node: {
|
|
text: 'Api Keys',
|
|
},
|
|
} as NavModel,
|
|
apiKeys: [] as ApiKey[],
|
|
searchQuery: '',
|
|
hasFetched: false,
|
|
loadApiKeys: jest.fn(),
|
|
deleteApiKey: jest.fn(),
|
|
setSearchQuery: mockToolkitActionCreator(setSearchQuery),
|
|
addApiKey: jest.fn(),
|
|
apiKeysCount: 0,
|
|
includeExpired: false,
|
|
};
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
const wrapper = shallow(<ApiKeysPage {...props} />);
|
|
const instance = wrapper.instance() as ApiKeysPage;
|
|
|
|
return {
|
|
wrapper,
|
|
instance,
|
|
};
|
|
};
|
|
|
|
describe('Render', () => {
|
|
it('should render API keys table if there are any keys', () => {
|
|
const { wrapper } = setup({
|
|
apiKeys: getMultipleMockKeys(5),
|
|
apiKeysCount: 5,
|
|
});
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render CTA if there are no API keys', () => {
|
|
const { wrapper } = setup({
|
|
apiKeys: getMultipleMockKeys(0),
|
|
apiKeysCount: 0,
|
|
hasFetched: true,
|
|
});
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
});
|
|
|
|
describe('Life cycle', () => {
|
|
it('should call loadApiKeys', () => {
|
|
const { instance } = setup();
|
|
|
|
instance.componentDidMount();
|
|
|
|
expect(instance.props.loadApiKeys).toHaveBeenCalledWith(false);
|
|
});
|
|
});
|
|
|
|
describe('Functions', () => {
|
|
describe('Delete team', () => {
|
|
it('should call delete team', () => {
|
|
const { instance } = setup();
|
|
instance.onDeleteApiKey(getMockKey());
|
|
expect(instance.props.deleteApiKey).toHaveBeenCalledWith(1, false);
|
|
});
|
|
});
|
|
|
|
describe('on search query change', () => {
|
|
it('should call setSearchQuery', () => {
|
|
const { instance } = setup();
|
|
|
|
instance.onSearchQueryChange('test');
|
|
|
|
expect(instance.props.setSearchQuery).toHaveBeenCalledWith('test');
|
|
});
|
|
});
|
|
});
|