import { expect, test } from "vitest";
import { render, screen } from "@testing-library/react";

import "../i18n";
import { MutationError } from "./mutation-error";
import { HttpError, InUseError } from "../api/queries";

test("renders the status-specific message for an HttpError", () => {
  render(<MutationError error={new HttpError(403)} />);
  expect(screen.getByRole("alert")).toHaveTextContent(/permission/i);
});

test("renders the in-use count for an InUseError", () => {
  render(<MutationError error={new InUseError(2)} />);
  expect(screen.getByRole("alert")).toHaveTextContent(/2/);
});

test("renders nothing when there is no error", () => {
  const { container } = render(<MutationError error={null} />);
  expect(container).toBeEmptyDOMElement();
});
