mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
Fixed tests
This commit is contained in:
@@ -3,8 +3,8 @@ import { configure, shallow } from "enzyme";
|
||||
import DeleteUserButton from "./DeleteUserButton";
|
||||
import Adapter from "enzyme-adapter-react-16";
|
||||
|
||||
import { confirmAlert } from '../../components/ConfirmAlert';
|
||||
jest.mock('../../components/ConfirmAlert');
|
||||
import { confirmAlert } from "../../components/ConfirmAlert";
|
||||
jest.mock("../../components/ConfirmAlert");
|
||||
|
||||
import "raf/polyfill";
|
||||
|
||||
@@ -15,7 +15,9 @@ it("should render nothing, if the delete link is missing", () => {
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const button = shallow(<DeleteUserButton user={user} deleteUser={() => {}} />);
|
||||
const button = shallow(
|
||||
<DeleteUserButton user={user} deleteUser={() => {}} />
|
||||
);
|
||||
expect(button.text()).toBe("");
|
||||
});
|
||||
|
||||
@@ -28,12 +30,13 @@ it("should render the button", () => {
|
||||
}
|
||||
};
|
||||
|
||||
const button = shallow(<DeleteUserButton user={user} deleteUser={() => {}} />);
|
||||
const button = shallow(
|
||||
<DeleteUserButton user={user} deleteUser={() => {}} />
|
||||
);
|
||||
expect(button.text()).not.toBe("");
|
||||
});
|
||||
|
||||
it("should open the confirm dialog on button click", () => {
|
||||
|
||||
const user = {
|
||||
_links: {
|
||||
delete: {
|
||||
@@ -42,7 +45,9 @@ it("should open the confirm dialog on button click", () => {
|
||||
}
|
||||
};
|
||||
|
||||
const button = shallow(<DeleteUserButton user={user} deleteUser={() => {}} />);
|
||||
const button = shallow(
|
||||
<DeleteUserButton user={user} deleteUser={() => {}} />
|
||||
);
|
||||
button.simulate("click");
|
||||
|
||||
expect(confirmAlert.mock.calls.length).toBe(1);
|
||||
@@ -58,11 +63,13 @@ it("should call the delete user function with delete url", () => {
|
||||
};
|
||||
|
||||
let calledUrl = null;
|
||||
function capture(url) {
|
||||
calledUrl = url;
|
||||
function capture(user) {
|
||||
calledUrl = user._links.delete.href;
|
||||
}
|
||||
|
||||
const button = shallow(<DeleteUserButton user={user} confirmDialog={false} deleteUser={capture} />);
|
||||
const button = shallow(
|
||||
<DeleteUserButton user={user} confirmDialog={false} deleteUser={capture} />
|
||||
);
|
||||
button.simulate("click");
|
||||
|
||||
expect(calledUrl).toBe("/users");
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
// @flow
|
||||
import {
|
||||
apiClient,
|
||||
NOT_FOUND_ERROR
|
||||
} from "../../apiclient";
|
||||
import type {
|
||||
User
|
||||
} from "../types/User";
|
||||
import type {
|
||||
UserEntry
|
||||
} from "../types/UserEntry";
|
||||
import {
|
||||
Dispatch
|
||||
} from "redux";
|
||||
import { apiClient, NOT_FOUND_ERROR } from "../../apiclient";
|
||||
import type { User } from "../types/User";
|
||||
import type { UserEntry } from "../types/UserEntry";
|
||||
import { Dispatch } from "redux";
|
||||
|
||||
export const FETCH_USERS = "scm/users/FETCH";
|
||||
export const FETCH_USERS_SUCCESS = "scm/users/FETCH_SUCCESS";
|
||||
@@ -58,7 +49,7 @@ function usersNotFound(url: string) {
|
||||
}
|
||||
|
||||
export function fetchUsers() {
|
||||
return function (dispatch: any) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(requestUsers());
|
||||
return apiClient
|
||||
.get(USERS_URL)
|
||||
@@ -98,7 +89,7 @@ function requestAddUser(user: User) {
|
||||
}
|
||||
|
||||
export function addUser(user: User) {
|
||||
return function (dispatch: Dispatch) {
|
||||
return function(dispatch: Dispatch) {
|
||||
dispatch(requestAddUser(user));
|
||||
return apiClient
|
||||
.postWithContentType(USERS_URL, user, CONTENT_TYPE_USER)
|
||||
@@ -132,7 +123,7 @@ function requestUpdateUser(user: User) {
|
||||
}
|
||||
|
||||
export function updateUser(user: User) {
|
||||
return function (dispatch: Dispatch) {
|
||||
return function(dispatch: Dispatch) {
|
||||
dispatch(requestUpdateUser(user));
|
||||
return apiClient
|
||||
.putWithContentType(user._links.update.href, user, CONTENT_TYPE_USER)
|
||||
@@ -182,9 +173,8 @@ export function deleteUserFailure(user: User, error: Error) {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function deleteUser(user: User) {
|
||||
return function (dispatch: any) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(requestDeleteUser(user));
|
||||
return apiClient
|
||||
.delete(user._links.delete.href)
|
||||
@@ -204,7 +194,7 @@ export function getUsersFromState(state) {
|
||||
if (!userNames) {
|
||||
return null;
|
||||
}
|
||||
var userEntries: Array < UserEntry > = [];
|
||||
const userEntries: Array<UserEntry> = [];
|
||||
|
||||
for (let userName of userNames) {
|
||||
userEntries.push(state.users.usersByNames[userName]);
|
||||
@@ -214,11 +204,11 @@ export function getUsersFromState(state) {
|
||||
}
|
||||
|
||||
function extractUsersByNames(
|
||||
users: Array < User > ,
|
||||
userNames: Array < string > ,
|
||||
users: Array<User>,
|
||||
userNames: Array<string>,
|
||||
oldUsersByNames: {}
|
||||
) {
|
||||
var usersByNames = {};
|
||||
const usersByNames = {};
|
||||
|
||||
for (let user of users) {
|
||||
usersByNames[user.name] = {
|
||||
@@ -226,7 +216,7 @@ function extractUsersByNames(
|
||||
};
|
||||
}
|
||||
|
||||
for (var userName in oldUsersByNames) {
|
||||
for (let userName in oldUsersByNames) {
|
||||
usersByNames[userName] = oldUsersByNames[userName];
|
||||
}
|
||||
return usersByNames;
|
||||
@@ -239,7 +229,11 @@ export function editUser(user: User) {
|
||||
};
|
||||
}
|
||||
|
||||
const reduceUsersByNames = (state: any, username: string, newUserState: any) => {
|
||||
const reduceUsersByNames = (
|
||||
state: any,
|
||||
username: string,
|
||||
newUserState: any
|
||||
) => {
|
||||
const newUsersByNames = {
|
||||
...state.usersByNames,
|
||||
[username]: newUserState
|
||||
|
||||
@@ -222,8 +222,8 @@ describe("fetch tests", () => {
|
||||
describe("reducer tests", () => {
|
||||
test("users request", () => {
|
||||
var newState = reducer({}, { type: FETCH_USERS });
|
||||
expect(newState.users.loading).toBeTruthy();
|
||||
expect(newState.users.error).toBeNull();
|
||||
expect(newState.loading).toBeTruthy();
|
||||
expect(newState.error).toBeNull();
|
||||
});
|
||||
|
||||
test("fetch users successful", () => {
|
||||
@@ -250,8 +250,8 @@ describe("reducer tests", () => {
|
||||
|
||||
test("delete user requested", () => {
|
||||
const state = {
|
||||
usersByNames : {
|
||||
"zaphod": {
|
||||
usersByNames: {
|
||||
zaphod: {
|
||||
loading: false,
|
||||
error: null,
|
||||
entry: userZaphod
|
||||
@@ -263,17 +263,17 @@ describe("reducer tests", () => {
|
||||
const zaphod = newState.usersByNames["zaphod"];
|
||||
expect(zaphod.loading).toBeTruthy();
|
||||
expect(zaphod.entry).toBe(userZaphod);
|
||||
})
|
||||
});
|
||||
|
||||
it("should not effect other users if one user will be deleted", () => {
|
||||
const state = {
|
||||
usersByNames : {
|
||||
"zaphod": {
|
||||
usersByNames: {
|
||||
zaphod: {
|
||||
loading: false,
|
||||
error: null,
|
||||
entry: userZaphod
|
||||
},
|
||||
"ford": {
|
||||
ford: {
|
||||
loading: false
|
||||
}
|
||||
}
|
||||
@@ -286,8 +286,8 @@ describe("reducer tests", () => {
|
||||
|
||||
it("should set the error of user which could not be deleted", () => {
|
||||
const state = {
|
||||
usersByNames : {
|
||||
"zaphod": {
|
||||
usersByNames: {
|
||||
zaphod: {
|
||||
loading: false,
|
||||
error: null,
|
||||
entry: userZaphod
|
||||
@@ -304,13 +304,13 @@ describe("reducer tests", () => {
|
||||
|
||||
it("should not effect other users if one user could not be deleted", () => {
|
||||
const state = {
|
||||
usersByNames : {
|
||||
"zaphod": {
|
||||
usersByNames: {
|
||||
zaphod: {
|
||||
loading: false,
|
||||
error: null,
|
||||
entry: userZaphod
|
||||
},
|
||||
"ford": {
|
||||
ford: {
|
||||
loading: false
|
||||
}
|
||||
}
|
||||
@@ -322,7 +322,6 @@ describe("reducer tests", () => {
|
||||
expect(ford.loading).toBeFalsy();
|
||||
});
|
||||
|
||||
|
||||
test("reducer does not replace whole usersByNames map", () => {
|
||||
const oldState = {
|
||||
usersByNames: {
|
||||
@@ -340,7 +339,6 @@ describe("reducer tests", () => {
|
||||
expect(newState.usersByNames["ford"]).toBeDefined();
|
||||
});
|
||||
|
||||
|
||||
test("edit user", () => {
|
||||
const newState = reducer(
|
||||
{},
|
||||
|
||||
Reference in New Issue
Block a user