2018-10-03 02:43:10 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { UsersListPage, Props } from './UsersListPage';
|
2019-04-30 09:46:46 -05:00
|
|
|
import { Invitee, OrgUser } from 'app/types';
|
2018-10-03 02:43:10 -05:00
|
|
|
import { getMockUser } from './__mocks__/userMocks';
|
|
|
|
import appEvents from '../../core/app_events';
|
2019-06-18 10:17:27 -05:00
|
|
|
import { NavModel } from '@grafana/data';
|
2018-10-03 02:43:10 -05:00
|
|
|
|
|
|
|
jest.mock('../../core/app_events', () => ({
|
|
|
|
emit: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
const setup = (propOverrides?: object) => {
|
|
|
|
const props: Props = {
|
2019-01-16 09:29:07 -06:00
|
|
|
navModel: {
|
|
|
|
main: {
|
2019-02-13 04:14:53 -06:00
|
|
|
text: 'Configuration',
|
2019-01-16 09:29:07 -06:00
|
|
|
},
|
|
|
|
node: {
|
2019-02-13 04:14:53 -06:00
|
|
|
text: 'Users',
|
|
|
|
},
|
2019-01-16 09:29:07 -06:00
|
|
|
} as NavModel,
|
2018-10-03 02:43:10 -05:00
|
|
|
users: [] as OrgUser[],
|
|
|
|
invitees: [] as Invitee[],
|
|
|
|
searchQuery: '',
|
|
|
|
externalUserMngInfo: '',
|
|
|
|
loadInvitees: jest.fn(),
|
|
|
|
loadUsers: jest.fn(),
|
|
|
|
updateUser: jest.fn(),
|
|
|
|
removeUser: jest.fn(),
|
|
|
|
setUsersSearchQuery: jest.fn(),
|
2018-10-11 04:49:34 -05:00
|
|
|
hasFetched: false,
|
2018-10-03 02:43:10 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
|
|
|
|
const wrapper = shallow(<UsersListPage {...props} />);
|
|
|
|
const instance = wrapper.instance() as UsersListPage;
|
|
|
|
|
|
|
|
return {
|
|
|
|
wrapper,
|
|
|
|
instance,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Render', () => {
|
|
|
|
it('should render component', () => {
|
|
|
|
const { wrapper } = setup();
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2018-10-11 04:49:34 -05:00
|
|
|
|
|
|
|
it('should render List page', () => {
|
|
|
|
const { wrapper } = setup({
|
|
|
|
hasFetched: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2018-10-03 02:43:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Functions', () => {
|
|
|
|
it('should emit show remove user modal', () => {
|
|
|
|
const { instance } = setup();
|
|
|
|
const mockUser = getMockUser();
|
|
|
|
|
|
|
|
instance.onRemoveUser(mockUser);
|
|
|
|
|
|
|
|
expect(appEvents.emit).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|