feat(frontend): RenameDialog and DeleteConfirmDialog
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { vi } from "vitest";
|
||||
import { RenameDialog } from "./RenameDialog";
|
||||
import { DeleteConfirmDialog } from "./DeleteConfirmDialog";
|
||||
|
||||
test("RenameDialog submits the edited name", async () => {
|
||||
const onSubmit = vi.fn();
|
||||
render(<RenameDialog open initial="Vecchio" onOpenChange={vi.fn()} onSubmit={onSubmit} />);
|
||||
const input = screen.getByLabelText(/name/i);
|
||||
await userEvent.clear(input);
|
||||
await userEvent.type(input, "Nuovo");
|
||||
await userEvent.click(screen.getByRole("button", { name: /save/i }));
|
||||
expect(onSubmit).toHaveBeenCalledWith("Nuovo");
|
||||
});
|
||||
|
||||
test("DeleteConfirmDialog confirms only on the destructive button", async () => {
|
||||
const onConfirm = vi.fn();
|
||||
render(<DeleteConfirmDialog open label="Sessione X" onOpenChange={vi.fn()} onConfirm={onConfirm} />);
|
||||
expect(screen.getByText(/Sessione X/)).toBeInTheDocument();
|
||||
await userEvent.click(screen.getByRole("button", { name: /delete/i }));
|
||||
expect(onConfirm).toHaveBeenCalled();
|
||||
});
|
||||
Reference in New Issue
Block a user