2018-10-10 18:17:00 -05:00
|
|
|
import React from 'react';
|
2018-09-26 07:58:27 -05:00
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { Props, ApiKeysPage } from './ApiKeysPage';
|
2019-04-30 09:46:46 -05:00
|
|
|
import { ApiKey } from 'app/types';
|
2018-09-26 07:58:27 -05:00
|
|
|
import { getMultipleMockKeys, getMockKey } from './__mocks__/apiKeysMock';
|
2019-06-18 10:17:27 -05:00
|
|
|
import { NavModel } from '@grafana/data';
|
2018-09-26 07:58:27 -05:00
|
|
|
|
|
|
|
const setup = (propOverrides?: object) => {
|
|
|
|
const props: Props = {
|
2019-01-16 09:29:07 -06:00
|
|
|
navModel: {
|
|
|
|
main: {
|
2019-02-12 01:03:43 -06:00
|
|
|
text: 'Configuration',
|
2019-01-16 09:29:07 -06:00
|
|
|
},
|
|
|
|
node: {
|
2019-02-12 01:03:43 -06:00
|
|
|
text: 'Api Keys',
|
|
|
|
},
|
2019-01-16 09:29:07 -06:00
|
|
|
} as NavModel,
|
2018-09-26 07:58:27 -05:00
|
|
|
apiKeys: [] as ApiKey[],
|
|
|
|
searchQuery: '',
|
2018-10-11 04:49:34 -05:00
|
|
|
hasFetched: false,
|
2018-09-26 07:58:27 -05:00
|
|
|
loadApiKeys: jest.fn(),
|
|
|
|
deleteApiKey: jest.fn(),
|
|
|
|
setSearchQuery: jest.fn(),
|
|
|
|
addApiKey: jest.fn(),
|
2018-10-10 18:17:00 -05:00
|
|
|
apiKeysCount: 0,
|
2018-09-26 07:58:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
|
|
|
|
const wrapper = shallow(<ApiKeysPage {...props} />);
|
|
|
|
const instance = wrapper.instance() as ApiKeysPage;
|
|
|
|
|
|
|
|
return {
|
|
|
|
wrapper,
|
|
|
|
instance,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Render', () => {
|
2018-10-10 18:17:00 -05:00
|
|
|
it('should render API keys table if there are any keys', () => {
|
|
|
|
const { wrapper } = setup({
|
|
|
|
apiKeys: getMultipleMockKeys(5),
|
|
|
|
apiKeysCount: 5,
|
|
|
|
});
|
|
|
|
|
2018-09-26 07:58:27 -05:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2018-10-11 04:56:32 -05:00
|
|
|
it('should render CTA if there are no API keys', () => {
|
2018-09-26 07:58:27 -05:00
|
|
|
const { wrapper } = setup({
|
2018-10-10 18:17:00 -05:00
|
|
|
apiKeys: getMultipleMockKeys(0),
|
|
|
|
apiKeysCount: 0,
|
2018-10-11 07:01:13 -05:00
|
|
|
hasFetched: true,
|
2018-09-26 07:58:27 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Life cycle', () => {
|
|
|
|
it('should call loadApiKeys', () => {
|
|
|
|
const { instance } = setup();
|
|
|
|
|
|
|
|
instance.componentDidMount();
|
|
|
|
|
|
|
|
expect(instance.props.loadApiKeys).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Functions', () => {
|
|
|
|
describe('Delete team', () => {
|
|
|
|
it('should call delete team', () => {
|
|
|
|
const { instance } = setup();
|
|
|
|
instance.onDeleteApiKey(getMockKey());
|
|
|
|
expect(instance.props.deleteApiKey).toHaveBeenCalledWith(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('on search query change', () => {
|
|
|
|
it('should call setSearchQuery', () => {
|
|
|
|
const { instance } = setup();
|
|
|
|
|
2019-02-12 01:03:43 -06:00
|
|
|
instance.onSearchQueryChange('test');
|
2018-09-26 07:58:27 -05:00
|
|
|
|
|
|
|
expect(instance.props.setSearchQuery).toHaveBeenCalledWith('test');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|