2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
2020-01-08 15:57:13 +01:00
|
|
|
import { mount, shallow } from "@scm-manager/ui-tests/enzyme-router";
|
2019-10-20 18:02:52 +02:00
|
|
|
import "@scm-manager/ui-tests/enzyme";
|
|
|
|
|
import "@scm-manager/ui-tests/i18n";
|
|
|
|
|
import DeletePermissionButton from "./DeletePermissionButton";
|
2019-10-19 16:38:07 +02:00
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
import { confirmAlert } from "@scm-manager/ui-components";
|
2020-01-08 15:57:13 +01:00
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
jest.mock("@scm-manager/ui-components", () => ({
|
2019-10-19 16:38:07 +02:00
|
|
|
confirmAlert: jest.fn(),
|
2019-10-20 18:02:52 +02:00
|
|
|
DeleteButton: require.requireActual("@scm-manager/ui-components").DeleteButton
|
2019-10-19 16:38:07 +02:00
|
|
|
}));
|
|
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
describe("DeletePermissionButton", () => {
|
|
|
|
|
it("should render nothing, if the delete link is missing", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const permission = {
|
2019-10-20 18:02:52 +02:00
|
|
|
_links: {}
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-21 10:57:56 +02:00
|
|
|
const navLink = shallow(<DeletePermissionButton permission={permission} deletePermission={() => {}} />);
|
2019-10-20 18:02:52 +02:00
|
|
|
expect(navLink.text()).toBe("");
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
|
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
it("should render the delete icon", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const permission = {
|
|
|
|
|
_links: {
|
|
|
|
|
delete: {
|
2019-10-20 18:02:52 +02:00
|
|
|
href: "/permission"
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-21 10:57:56 +02:00
|
|
|
const deleteIcon = mount(<DeletePermissionButton permission={permission} deletePermission={() => {}} />);
|
2019-10-20 18:02:52 +02:00
|
|
|
expect(deleteIcon.html()).not.toBe("");
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
|
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
it("should open the confirm dialog on button click", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const permission = {
|
|
|
|
|
_links: {
|
|
|
|
|
delete: {
|
2019-10-20 18:02:52 +02:00
|
|
|
href: "/permission"
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-21 10:57:56 +02:00
|
|
|
const button = mount(<DeletePermissionButton permission={permission} deletePermission={() => {}} />);
|
2019-10-20 18:02:52 +02:00
|
|
|
button.find(".fa-trash").simulate("click");
|
2019-10-19 16:38:07 +02:00
|
|
|
|
|
|
|
|
expect(confirmAlert.mock.calls.length).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
it("should call the delete permission function with delete url", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const permission = {
|
|
|
|
|
_links: {
|
|
|
|
|
delete: {
|
2019-10-20 18:02:52 +02:00
|
|
|
href: "/permission"
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let calledUrl = null;
|
|
|
|
|
function capture(permission) {
|
|
|
|
|
calledUrl = permission._links.delete.href;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const button = mount(
|
2019-10-21 10:57:56 +02:00
|
|
|
<DeletePermissionButton permission={permission} confirmDialog={false} deletePermission={capture} />
|
2019-10-19 16:38:07 +02:00
|
|
|
);
|
2019-10-20 18:02:52 +02:00
|
|
|
button.find(".fa-trash").simulate("click");
|
2019-10-19 16:38:07 +02:00
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
expect(calledUrl).toBe("/permission");
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
|
|
|
|
});
|