delete team

This commit is contained in:
Peter Holmberg 2018-09-05 15:32:51 +02:00
parent 167f009819
commit 7e340b7aa5
3 changed files with 38 additions and 16 deletions

View File

@ -1,6 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import { TeamList, Props } from './TeamList';
import { Props, TeamList } from './TeamList';
import { NavModel, Team } from '../../types';
const setup = (propOverrides?: object) => {
@ -8,6 +8,7 @@ const setup = (propOverrides?: object) => {
navModel: {} as NavModel,
teams: [] as Team[],
loadTeams: jest.fn(),
deleteTeam: jest.fn(),
search: '',
};
@ -22,6 +23,17 @@ const setup = (propOverrides?: object) => {
};
};
const mockTeam: Team = {
id: 1,
name: 'test',
avatarUrl: 'some/url/',
email: 'test@test.com',
memberCount: 1,
search: '',
members: [],
groups: [],
};
describe('Render', () => {
it('should render component', () => {
const { wrapper } = setup();
@ -30,18 +42,7 @@ describe('Render', () => {
it('should render teams table', () => {
const { wrapper } = setup({
teams: [
{
id: 1,
name: 'test',
avatarUrl: 'some/url/',
email: 'test@test.com',
memberCount: 1,
search: '',
members: [],
groups: [],
},
],
teams: [mockTeam],
});
expect(wrapper).toMatchSnapshot();
@ -58,4 +59,13 @@ describe('Life cycle', () => {
});
});
describe('Functions', () => {});
describe('Functions', () => {
describe('Delete team', () => {
it('should call delete team', () => {
const { instance } = setup();
instance.deleteTeam(mockTeam);
expect(instance.props.deleteTeam).toHaveBeenCalledWith(1);
});
});
});

View File

@ -4,7 +4,7 @@ import { hot } from 'react-hot-loader';
import PageHeader from 'app/core/components/PageHeader/PageHeader';
import DeleteButton from 'app/core/components/DeleteButton/DeleteButton';
import { NavModel, Team } from '../../types';
import { loadTeams } from './state/actions';
import { loadTeams, deleteTeam } from './state/actions';
import { getTeams } from './state/selectors';
import { getNavModel } from 'app/core/selectors/navModel';
@ -12,6 +12,7 @@ export interface Props {
navModel: NavModel;
teams: Team[];
loadTeams: typeof loadTeams;
deleteTeam: typeof deleteTeam;
search: string;
}
@ -25,7 +26,7 @@ export class TeamList extends PureComponent<Props, any> {
}
deleteTeam = (team: Team) => {
console.log('delete team', team);
this.props.deleteTeam(team.id);
};
onSearchQueryChange = event => {
@ -116,6 +117,7 @@ function mapStateToProps(state) {
const mapDispatchToProps = {
loadTeams,
deleteTeam,
};
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(TeamList));

View File

@ -26,3 +26,13 @@ export function loadTeams(): ThunkResult<void> {
dispatch(teamsLoaded(response.teams));
};
}
export function deleteTeam(id: number): ThunkResult<void> {
return async dispatch => {
await getBackendSrv()
.delete(`/api/teams/${id}`)
.then(() => {
dispatch(loadTeams());
});
};
}