This commit is contained in:
Chahat Kesharwani 2026-09-23 14:51:53 +00:00 • committed by GitHub
commit 75e7174163
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

@ -121,6 +121,25 @@ describe("DeleteResourceModal", () => {
expect(deleteButton).toBeEnabled();
});
it("should enable delete button when the confirmation input matches after surrounding whitespace is trimmed", () => {
renderWithProviders(<DeleteResourceModal {...defaultProps} requiredConfirmation="prod-key" />);
const input = screen.getByPlaceholderText("prod-key");
fireEvent.change(input, { target: { value: " prod-key " } });
expect(screen.getByRole("button", { name: /delete/i })).toBeEnabled();
});
it("should keep delete disabled when trimmed confirmation input still does not match", () => {
renderWithProviders(<DeleteResourceModal {...defaultProps} requiredConfirmation="prod-key" />);
fireEvent.change(screen.getByPlaceholderText("prod-key"), { target: { value: " other-key " } });
expect(screen.getByRole("button", { name: /delete/i })).toBeDisabled();
});
it("should enable delete when the stored name itself has surrounding whitespace", () => {
renderWithProviders(<DeleteResourceModal {...defaultProps} requiredConfirmation=" prod-key " />);
fireEvent.change(screen.getByRole("textbox"), { target: { value: "prod-key" } });
expect(screen.getByRole("button", { name: /delete/i })).toBeEnabled();
});
it("should reset requiredConfirmation input when modal opens", async () => {
const user = userEvent.setup();
const { rerender } = renderWithProviders(<DeleteResourceModal {...defaultProps} requiredConfirmation="DELETE" />);

View file

@ -101,7 +101,10 @@ export default function DeleteResourceModal({
<Button
variant="destructive"
onClick={onOk}
disabled={(!!requiredConfirmation && requiredConfirmationInput !== requiredConfirmation) || confirmLoading}
disabled={
(!!requiredConfirmation && requiredConfirmationInput.trim() !== requiredConfirmation.trim()) ||
confirmLoading
}
>
{confirmLoading ? "Deleting..." : "Delete"}
</Button>