mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
Merged changes
This commit is contained in:
@@ -32,7 +32,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"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": {
|
"babel": {
|
||||||
"presets": [
|
"presets": [
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
//@flow
|
//@flow
|
||||||
|
|
||||||
import { apiClient } from "../apiclient";
|
import { apiClient } from "../apiclient";
|
||||||
import { isRegExp } from "util";
|
|
||||||
|
|
||||||
const LOGIN_URL = "/auth/access_token";
|
const LOGIN_URL = "/auth/access_token";
|
||||||
const AUTHENTICATION_INFO_URL = "/me";
|
const AUTHENTICATION_INFO_URL = "/me";
|
||||||
@@ -22,7 +21,7 @@ export function getIsAuthenticatedRequest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getIsAuthenticated() {
|
export function getIsAuthenticated() {
|
||||||
return function(dispatch: any) {
|
return function(dispatch: (any) => void) {
|
||||||
dispatch(getIsAuthenticatedRequest());
|
dispatch(getIsAuthenticatedRequest());
|
||||||
return apiClient
|
return apiClient
|
||||||
.get(AUTHENTICATION_INFO_URL)
|
.get(AUTHENTICATION_INFO_URL)
|
||||||
@@ -61,9 +60,9 @@ export function login(username: string, password: string) {
|
|||||||
cookie: true,
|
cookie: true,
|
||||||
grant_type: "password",
|
grant_type: "password",
|
||||||
username,
|
username,
|
||||||
password
|
password,
|
||||||
};
|
};
|
||||||
return function(dispatch: any) {
|
return function(dispatch: (any) => void) {
|
||||||
dispatch(loginRequest());
|
dispatch(loginRequest());
|
||||||
return apiClient.post(LOGIN_URL, login_data).then(response => {
|
return apiClient.post(LOGIN_URL, login_data).then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
|||||||
@@ -1,46 +1,36 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { deleteUser } from '../modules/users';
|
|
||||||
import {connect} from "react-redux";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
user: any,
|
user: any,
|
||||||
deleteUser: (username: string) => void
|
deleteUser: (link: string) => void
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeleteUser extends React.Component<Props> {
|
class DeleteUser extends React.Component<Props> {
|
||||||
|
|
||||||
deleteUser = () => {
|
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() {
|
render() {
|
||||||
if(this.props.user._links.delete) {
|
if (!this.isDeletable()) {
|
||||||
return (
|
return;
|
||||||
<button type="button" onClick={this.deleteUser}>
|
|
||||||
Delete User
|
|
||||||
</button>
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
return (
|
||||||
|
<button type="button" onClick={this.deleteUser}>
|
||||||
|
Delete User
|
||||||
|
</button>
|
||||||
|
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
export default DeleteUser;
|
||||||
return {
|
|
||||||
users: state.users.users
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
|
||||||
return {
|
|
||||||
deleteUser: (username: string) => {
|
|
||||||
dispatch(deleteUser(username));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default connect(
|
|
||||||
mapStateToProps,
|
|
||||||
mapDispatchToProps
|
|
||||||
)(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