diff --git a/scm-ui/jest.config.js b/scm-ui/jest.config.js deleted file mode 100644 index a5e135724b..0000000000 --- a/scm-ui/jest.config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - collectCoverage: true, - coverageFormats: ["json", "html"] -}; diff --git a/scm-ui/package.json b/scm-ui/package.json index c93ac29ca6..de30ec8047 100644 --- a/scm-ui/package.json +++ b/scm-ui/package.json @@ -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" }, diff --git a/scm-ui/src/apiclient.test.js b/scm-ui/src/apiclient.test.js index 2a185196d5..15c1904ca4 100644 --- a/scm-ui/src/apiclient.test.js +++ b/scm-ui/src/apiclient.test.js @@ -1,13 +1,15 @@ // @flow import { createUrl } from "./apiclient"; -test("create url, should not change absolute urls", () => { - expect(createUrl("https://www.scm-manager.org")).toBe( - "https://www.scm-manager.org" - ); -}); +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", () => { - expect(createUrl("/users")).toBe("/scm/api/rest/v2/users"); - expect(createUrl("users")).toBe("/scm/api/rest/v2/users"); + it("should add prefix for api", () => { + expect(createUrl("/users")).toBe("/scm/api/rest/v2/users"); + expect(createUrl("users")).toBe("/scm/api/rest/v2/users"); + }); }); diff --git a/scm-ui/src/users/containers/DeleteUserButton.test.js b/scm-ui/src/users/containers/DeleteUserButton.test.js index 718b41be8d..5923dbbc2a 100644 --- a/scm-ui/src/users/containers/DeleteUserButton.test.js +++ b/scm-ui/src/users/containers/DeleteUserButton.test.js @@ -10,67 +10,73 @@ import "raf/polyfill"; configure({ adapter: new Adapter() }); -it("should render nothing, if the delete link is missing", () => { - const user = { - _links: {} - }; +describe("DeleteUserButton", () => { + it("should render nothing, if the delete link is missing", () => { + const user = { + _links: {} + }; - const button = shallow( - {}} /> - ); - expect(button.text()).toBe(""); -}); + const button = shallow( + {}} /> + ); + expect(button.text()).toBe(""); + }); -it("should render the button", () => { - const user = { - _links: { - delete: { - href: "/users" + it("should render the button", () => { + const user = { + _links: { + delete: { + href: "/users" + } } - } - }; + }; - const button = shallow( - {}} /> - ); - expect(button.text()).not.toBe(""); -}); + const button = shallow( + {}} /> + ); + expect(button.text()).not.toBe(""); + }); -it("should open the confirm dialog on button click", () => { - const user = { - _links: { - delete: { - href: "/users" + it("should open the confirm dialog on button click", () => { + const user = { + _links: { + delete: { + href: "/users" + } } - } - }; + }; - const button = shallow( - {}} /> - ); - button.simulate("click"); + const button = shallow( + {}} /> + ); + 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", () => { - const user = { - _links: { - delete: { - href: "/users" + it("should call the delete user function with delete url", () => { + const user = { + _links: { + delete: { + href: "/users" + } } + }; + + let calledUrl = null; + function capture(user) { + calledUrl = user._links.delete.href; } - }; - let calledUrl = null; - function capture(user) { - calledUrl = user._links.delete.href; - } + const button = shallow( + + ); + button.simulate("click"); - const button = shallow( - - ); - button.simulate("click"); - - expect(calledUrl).toBe("/users"); + expect(calledUrl).toBe("/users"); + }); }); diff --git a/scm-ui/src/users/containers/Users.js b/scm-ui/src/users/containers/Users.js index 14f621c853..195cf6ab7e 100644 --- a/scm-ui/src/users/containers/Users.js +++ b/scm-ui/src/users/containers/Users.js @@ -82,7 +82,7 @@ class Users extends React.Component { const mapStateToProps = state => { const userEntries = getUsersFromState(state); - var userToEdit = state.users.editUser; + const userToEdit = state.users.editUser; if (!userEntries) { return { userToEdit }; } diff --git a/scm-ui/src/users/modules/users.test.js b/scm-ui/src/users/modules/users.test.js index e39998cb39..5069888a2f 100644 --- a/scm-ui/src/users/modules/users.test.js +++ b/scm-ui/src/users/modules/users.test.js @@ -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( {}, {