Fixed tests

This commit is contained in:
Philipp Czora
2018-07-17 17:00:45 +02:00
parent 0f87b61329
commit 727318124c
3 changed files with 47 additions and 48 deletions

View File

@@ -3,8 +3,8 @@ import { configure, shallow } from "enzyme";
import DeleteUserButton from "./DeleteUserButton";
import Adapter from "enzyme-adapter-react-16";
import { confirmAlert } from '../../components/ConfirmAlert';
jest.mock('../../components/ConfirmAlert');
import { confirmAlert } from "../../components/ConfirmAlert";
jest.mock("../../components/ConfirmAlert");
import "raf/polyfill";
@@ -15,7 +15,9 @@ it("should render nothing, if the delete link is missing", () => {
_links: {}
};
const button = shallow(<DeleteUserButton user={user} deleteUser={() => {}} />);
const button = shallow(
<DeleteUserButton user={user} deleteUser={() => {}} />
);
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("");
});
it("should open the confirm dialog on button click", () => {
const user = {
_links: {
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");
expect(confirmAlert.mock.calls.length).toBe(1);
@@ -58,11 +63,13 @@ it("should call the delete user function with delete url", () => {
};
let calledUrl = null;
function capture(url) {
calledUrl = url;
function capture(user) {
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");
expect(calledUrl).toBe("/users");