/**
 * Unit tests for ErrorState. Ported from webapp/js/ui.test.js showError.
 */

import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen } from "@testing-library/react";
import { ErrorState } from "./ErrorState";
import { resetAppStore } from "@/test/test-utils";

describe("ErrorState", () => {
  beforeEach(() => resetAppStore());

  it("renders error message", () => {
    render(<ErrorState message="Network error" onRetry={undefined} />);
    expect(screen.getByText("Network error")).toBeInTheDocument();
  });

  it("renders Retry button when onRetry provided", () => {
    const onRetry = vi.fn();
    render(<ErrorState message="Fail" onRetry={onRetry} />);
    const retry = screen.getByRole("button", { name: /retry|повторить/i });
    expect(retry).toBeInTheDocument();
    retry.click();
    expect(onRetry).toHaveBeenCalled();
  });
});
