import {fireEvent, render, screen, waitFor} from "@testing-library/react";
import MockAppWithProviders from "../../../../../../../mocks/AppWithProvider";
import React from "react";
import DeleteForm from "@/components/dashboard/expert-management/Form/DeleteForm";

describe("CreateForm Component From Expert Management", () => {
    describe("Rendering", () => {
        it("Delete Expert Button And Tooltip Rendered", () => {
            render(<MockAppWithProviders><DeleteForm/></MockAppWithProviders>);
            const DeleteButton = screen.getByTestId('delete-button');
            expect(DeleteButton).toBeInTheDocument();
        });
        it("Delete Dialog Rendered", () => {
            render(<MockAppWithProviders><DeleteForm/></MockAppWithProviders>);
            const DeleteButton = screen.getByTestId('delete-button');
            fireEvent.click(DeleteButton);
            const DeleteDialogHeader = screen.queryByText("حذف کارشناس");
            expect(DeleteDialogHeader).toBeInTheDocument();
        });
        it("Delete Dialog Text Rendered", () => {
            render(<MockAppWithProviders><DeleteForm/></MockAppWithProviders>);
            const DeleteButton = screen.getByTestId('delete-button');
            fireEvent.click(DeleteButton);
            const DeleteDialogText = screen.queryByText("آیا از انجام این عملیات اطمینان دارید؟");
            expect(DeleteDialogText).toBeInTheDocument();
        });
        it("Delete Dialog Delete Button Rendered", () => {
            render(<MockAppWithProviders><DeleteForm/></MockAppWithProviders>);
            const DeleteButton = screen.getByTestId('delete-button');
            fireEvent.click(DeleteButton);
            const DeleteButtonDialog = screen.getByRole('button', {name: "حذف"});
            expect(DeleteButtonDialog).toBeInTheDocument();
        });
        it("Delete Dialog Cancel Button Rendered", () => {
            render(<MockAppWithProviders><DeleteForm/></MockAppWithProviders>);
            const DeleteButton = screen.getByTestId('delete-button');
            fireEvent.click(DeleteButton);
            const CancelButtonDialog = screen.getByRole('button', {name: "بستن"});
            expect(CancelButtonDialog).toBeInTheDocument();
        });
    });
    describe("Behavioral", () => {
        it("By Clicking Delete Button Dialog Should Append To Document", async () => {
            render(<MockAppWithProviders><DeleteForm/></MockAppWithProviders>);
            const DeleteButton = screen.getByTestId('delete-button');
            fireEvent.click(DeleteButton);
            await waitFor(() => {
                const DeleteDialog = screen.getByRole('dialog', {name: "حذف کارشناس"})
                expect(DeleteDialog).toBeInTheDocument();
            });
        });
    });
    describe("Form Submission", () => {
        it("By Clicking Delete Button Request To Api And Delete Item", async () => {
            render(<MockAppWithProviders><DeleteForm rowId={1}/></MockAppWithProviders>);
            const DeleteButton = screen.getByTestId('delete-button');
            fireEvent.click(DeleteButton);
            const DeleteButtonDialog = screen.getByRole('button', {name: "حذف"});
            fireEvent.click(DeleteButtonDialog);
            await waitFor(() => {
                const DeleteDialog = screen.queryByRole('dialog', {name: "حذف کارشناس"});
                expect(DeleteDialog).not.toBeInTheDocument();
            });
        });
    });
});