mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
merging heads
This commit is contained in:
4
scm-ui/jest.config.js
Normal file
4
scm-ui/jest.config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
collectCoverage: true,
|
||||
coverageFormats: ["json", "html"]
|
||||
};
|
||||
29
scm-ui/src/users/containers/EditUserButton.js
Normal file
29
scm-ui/src/users/containers/EditUserButton.js
Normal file
@@ -0,0 +1,29 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import type { User } from "../types/User";
|
||||
|
||||
type Props = {
|
||||
user: User,
|
||||
editUser: User => void
|
||||
};
|
||||
|
||||
type State = {};
|
||||
|
||||
class EditUserButton extends React.Component<Props, State> {
|
||||
render() {
|
||||
if (!this.isEditable()) {
|
||||
return "";
|
||||
}
|
||||
return (
|
||||
<button type="button" onClick={e => this.props.editUser(this.props.user)}>
|
||||
Edit user
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
isEditable = () => {
|
||||
return this.props.user._links.update;
|
||||
};
|
||||
}
|
||||
|
||||
export default EditUserButton;
|
||||
31
scm-ui/src/users/containers/EditUserButton.test.js
Normal file
31
scm-ui/src/users/containers/EditUserButton.test.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from "react";
|
||||
import { configure, shallow } from "enzyme";
|
||||
import EditUserButton from "./EditUserButton";
|
||||
import Adapter from "enzyme-adapter-react-16";
|
||||
|
||||
import "raf/polyfill";
|
||||
|
||||
configure({ adapter: new Adapter() });
|
||||
|
||||
it("should render nothing, if the edit link is missing", () => {
|
||||
const user = {
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const button = shallow(<EditUserButton user={user} />);
|
||||
expect(button.text()).toBe("");
|
||||
});
|
||||
|
||||
it("should render the button", () => {
|
||||
const user = {
|
||||
_links: {
|
||||
update: {
|
||||
href: "/users"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const button = shallow(<EditUserButton user={user} />);
|
||||
expect(button.text()).not.toBe("");
|
||||
});
|
||||
|
||||
@@ -182,6 +182,7 @@ export function deleteUserFailure(user: User, error: Error) {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function deleteUser(user: User) {
|
||||
return function (dispatch: any) {
|
||||
dispatch(requestDeleteUser(user));
|
||||
@@ -241,7 +242,7 @@ export function editUser(user: User) {
|
||||
const reduceUsersByNames = (state: any, username: string, newUserState: any) => {
|
||||
const newUsersByNames = {
|
||||
...state.usersByNames,
|
||||
[username] : newUserState
|
||||
[username]: newUserState
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -254,12 +255,8 @@ export default function reducer(state: any = {}, action: any = {}) {
|
||||
switch (action.type) {
|
||||
case FETCH_USERS:
|
||||
return {
|
||||
...state,
|
||||
users: {
|
||||
error: null,
|
||||
entries: null,
|
||||
loading: true
|
||||
}
|
||||
loading: true,
|
||||
error: null
|
||||
};
|
||||
case DELETE_USER:
|
||||
return reduceUsersByNames(state, action.payload.name, {
|
||||
@@ -287,11 +284,6 @@ export default function reducer(state: any = {}, action: any = {}) {
|
||||
};
|
||||
|
||||
case FETCH_USERS_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
loading: false
|
||||
};
|
||||
case DELETE_USER_FAILURE:
|
||||
return reduceUsersByNames(state, action.payload.user.name, {
|
||||
loading: false,
|
||||
|
||||
@@ -11,6 +11,10 @@ import {
|
||||
FETCH_USERS_SUCCESS,
|
||||
fetchUsers,
|
||||
FETCH_USERS_FAILURE,
|
||||
addUser,
|
||||
ADD_USER,
|
||||
ADD_USER_SUCCESS,
|
||||
ADD_USER_FAILURE,
|
||||
updateUser,
|
||||
UPDATE_USER,
|
||||
UPDATE_USER_FAILURE,
|
||||
@@ -160,6 +164,33 @@ describe("fetch tests", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("successful user add", () => {
|
||||
fetchMock.postOnce("/scm/api/rest/v2/users", {
|
||||
status: 204
|
||||
});
|
||||
|
||||
const store = mockStore({});
|
||||
return store.dispatch(addUser(userZaphod)).then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(ADD_USER);
|
||||
expect(actions[1].type).toEqual(ADD_USER_SUCCESS);
|
||||
});
|
||||
});
|
||||
|
||||
test("user add failed", () => {
|
||||
fetchMock.postOnce("/scm/api/rest/v2/users", {
|
||||
status: 500
|
||||
});
|
||||
|
||||
const store = mockStore({});
|
||||
return store.dispatch(addUser(userZaphod)).then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0].type).toEqual(ADD_USER);
|
||||
expect(actions[1].type).toEqual(ADD_USER_FAILURE);
|
||||
expect(actions[1].payload).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
test("successful user update", () => {
|
||||
fetchMock.putOnce("http://localhost:8081/scm/api/rest/v2/users/zaphod", {
|
||||
status: 204
|
||||
|
||||
7
scm-ui/src/users/types/UserEntry.js
Normal file
7
scm-ui/src/users/types/UserEntry.js
Normal file
@@ -0,0 +1,7 @@
|
||||
type UserEntry = {
|
||||
loading: boolean,
|
||||
error: Error,
|
||||
user: User
|
||||
};
|
||||
|
||||
export type UserEntry;
|
||||
Reference in New Issue
Block a user