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

70 lines
1.5 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 15:06:40 +02:00
import { confirmAlert } from '../../components/ConfirmAlert';
jest.mock('../../components/ConfirmAlert');
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 15:06:40 +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 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);
});
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;
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");
});