import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { MemoryRouter } from "react-router-dom";
import { LoginPage } from "./LoginPage";

describe("LoginPage", () => {
  it("показывает ошибки валидации для некорректных данных", async () => {
    const user = userEvent.setup();
    render(
      <MemoryRouter>
        <LoginPage />
      </MemoryRouter>,
    );

    const email = screen.getByLabelText("Логин или почта");
    const password = screen.getByLabelText("Пароль");
    await user.clear(email);
    await user.type(email, "ab");
    await user.clear(password);
    await user.type(password, "123");
    await user.click(screen.getByRole("button", { name: "Войти" }));

    expect(await screen.findByText("Введите логин или почту")).toBeInTheDocument();
    expect(screen.getByText("Минимум 6 символов")).toBeInTheDocument();
  });
});
