import {fireEvent, getByRole, render, screen} from "@testing-library/react";
import PasswordField from "@/core/components/PasswordField";
import {Formik} from "formik";

describe('Password Field component in core folder',  () => {
    describe('Rendering', () => {
        it('Show password when visibility icon clicked',() => {
            render (
                <Formik initialValues={{password:''}} onSubmit={()=>{}}>
                    {(props)=>(
                <PasswordField label="رمز عبور" />
                    )}
                </Formik>
            )

            const iconElement = screen.getByLabelText("رمز عبور")
            const iconButton = screen.getByRole("button")


            expect(iconElement).toHaveAttribute('type', 'password');

            fireEvent.click(iconButton);

            expect(iconElement).toHaveAttribute("type", "text");

            fireEvent.click(iconButton);

            expect(iconElement).toHaveAttribute('type', 'password');
        })
    })
})