Fixed minor issues

This commit is contained in:
Philipp Czora
2018-07-18 08:31:23 +02:00
parent 727318124c
commit ef4d4b8f02
6 changed files with 83 additions and 78 deletions

View File

@@ -1,4 +0,0 @@
module.exports = {
collectCoverage: true,
coverageFormats: ["json", "html"]
};

View File

@@ -27,6 +27,7 @@
"build-js": "react-scripts build",
"build": "npm-run-all build-css build-js",
"test": "jest",
"test-coverage": "yarn run test --coverage",
"eject": "react-scripts eject",
"flow": "flow"
},

View File

@@ -1,13 +1,15 @@
// @flow
import { createUrl } from "./apiclient";
test("create url, should not change absolute urls", () => {
describe("create url", () => {
it("should not change absolute urls", () => {
expect(createUrl("https://www.scm-manager.org")).toBe(
"https://www.scm-manager.org"
);
});
test("create url, should add prefix for api", () => {
it("should add prefix for api", () => {
expect(createUrl("/users")).toBe("/scm/api/rest/v2/users");
expect(createUrl("users")).toBe("/scm/api/rest/v2/users");
});
});

View File

@@ -10,6 +10,7 @@ import "raf/polyfill";
configure({ adapter: new Adapter() });
describe("DeleteUserButton", () => {
it("should render nothing, if the delete link is missing", () => {
const user = {
_links: {}
@@ -68,9 +69,14 @@ it("should call the delete user function with delete url", () => {
}
const button = shallow(
<DeleteUserButton user={user} confirmDialog={false} deleteUser={capture} />
<DeleteUserButton
user={user}
confirmDialog={false}
deleteUser={capture}
/>
);
button.simulate("click");
expect(calledUrl).toBe("/users");
});
});

View File

@@ -82,7 +82,7 @@ class Users extends React.Component<Props, User> {
const mapStateToProps = state => {
const userEntries = getUsersFromState(state);
var userToEdit = state.users.editUser;
const userToEdit = state.users.editUser;
if (!userEntries) {
return { userToEdit };
}

View File

@@ -125,14 +125,14 @@ const response = {
responseBody
};
describe("fetch tests", () => {
describe("users fetch()", () => {
const mockStore = configureMockStore([thunk]);
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
test("successful users fetch", () => {
it("should successfully fetch users", () => {
fetchMock.getOnce("/scm/api/rest/v2/users", response);
const expectedActions = [
@@ -150,7 +150,7 @@ describe("fetch tests", () => {
});
});
test("me fetch failed", () => {
it("should fail getting users on HTTP 500", () => {
fetchMock.getOnce("/scm/api/rest/v2/users", {
status: 500
});
@@ -164,7 +164,7 @@ describe("fetch tests", () => {
});
});
test("successful user add", () => {
it("should add a user successfully", () => {
fetchMock.postOnce("/scm/api/rest/v2/users", {
status: 204
});
@@ -177,7 +177,7 @@ describe("fetch tests", () => {
});
});
test("user add failed", () => {
it("should fail adding a user on HTTP 500", () => {
fetchMock.postOnce("/scm/api/rest/v2/users", {
status: 500
});
@@ -191,7 +191,7 @@ describe("fetch tests", () => {
});
});
test("successful user update", () => {
it("successfully update user", () => {
fetchMock.putOnce("http://localhost:8081/scm/api/rest/v2/users/zaphod", {
status: 204
});
@@ -204,7 +204,7 @@ describe("fetch tests", () => {
});
});
test("user update failed", () => {
it("should fail updating user on HTTP 500", () => {
fetchMock.putOnce("http://localhost:8081/scm/api/rest/v2/users/zaphod", {
status: 500
});
@@ -219,15 +219,15 @@ describe("fetch tests", () => {
});
});
describe("reducer tests", () => {
test("users request", () => {
var newState = reducer({}, { type: FETCH_USERS });
describe("users reducer", () => {
test("should update state correctly according to FETCH_USERS action", () => {
const newState = reducer({}, { type: FETCH_USERS });
expect(newState.loading).toBeTruthy();
expect(newState.error).toBeNull();
});
test("fetch users successful", () => {
var newState = reducer(
it("should update state correctly according to FETCH_USERS_SUCCESS action", () => {
const newState = reducer(
{},
{ type: FETCH_USERS_SUCCESS, payload: responseBody }
);
@@ -248,7 +248,7 @@ describe("reducer tests", () => {
});
});
test("delete user requested", () => {
test("should update state correctly according to DELETE_USER action", () => {
const state = {
usersByNames: {
zaphod: {
@@ -322,7 +322,7 @@ describe("reducer tests", () => {
expect(ford.loading).toBeFalsy();
});
test("reducer does not replace whole usersByNames map", () => {
it("should not replace whole usersByNames map when fetching users", () => {
const oldState = {
usersByNames: {
ford: {
@@ -339,7 +339,7 @@ describe("reducer tests", () => {
expect(newState.usersByNames["ford"]).toBeDefined();
});
test("edit user", () => {
it("should update state correctly according to EDIT_USER action", () => {
const newState = reducer(
{},
{