Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- the `DeleteAction` component now correctly displays the delete button, and supports custom text.

## [2.8.0] - 2023-09-05

### Fixed
Expand Down
12 changes: 7 additions & 5 deletions cypress/cypress/component/DeleteAction/DeleteAction.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { faker } from "@faker-js/faker";

describe("DeleteAction.cy.tsx", () => {
it("delete action works", () => {
const buttonText = faker.random.word();
const deleteButtonText = faker.random.word();
const cancelButtonText = faker.random.word();
const text = faker.random.words(10);
Expand All @@ -12,23 +13,24 @@ describe("DeleteAction.cy.tsx", () => {
cy.mount(
<DeleteAction
onDelete={cy.spy().as("onDelete")}
buttonText={buttonText}
deleteButtonText={deleteButtonText}
cancelButtonText={cancelButtonText}
text={text}
title={title}
iconOnly
/>,
);

// Check if correct default icon is drawn, open dialog, check title and press close icon
cy.get("[data-cy-root] > svg").should("have.class", "fa-trash").click();
// Check if correct default icon and text are drawn, open dialog, check title and press close icon
cy.get("[data-cy-root]").parents("body").get(".btn-danger").should("have.text", buttonText);
cy.get("[data-cy-root] svg").should("have.class", "fa-trash").click();
cy.get("[data-cy-root]").parents("body").get(".modal-dialog .modal-header h5").should("have.text", title);
cy.get("[data-cy-root]").parents("body").get(".modal-dialog .modal-header button.btn-close").click();
cy.get("@onDelete").should("not.be.calledOn");
cy.get("[data-cy-root]").parents("body").get(".modal-dialog").should("not.exist");

// Open dialog, check text, cancel button and press cancel button
cy.get("[data-cy-root] > svg").should("have.class", "fa-trash").click();
cy.get("[data-cy-root] svg").should("have.class", "fa-trash").click();
cy.get("[data-cy-root]").parents("body").get(".modal-dialog .modal-body").should("have.text", text);
cy.get("[data-cy-root]")
.parents("body")
Expand All @@ -39,7 +41,7 @@ describe("DeleteAction.cy.tsx", () => {
cy.get("[data-cy-root]").parents("body").get(".modal-dialog").should("not.exist");

// Open dialog, check delete button and press delete button
cy.get("[data-cy-root] > svg").should("have.class", "fa-trash").click();
cy.get("[data-cy-root] svg").should("have.class", "fa-trash").click();
cy.get("[data-cy-root]").parents("body").get(".modal-dialog .modal-footer .btn-danger").should("have.text", deleteButtonText).click();
cy.get("@onDelete").should("be.calledOnce");
});
Expand Down
7 changes: 5 additions & 2 deletions src/lib/DeleteAction/DeleteAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from "reactstrap";
interface DeleteActionProps {
title?: string;
text?: string;
buttonText?: string;
deleteButtonText?: string;
cancelButtonText?: string;
iconOnly?: boolean;
Expand All @@ -15,6 +16,7 @@ interface DeleteActionProps {
function DeleteAction({
title = "Delete Entry",
text = "Are you sure to Delete this Entry?",
buttonText = "Delete",
deleteButtonText = "Delete",
cancelButtonText = "Cancel",
iconOnly = false,
Expand All @@ -29,8 +31,9 @@ function DeleteAction({
{iconOnly ? (
<FontAwesomeIcon icon={faTrash} style={{ marginRight: "5px", cursor: "pointer" }} onClick={toggle} />
) : (
<Button color="danger" close onClick={toggle}>
<FontAwesomeIcon icon={faTrash} />
<Button color="danger" onClick={toggle}>
<FontAwesomeIcon style={{ marginRight: "5px" }} icon={faTrash} />
{buttonText}
</Button>
)}
<Modal isOpen={showModal} toggle={toggle}>
Expand Down