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

53 lines
1.1 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
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: {}
};
const button = shallow(<DeleteUserButton user={user} />);
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
}
}
};
const button = shallow(<DeleteUserButton user={user} />);
2018-07-10 16:37:40 +02:00
expect(button.text()).not.toBe("");
});
//TODO: Fix wrong test!
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;
}
const button = shallow(<DeleteUserButton user={user} deleteUser={capture} />);
2018-07-10 16:37:40 +02:00
button.simulate("click");
expect(calledUrl).toBe("/users");
});