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

88 lines
1.8 KiB
JavaScript
Raw Normal View History

import React from "react";
2018-07-18 14:02:07 +02:00
import { mount, shallow } from "enzyme";
import "../../tests/enzyme";
import "../../tests/i18n";
2018-07-10 16:37:40 +02:00
import DeleteUserButton from "./DeleteUserButton";
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
2018-07-18 08:31:23 +02:00
describe("DeleteUserButton", () => {
it("should render nothing, if the delete link is missing", () => {
2018-07-18 09:48:59 +02:00
const entry = {
entry: {
_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-18 09:48:59 +02:00
<DeleteUserButton entry={entry} 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-18 09:48:59 +02:00
const entry = {
entry: {
_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(
<DeleteUserButton entry={entry} 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-18 09:48:59 +02:00
const entry = {
entry: {
_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(
<DeleteUserButton entry={entry} deleteUser={() => {}} />
2018-07-18 08:31:23 +02:00
);
button.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-18 09:48:59 +02:00
const entry = {
entry: {
_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-18 09:48:59 +02:00
entry={entry}
2018-07-18 08:31:23 +02:00
confirmDialog={false}
deleteUser={capture}
/>
);
button.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
});