2018-07-11 12:02:53 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { configure, shallow } from "enzyme";
|
2018-07-10 16:37:40 +02:00
|
|
|
import DeleteUserButton from "./DeleteUserButton";
|
2018-07-11 12:02:53 +02:00
|
|
|
import Adapter from "enzyme-adapter-react-16";
|
2018-07-10 16:37:40 +02:00
|
|
|
|
2018-07-17 15:06:40 +02:00
|
|
|
import { confirmAlert } from '../../components/ConfirmAlert';
|
|
|
|
|
jest.mock('../../components/ConfirmAlert');
|
|
|
|
|
|
2018-07-11 12:02:53 +02:00
|
|
|
import "raf/polyfill";
|
2018-07-10 16:37:40 +02:00
|
|
|
|
|
|
|
|
configure({ adapter: new Adapter() });
|
|
|
|
|
|
2018-07-11 12:02:53 +02:00
|
|
|
it("should render nothing, if the delete link is missing", () => {
|
2018-07-10 16:37:40 +02:00
|
|
|
const user = {
|
|
|
|
|
_links: {}
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-17 15:06:40 +02:00
|
|
|
const button = shallow(<DeleteUserButton user={user} deleteUser={() => {}} />);
|
2018-07-10 16:37:40 +02:00
|
|
|
expect(button.text()).toBe("");
|
|
|
|
|
});
|
|
|
|
|
|
2018-07-11 12:02:53 +02:00
|
|
|
it("should render the button", () => {
|
2018-07-10 16:37:40 +02:00
|
|
|
const user = {
|
|
|
|
|
_links: {
|
2018-07-11 12:02:53 +02:00
|
|
|
delete: {
|
|
|
|
|
href: "/users"
|
2018-07-10 16:37:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-17 15:06:40 +02:00
|
|
|
const button = shallow(<DeleteUserButton user={user} deleteUser={() => {}} />);
|
2018-07-10 16:37:40 +02:00
|
|
|
expect(button.text()).not.toBe("");
|
|
|
|
|
});
|
|
|
|
|
|
2018-07-17 15:06:40 +02:00
|
|
|
it("should open the confirm dialog on button click", () => {
|
|
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
|
_links: {
|
|
|
|
|
delete: {
|
|
|
|
|
href: "/users"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const button = shallow(<DeleteUserButton user={user} deleteUser={() => {}} />);
|
|
|
|
|
button.simulate("click");
|
|
|
|
|
|
|
|
|
|
expect(confirmAlert.mock.calls.length).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
2018-07-11 12:02:53 +02:00
|
|
|
it("should call the delete user function with delete url", () => {
|
2018-07-10 16:37:40 +02:00
|
|
|
const user = {
|
|
|
|
|
_links: {
|
2018-07-11 12:02:53 +02:00
|
|
|
delete: {
|
|
|
|
|
href: "/users"
|
2018-07-10 16:37:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let calledUrl = null;
|
|
|
|
|
function capture(url) {
|
|
|
|
|
calledUrl = url;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-17 15:06:40 +02:00
|
|
|
const button = shallow(<DeleteUserButton user={user} confirmDialog={false} deleteUser={capture} />);
|
2018-07-10 16:37:40 +02:00
|
|
|
button.simulate("click");
|
|
|
|
|
|
|
|
|
|
expect(calledUrl).toBe("/users");
|
|
|
|
|
});
|