2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
2020-10-05 18:40:15 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
import React, { FC } from "react";
|
|
|
|
|
// eslint-disable-next-line no-restricted-imports
|
2020-01-08 15:57:13 +01:00
|
|
|
import { mount, shallow } from "@scm-manager/ui-tests/enzyme-router";
|
2020-10-05 18:40:15 +02:00
|
|
|
// eslint-disable-next-line no-restricted-imports
|
2019-10-20 18:02:52 +02:00
|
|
|
import "@scm-manager/ui-tests/enzyme";
|
2020-10-05 18:40:15 +02:00
|
|
|
// eslint-disable-next-line no-restricted-imports
|
2019-10-20 18:02:52 +02:00
|
|
|
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
|
|
|
jest.mock("@scm-manager/ui-components", () => ({
|
2020-10-05 18:40:15 +02:00
|
|
|
ConfirmAlert: (({ children }) => <div className="modal">{children}</div>) as FC<never>,
|
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
|
|
|
};
|
|
|
|
|
|
2020-10-05 18:40:15 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
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
|
|
|
};
|
|
|
|
|
|
2020-10-05 18:40:15 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
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
|
|
|
};
|
|
|
|
|
|
2020-10-05 18:40:15 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
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
|
|
|
|
2020-10-05 18:40:15 +02:00
|
|
|
expect(button.find(".modal")).toBeTruthy();
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
|
|
|
|
|
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;
|
2020-10-05 18:40:15 +02:00
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
function capture(permission) {
|
|
|
|
|
calledUrl = permission._links.delete.href;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const button = mount(
|
2020-10-05 18:40:15 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
|
|
|
// @ts-ignore
|
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
|
|
|
});
|
|
|
|
|
});
|