2018-09-11 07:14:03 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { Props, TeamList } from './TeamList';
|
2020-01-13 01:03:22 -06:00
|
|
|
import { OrgRole, Team } from '../../types';
|
2018-09-11 07:14:03 -05:00
|
|
|
import { getMockTeam, getMultipleMockTeams } from './__mocks__/teamMocks';
|
2019-03-14 02:21:53 -05:00
|
|
|
import { User } from 'app/core/services/context_srv';
|
2019-06-18 10:17:27 -05:00
|
|
|
import { NavModel } from '@grafana/data';
|
2020-01-13 01:03:22 -06:00
|
|
|
import { mockToolkitActionCreator } from 'test/core/redux/mocks';
|
|
|
|
import { setSearchQuery } from './state/reducers';
|
2018-09-11 07:14:03 -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: 'Team List',
|
|
|
|
},
|
2019-01-16 09:29:07 -06:00
|
|
|
} as NavModel,
|
2018-09-11 07:14:03 -05:00
|
|
|
teams: [] as Team[],
|
|
|
|
loadTeams: jest.fn(),
|
|
|
|
deleteTeam: jest.fn(),
|
2020-01-13 01:03:22 -06:00
|
|
|
setSearchQuery: mockToolkitActionCreator(setSearchQuery),
|
2018-09-11 07:14:03 -05:00
|
|
|
searchQuery: '',
|
|
|
|
teamsCount: 0,
|
2018-10-11 04:49:34 -05:00
|
|
|
hasFetched: false,
|
2019-03-14 02:21:53 -05:00
|
|
|
editorsCanAdmin: false,
|
|
|
|
signedInUser: {
|
|
|
|
id: 1,
|
|
|
|
orgRole: OrgRole.Viewer,
|
|
|
|
} as User,
|
2018-09-11 07:14:03 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
|
|
|
|
const wrapper = shallow(<TeamList {...props} />);
|
|
|
|
const instance = wrapper.instance() as TeamList;
|
|
|
|
|
|
|
|
return {
|
|
|
|
wrapper,
|
|
|
|
instance,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Render', () => {
|
|
|
|
it('should render component', () => {
|
|
|
|
const { wrapper } = setup();
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render teams table', () => {
|
|
|
|
const { wrapper } = setup({
|
|
|
|
teams: getMultipleMockTeams(5),
|
|
|
|
teamsCount: 5,
|
2018-10-11 04:49:34 -05:00
|
|
|
hasFetched: true,
|
2018-09-11 07:14:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2019-03-14 02:21:53 -05:00
|
|
|
|
|
|
|
describe('when feature toggle editorsCanAdmin is turned on', () => {
|
|
|
|
describe('and signedin user is not viewer', () => {
|
|
|
|
it('should enable the new team button', () => {
|
|
|
|
const { wrapper } = setup({
|
|
|
|
teams: getMultipleMockTeams(1),
|
|
|
|
teamsCount: 1,
|
|
|
|
hasFetched: true,
|
|
|
|
editorsCanAdmin: true,
|
|
|
|
signedInUser: {
|
|
|
|
id: 1,
|
|
|
|
orgRole: OrgRole.Editor,
|
|
|
|
} as User,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('and signedin user is a viewer', () => {
|
|
|
|
it('should disable the new team button', () => {
|
|
|
|
const { wrapper } = setup({
|
|
|
|
teams: getMultipleMockTeams(1),
|
|
|
|
teamsCount: 1,
|
|
|
|
hasFetched: true,
|
|
|
|
editorsCanAdmin: true,
|
|
|
|
signedInUser: {
|
|
|
|
id: 1,
|
|
|
|
orgRole: OrgRole.Viewer,
|
|
|
|
} as User,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-09-11 07:14:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Life cycle', () => {
|
|
|
|
it('should call loadTeams', () => {
|
|
|
|
const { instance } = setup();
|
|
|
|
|
|
|
|
instance.componentDidMount();
|
|
|
|
|
|
|
|
expect(instance.props.loadTeams).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Functions', () => {
|
|
|
|
describe('Delete team', () => {
|
|
|
|
it('should call delete team', () => {
|
|
|
|
const { instance } = setup();
|
|
|
|
instance.deleteTeam(getMockTeam());
|
|
|
|
|
|
|
|
expect(instance.props.deleteTeam).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-11 07:14:03 -05:00
|
|
|
|
|
|
|
expect(instance.props.setSearchQuery).toHaveBeenCalledWith('test');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|