mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 20:54:22 -06:00
delete team
This commit is contained in:
parent
167f009819
commit
7e340b7aa5
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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));
|
||||
|
@ -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());
|
||||
});
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user