Files
SCM-Manager/scm-ui/src/users/containers/DeleteUserButton.test.js

77 lines
1.6 KiB
JavaScript
Raw Normal View History

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