mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
Merged changes
This commit is contained in:
@@ -32,7 +32,10 @@
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^1.13.7"
|
||||
"enzyme": "^3.3.0",
|
||||
"enzyme-adapter-react-16": "^1.1.1",
|
||||
"prettier": "^1.13.7",
|
||||
"react-test-renderer": "^16.4.1"
|
||||
},
|
||||
"babel": {
|
||||
"presets": [
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//@flow
|
||||
|
||||
import { apiClient } from "../apiclient";
|
||||
import { isRegExp } from "util";
|
||||
|
||||
const LOGIN_URL = "/auth/access_token";
|
||||
const AUTHENTICATION_INFO_URL = "/me";
|
||||
@@ -22,7 +21,7 @@ export function getIsAuthenticatedRequest() {
|
||||
}
|
||||
|
||||
export function getIsAuthenticated() {
|
||||
return function(dispatch: any) {
|
||||
return function(dispatch: (any) => void) {
|
||||
dispatch(getIsAuthenticatedRequest());
|
||||
return apiClient
|
||||
.get(AUTHENTICATION_INFO_URL)
|
||||
@@ -61,9 +60,9 @@ export function login(username: string, password: string) {
|
||||
cookie: true,
|
||||
grant_type: "password",
|
||||
username,
|
||||
password
|
||||
password,
|
||||
};
|
||||
return function(dispatch: any) {
|
||||
return function(dispatch: (any) => void) {
|
||||
dispatch(loginRequest());
|
||||
return apiClient.post(LOGIN_URL, login_data).then(response => {
|
||||
if (response.ok) {
|
||||
|
||||
@@ -1,46 +1,36 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import { deleteUser } from '../modules/users';
|
||||
import {connect} from "react-redux";
|
||||
|
||||
type Props = {
|
||||
user: any,
|
||||
deleteUser: (username: string) => void
|
||||
deleteUser: (link: string) => void
|
||||
};
|
||||
|
||||
class DeleteUser extends React.Component<Props> {
|
||||
|
||||
deleteUser = () => {
|
||||
this.props.deleteUser(this.props.user.name);
|
||||
this.props.deleteUser(this.props.user._links.delete.href);
|
||||
};
|
||||
|
||||
if(deleteButtonClicked) {
|
||||
let deleteButtonAsk = <div>You really want to remove this user?</div>
|
||||
}
|
||||
|
||||
isDeletable = () => {
|
||||
return this.props.user._links.delete;
|
||||
};
|
||||
|
||||
render() {
|
||||
if(this.props.user._links.delete) {
|
||||
return (
|
||||
<button type="button" onClick={this.deleteUser}>
|
||||
Delete User
|
||||
</button>
|
||||
|
||||
);
|
||||
if (!this.isDeletable()) {
|
||||
return;
|
||||
}
|
||||
return (
|
||||
<button type="button" onClick={this.deleteUser}>
|
||||
Delete User
|
||||
</button>
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
users: state.users.users
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
deleteUser: (username: string) => {
|
||||
dispatch(deleteUser(username));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(DeleteUser);
|
||||
export default DeleteUser;
|
||||
|
||||
54
scm-ui/src/users/containers/DeleteUserButton.test.js
Normal file
54
scm-ui/src/users/containers/DeleteUserButton.test.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import React from 'react';
|
||||
import {configure, shallow} from 'enzyme';
|
||||
import DeleteUserButton from "./DeleteUserButton";
|
||||
import Adapter from 'enzyme-adapter-react-16';
|
||||
|
||||
import 'raf/polyfill';
|
||||
|
||||
configure({ adapter: new Adapter() });
|
||||
|
||||
it('should render nothing, if the delete link is missing', () => {
|
||||
|
||||
const user = {
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const button = shallow(<DeleteUserButton user={ user } />);
|
||||
expect(button.text()).toBe("");
|
||||
});
|
||||
|
||||
it('should render the button', () => {
|
||||
|
||||
const user = {
|
||||
_links: {
|
||||
"delete": {
|
||||
"href": "/users"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const button = shallow(<DeleteUserButton user={ user } />);
|
||||
expect(button.text()).not.toBe("");
|
||||
});
|
||||
|
||||
it('should call the delete user function with delete url', () => {
|
||||
|
||||
const user = {
|
||||
_links: {
|
||||
"delete": {
|
||||
"href": "/users"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let calledUrl = null;
|
||||
|
||||
function capture(url) {
|
||||
calledUrl = url;
|
||||
}
|
||||
|
||||
const button = shallow(<DeleteUserButton user={ user } deleteUser={ capture } />);
|
||||
button.simulate("click");
|
||||
|
||||
expect(calledUrl).toBe("/users");
|
||||
});
|
||||
Reference in New Issue
Block a user