mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
fixed warnings on test execution
This commit is contained in:
13
scm-ui/src/tests/enzyme.js
Normal file
13
scm-ui/src/tests/enzyme.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import "raf/polyfill";
|
||||||
|
|
||||||
|
// Temporary hack to suppress error
|
||||||
|
// https://github.com/facebook/create-react-app/issues/3199#issuecomment-345024029
|
||||||
|
window.requestAnimationFrame = function(callback) {
|
||||||
|
setTimeout(callback, 0);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
import { configure } from "enzyme";
|
||||||
|
import Adapter from "enzyme-adapter-react-16";
|
||||||
|
|
||||||
|
configure({ adapter: new Adapter() });
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { configure, mount, shallow } from "enzyme";
|
import { mount, shallow } from "enzyme";
|
||||||
|
import "../../tests/enzyme";
|
||||||
import DeleteUserButton from "./DeleteUserButton";
|
import DeleteUserButton from "./DeleteUserButton";
|
||||||
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";
|
|
||||||
|
|
||||||
configure({ adapter: new Adapter() });
|
|
||||||
|
|
||||||
describe("DeleteUserButton", () => {
|
describe("DeleteUserButton", () => {
|
||||||
it("should render nothing, if the delete link is missing", () => {
|
it("should render nothing, if the delete link is missing", () => {
|
||||||
const entry = {
|
const entry = {
|
||||||
@@ -38,9 +34,6 @@ describe("DeleteUserButton", () => {
|
|||||||
const button = mount(
|
const button = mount(
|
||||||
<DeleteUserButton entry={entry} deleteUser={() => {}} />
|
<DeleteUserButton entry={entry} deleteUser={() => {}} />
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(button);
|
|
||||||
|
|
||||||
expect(button.text()).not.toBe("");
|
expect(button.text()).not.toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { configure, shallow } from "enzyme";
|
import { configure, shallow } from "enzyme";
|
||||||
|
import "../../tests/enzyme";
|
||||||
import EditUserButton from "./EditUserButton";
|
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", () => {
|
it("should render nothing, if the edit link is missing", () => {
|
||||||
const entry = {
|
const entry = {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
getUsersFromState
|
getUsersFromState
|
||||||
} from "../modules/users";
|
} from "../modules/users";
|
||||||
import Loading from "../../components/Loading";
|
import Loading from "../../components/Loading";
|
||||||
|
import ErrorNotification from "../../components/ErrorNotification";
|
||||||
import UserForm from "./UserForm";
|
import UserForm from "./UserForm";
|
||||||
import UserTable from "./UserTable";
|
import UserTable from "./UserTable";
|
||||||
import type { User } from "../types/User";
|
import type { User } from "../types/User";
|
||||||
@@ -68,10 +69,11 @@ class Users extends React.Component<Props, User> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderContent() {
|
renderContent() {
|
||||||
const { userEntries, deleteUser, editUser, userToEdit } = this.props;
|
const { userEntries, deleteUser, editUser, userToEdit, error } = this.props;
|
||||||
if (userEntries) {
|
if (userEntries) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
<ErrorNotification error={error} />
|
||||||
<UserTable
|
<UserTable
|
||||||
entries={userEntries}
|
entries={userEntries}
|
||||||
deleteUser={deleteUser}
|
deleteUser={deleteUser}
|
||||||
@@ -97,7 +99,8 @@ const mapStateToProps = state => {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
userEntries,
|
userEntries,
|
||||||
userToEdit
|
userToEdit,
|
||||||
|
error: state.users.error
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import React from "react";
|
|
||||||
import { configure, shallow } from "enzyme";
|
|
||||||
import Adapter from "enzyme-adapter-react-16";
|
|
||||||
import configureMockStore from "redux-mock-store";
|
import configureMockStore from "redux-mock-store";
|
||||||
import thunk from "redux-thunk";
|
import thunk from "redux-thunk";
|
||||||
import fetchMock from "fetch-mock";
|
import fetchMock from "fetch-mock";
|
||||||
@@ -21,15 +18,15 @@ import {
|
|||||||
UPDATE_USER_SUCCESS,
|
UPDATE_USER_SUCCESS,
|
||||||
EDIT_USER,
|
EDIT_USER,
|
||||||
requestDeleteUser,
|
requestDeleteUser,
|
||||||
deleteUserFailure
|
deleteUserFailure,
|
||||||
|
DELETE_USER,
|
||||||
|
DELETE_USER_SUCCESS,
|
||||||
|
DELETE_USER_FAILURE,
|
||||||
|
deleteUser
|
||||||
} from "./users";
|
} from "./users";
|
||||||
|
|
||||||
import reducer from "./users";
|
import reducer from "./users";
|
||||||
|
|
||||||
import "raf/polyfill";
|
|
||||||
|
|
||||||
configure({ adapter: new Adapter() });
|
|
||||||
|
|
||||||
const userZaphod = {
|
const userZaphod = {
|
||||||
active: true,
|
active: true,
|
||||||
admin: true,
|
admin: true,
|
||||||
@@ -165,15 +162,20 @@ describe("users fetch()", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should add a user successfully", () => {
|
it("should add a user successfully", () => {
|
||||||
|
// unmatched
|
||||||
fetchMock.postOnce("/scm/api/rest/v2/users", {
|
fetchMock.postOnce("/scm/api/rest/v2/users", {
|
||||||
status: 204
|
status: 204
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// after create, the users are fetched again
|
||||||
|
fetchMock.getOnce("/scm/api/rest/v2/users", response);
|
||||||
|
|
||||||
const store = mockStore({});
|
const store = mockStore({});
|
||||||
return store.dispatch(addUser(userZaphod)).then(() => {
|
return store.dispatch(addUser(userZaphod)).then(() => {
|
||||||
const actions = store.getActions();
|
const actions = store.getActions();
|
||||||
expect(actions[0].type).toEqual(ADD_USER);
|
expect(actions[0].type).toEqual(ADD_USER);
|
||||||
expect(actions[1].type).toEqual(ADD_USER_SUCCESS);
|
expect(actions[1].type).toEqual(ADD_USER_SUCCESS);
|
||||||
|
expect(actions[2].type).toEqual(FETCH_USERS);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -195,12 +197,15 @@ describe("users fetch()", () => {
|
|||||||
fetchMock.putOnce("http://localhost:8081/scm/api/rest/v2/users/zaphod", {
|
fetchMock.putOnce("http://localhost:8081/scm/api/rest/v2/users/zaphod", {
|
||||||
status: 204
|
status: 204
|
||||||
});
|
});
|
||||||
|
// after update, the users are fetched again
|
||||||
|
fetchMock.getOnce("/scm/api/rest/v2/users", response);
|
||||||
|
|
||||||
const store = mockStore({});
|
const store = mockStore({});
|
||||||
return store.dispatch(updateUser(userZaphod)).then(() => {
|
return store.dispatch(updateUser(userZaphod)).then(() => {
|
||||||
const actions = store.getActions();
|
const actions = store.getActions();
|
||||||
expect(actions[0].type).toEqual(UPDATE_USER);
|
expect(actions[0].type).toEqual(UPDATE_USER);
|
||||||
expect(actions[1].type).toEqual(UPDATE_USER_SUCCESS);
|
expect(actions[1].type).toEqual(UPDATE_USER_SUCCESS);
|
||||||
|
expect(actions[2].type).toEqual(FETCH_USERS);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -217,6 +222,38 @@ describe("users fetch()", () => {
|
|||||||
expect(actions[1].payload).toBeDefined();
|
expect(actions[1].payload).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should delete successfully user zaphod", () => {
|
||||||
|
fetchMock.deleteOnce("http://localhost:8081/scm/api/rest/v2/users/zaphod", {
|
||||||
|
status: 204
|
||||||
|
});
|
||||||
|
// after update, the users are fetched again
|
||||||
|
fetchMock.getOnce("/scm/api/rest/v2/users", response);
|
||||||
|
|
||||||
|
const store = mockStore({});
|
||||||
|
return store.dispatch(deleteUser(userZaphod)).then(() => {
|
||||||
|
const actions = store.getActions();
|
||||||
|
expect(actions[0].type).toEqual(DELETE_USER);
|
||||||
|
expect(actions[0].payload).toBe(userZaphod);
|
||||||
|
expect(actions[1].type).toEqual(DELETE_USER_SUCCESS);
|
||||||
|
expect(actions[2].type).toEqual(FETCH_USERS);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should fail to delete user zaphod", () => {
|
||||||
|
fetchMock.deleteOnce("http://localhost:8081/scm/api/rest/v2/users/zaphod", {
|
||||||
|
status: 500
|
||||||
|
});
|
||||||
|
|
||||||
|
const store = mockStore({});
|
||||||
|
return store.dispatch(deleteUser(userZaphod)).then(() => {
|
||||||
|
const actions = store.getActions();
|
||||||
|
expect(actions[0].type).toEqual(DELETE_USER);
|
||||||
|
expect(actions[0].payload).toBe(userZaphod);
|
||||||
|
expect(actions[1].type).toEqual(DELETE_USER_FAILURE);
|
||||||
|
expect(actions[1].payload).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("users reducer", () => {
|
describe("users reducer", () => {
|
||||||
@@ -288,8 +325,7 @@ describe("users reducer", () => {
|
|||||||
const state = {
|
const state = {
|
||||||
usersByNames: {
|
usersByNames: {
|
||||||
zaphod: {
|
zaphod: {
|
||||||
loading: false,
|
loading: true,
|
||||||
error: null,
|
|
||||||
entry: userZaphod
|
entry: userZaphod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user