2018-07-11 12:02:53 +02:00
|
|
|
import React from "react";
|
2018-07-18 14:02:07 +02:00
|
|
|
import { mount, shallow } from "enzyme";
|
2018-07-25 15:04:19 +02:00
|
|
|
import "../../../tests/enzyme";
|
|
|
|
|
import "../../../tests/i18n";
|
2018-07-10 16:37:40 +02:00
|
|
|
import DeleteUserButton from "./DeleteUserButton";
|
|
|
|
|
|
2018-07-25 15:04:19 +02:00
|
|
|
import { confirmAlert } from "../../../components/modals/ConfirmAlert";
|
|
|
|
|
jest.mock("../../../components/modals/ConfirmAlert");
|
2018-07-17 15:06:40 +02:00
|
|
|
|
2018-07-18 08:31:23 +02:00
|
|
|
describe("DeleteUserButton", () => {
|
|
|
|
|
it("should render nothing, if the delete link is missing", () => {
|
2018-07-25 13:21:49 +02:00
|
|
|
const user = {
|
|
|
|
|
_links: {}
|
2018-07-18 08:31:23 +02:00
|
|
|
};
|
2018-07-10 16:37:40 +02:00
|
|
|
|
2018-07-18 08:31:23 +02:00
|
|
|
const button = shallow(
|
2018-07-25 13:21:49 +02:00
|
|
|
<DeleteUserButton user={user} deleteUser={() => {}} />
|
2018-07-18 08:31:23 +02:00
|
|
|
);
|
|
|
|
|
expect(button.text()).toBe("");
|
|
|
|
|
});
|
2018-07-10 16:37:40 +02:00
|
|
|
|
2018-07-18 08:31:23 +02:00
|
|
|
it("should render the button", () => {
|
2018-07-25 13:21:49 +02:00
|
|
|
const user = {
|
|
|
|
|
_links: {
|
|
|
|
|
delete: {
|
|
|
|
|
href: "/users"
|
2018-07-18 08:31:23 +02:00
|
|
|
}
|
2018-07-10 16:37:40 +02:00
|
|
|
}
|
2018-07-18 08:31:23 +02:00
|
|
|
};
|
2018-07-10 16:37:40 +02:00
|
|
|
|
2018-07-18 09:48:59 +02:00
|
|
|
const button = mount(
|
2018-07-25 13:21:49 +02:00
|
|
|
<DeleteUserButton user={user} deleteUser={() => {}} />
|
2018-07-18 08:31:23 +02:00
|
|
|
);
|
|
|
|
|
expect(button.text()).not.toBe("");
|
|
|
|
|
});
|
2018-07-10 16:37:40 +02:00
|
|
|
|
2018-07-18 08:31:23 +02:00
|
|
|
it("should open the confirm dialog on button click", () => {
|
2018-07-25 13:21:49 +02:00
|
|
|
const user = {
|
|
|
|
|
_links: {
|
|
|
|
|
delete: {
|
|
|
|
|
href: "/users"
|
2018-07-18 08:31:23 +02:00
|
|
|
}
|
2018-07-17 15:06:40 +02:00
|
|
|
}
|
2018-07-18 08:31:23 +02:00
|
|
|
};
|
2018-07-17 15:06:40 +02:00
|
|
|
|
2018-07-18 09:48:59 +02:00
|
|
|
const button = mount(
|
2018-07-25 13:21:49 +02:00
|
|
|
<DeleteUserButton user={user} deleteUser={() => {}} />
|
2018-07-18 08:31:23 +02:00
|
|
|
);
|
2018-07-25 13:21:49 +02:00
|
|
|
button.find("a").simulate("click");
|
2018-07-17 15:06:40 +02:00
|
|
|
|
2018-07-18 08:31:23 +02:00
|
|
|
expect(confirmAlert.mock.calls.length).toBe(1);
|
|
|
|
|
});
|
2018-07-17 15:06:40 +02:00
|
|
|
|
2018-07-18 08:31:23 +02:00
|
|
|
it("should call the delete user function with delete url", () => {
|
2018-07-25 13:21:49 +02:00
|
|
|
const user = {
|
|
|
|
|
_links: {
|
|
|
|
|
delete: {
|
|
|
|
|
href: "/users"
|
2018-07-18 08:31:23 +02:00
|
|
|
}
|
2018-07-10 16:37:40 +02:00
|
|
|
}
|
2018-07-18 08:31:23 +02:00
|
|
|
};
|
2018-07-10 16:37:40 +02:00
|
|
|
|
2018-07-18 08:31:23 +02:00
|
|
|
let calledUrl = null;
|
|
|
|
|
function capture(user) {
|
|
|
|
|
calledUrl = user._links.delete.href;
|
|
|
|
|
}
|
2018-07-10 16:37:40 +02:00
|
|
|
|
2018-07-18 09:48:59 +02:00
|
|
|
const button = mount(
|
2018-07-18 08:31:23 +02:00
|
|
|
<DeleteUserButton
|
2018-07-25 13:21:49 +02:00
|
|
|
user={user}
|
2018-07-18 08:31:23 +02:00
|
|
|
confirmDialog={false}
|
|
|
|
|
deleteUser={capture}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2018-07-25 13:21:49 +02:00
|
|
|
button.find("a").simulate("click");
|
2018-07-10 16:37:40 +02:00
|
|
|
|
2018-07-18 08:31:23 +02:00
|
|
|
expect(calledUrl).toBe("/users");
|
|
|
|
|
});
|
2018-07-10 16:37:40 +02:00
|
|
|
});
|