-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'clean' of https://github.com/hngprojects/hng_boilerplat…
…e_nextjs into refactor/restructure-email-templates
- Loading branch information
Showing
4 changed files
with
154 additions
and
83 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/app/dashboard/(admin)/admin/users/component/dialogue/delete-dialog.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
|
||
import DeleteDialog from "./delete-dialog"; | ||
|
||
describe("deleteDialog", () => { | ||
it("renders the dialog with correct content", () => { | ||
expect.hasAssertions(); | ||
const onClose = vi.fn(); | ||
render(<DeleteDialog onClose={onClose} />); | ||
|
||
expect(screen.getByText("Are you absolutely sure?")).toBeInTheDocument(); | ||
expect( | ||
screen.getByText( | ||
"This action cannot be undone. This will permanently delete this product from the database.", | ||
), | ||
).toBeInTheDocument(); | ||
expect(screen.getByRole("button", { name: /cancel/i })).toBeInTheDocument(); | ||
expect(screen.getByRole("button", { name: /delete/i })).toBeInTheDocument(); | ||
}); | ||
|
||
it("calls onClose when Cancel button is clicked", () => { | ||
expect.hasAssertions(); | ||
const onClose = vi.fn(); | ||
render(<DeleteDialog onClose={onClose} />); | ||
|
||
fireEvent.click(screen.getByRole("button", { name: /cancel/i })); | ||
expect(onClose).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("calls onClose when Delete button is clicked", () => { | ||
expect.hasAssertions(); | ||
const onClose = vi.fn(); | ||
render(<DeleteDialog onClose={onClose} />); | ||
|
||
fireEvent.click(screen.getByRole("button", { name: /delete/i })); | ||
expect(onClose).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
src/app/dashboard/(admin)/admin/users/component/dialogue/delete-dialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Button } from "~/components/common/common-button"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogHeader, | ||
DialogTitle, | ||
} from "~/components/ui/dialog"; | ||
|
||
const DeleteDialog = ({ onClose }: { onClose: () => void }) => { | ||
return ( | ||
<Dialog open onOpenChange={onClose}> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle className="text-lg font-semibold leading-7 text-slate-900"> | ||
Are you absolutely sure? | ||
</DialogTitle> | ||
<DialogDescription className="text-sm font-normal leading-tight text-slate-500"> | ||
This action cannot be undone. This will permanently delete this | ||
product from the database. | ||
</DialogDescription> | ||
</DialogHeader> | ||
<div className="flex w-full"> | ||
<Button | ||
variant="outline" | ||
className="ml-auto flex items-center justify-center gap-2.5 rounded-md px-4 py-2 text-sm font-medium leading-normal" | ||
onClick={onClose} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
onClick={onClose} | ||
className="ml-2 flex items-center justify-center gap-2.5 rounded-md bg-red-600 px-4 py-2 text-sm font-medium leading-normal text-white" | ||
> | ||
Delete | ||
</Button> | ||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default DeleteDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters