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