import {fireEvent, render, screen, waitFor} from "@testing-library/react";
import MockAppWithProviders from "../../../../../../../../../../../mocks/AppWithProvider";
import {AnswersProvider} from "@/lib/callWidget/contexts/answers";
import CallActionDescription from "..";

describe('Action Header Button from Call Actions Categories', () => {
    describe('Rendering', () => {
        it('should see placeholder text', async () => {
            render(
                <MockAppWithProviders>
                    <AnswersProvider>
                        <CallActionDescription />
                    </AnswersProvider>
                </MockAppWithProviders>
            )
            const textElement = screen.getByPlaceholderText('لطفا توضیحات خود را وارد نمایید')
            await waitFor(() => {
                expect(textElement).toBeInTheDocument()
            })
        });
        it('should see header text', async () => {
            render(
                <MockAppWithProviders>
                    <AnswersProvider>
                        <CallActionDescription />
                    </AnswersProvider>
                </MockAppWithProviders>
            )
            const textElement = screen.getByText('توضیحات تماس (اختیاری)')
            await waitFor(() => {
                expect(textElement).toBeInTheDocument()
            })
        });
    });
    describe("Behavior", ()=>{
        it("Should see what write in input", async()=>{
            const setDescription = jest.fn();
            render(
                <MockAppWithProviders>
                    <AnswersProvider>
                        <CallActionDescription setDescription={setDescription} />
                    </AnswersProvider>
                </MockAppWithProviders>
            )
            const textElement = screen.getByPlaceholderText('لطفا توضیحات خود را وارد نمایید')

            fireEvent.change(textElement, {target : {value : "امین"}})

            await waitFor(() => {
                expect(textElement).toHaveValue("امین")
            })
        })
    })
});