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-js": "react-scripts build",
"build": "npm-run-all build-css build-js", "build": "npm-run-all build-css build-js",
"test": "jest", "test": "jest",
"test-coverage": "yarn run test --coverage",
"eject": "react-scripts eject", "eject": "react-scripts eject",
"flow": "flow" "flow": "flow"
}, },

View File

@@ -1,13 +1,15 @@
// @flow // @flow
import { createUrl } from "./apiclient"; 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( expect(createUrl("https://www.scm-manager.org")).toBe(
"https://www.scm-manager.org" "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");
expect(createUrl("users")).toBe("/scm/api/rest/v2/users"); expect(createUrl("users")).toBe("/scm/api/rest/v2/users");
});
}); });

View File

@@ -10,7 +10,8 @@ import "raf/polyfill";
configure({ adapter: new Adapter() }); configure({ adapter: new Adapter() });
it("should render nothing, if the delete link is missing", () => { describe("DeleteUserButton", () => {
it("should render nothing, if the delete link is missing", () => {
const user = { const user = {
_links: {} _links: {}
}; };
@@ -19,9 +20,9 @@ it("should render nothing, if the delete link is missing", () => {
<DeleteUserButton user={user} deleteUser={() => {}} /> <DeleteUserButton user={user} deleteUser={() => {}} />
); );
expect(button.text()).toBe(""); expect(button.text()).toBe("");
}); });
it("should render the button", () => { it("should render the button", () => {
const user = { const user = {
_links: { _links: {
delete: { delete: {
@@ -34,9 +35,9 @@ it("should render the button", () => {
<DeleteUserButton user={user} deleteUser={() => {}} /> <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: {
@@ -51,9 +52,9 @@ it("should open the confirm dialog on button click", () => {
button.simulate("click"); button.simulate("click");
expect(confirmAlert.mock.calls.length).toBe(1); expect(confirmAlert.mock.calls.length).toBe(1);
}); });
it("should call the delete user function with delete url", () => { it("should call the delete user function with delete url", () => {
const user = { const user = {
_links: { _links: {
delete: { delete: {
@@ -68,9 +69,14 @@ it("should call the delete user function with delete url", () => {
} }
const button = shallow( const button = shallow(
<DeleteUserButton user={user} confirmDialog={false} deleteUser={capture} /> <DeleteUserButton
user={user}
confirmDialog={false}
deleteUser={capture}
/>
); );
button.simulate("click"); button.simulate("click");
expect(calledUrl).toBe("/users"); expect(calledUrl).toBe("/users");
});
}); });

View File

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

View File

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