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

const defaultTeam = {
  id: "team-1",
  name: "Test Team",
  description: "A test team",
  workspaceId: "ws-1",
  metadata: {},
  createdAt: new Date("2026-01-01"),
  updatedAt: new Date("2026-01-01"),
};

describe("TeamSettings", (): void => {
  const mockOnUpdate = vi.fn<(data: { name?: string; description?: string }) => Promise<void>>();
  const mockOnDelete = vi.fn<() => Promise<void>>();

  beforeEach((): void => {
    mockOnUpdate.mockReset();
    mockOnDelete.mockReset();
    mockOnUpdate.mockResolvedValue(undefined);
    mockOnDelete.mockResolvedValue(undefined);
  });

  describe("maxLength limits", (): void => {
    it("should have maxLength of 100 on team name input", (): void => {
      const team = defaultTeam;
      render(<TeamSettings team={team} onUpdate={mockOnUpdate} onDelete={mockOnDelete} />);

      const nameInput = screen.getByPlaceholderText("Enter team name");
      expect(nameInput).toHaveAttribute("maxLength", "100");
    });

    it("should have maxLength of 500 on team description textarea", (): void => {
      const team = defaultTeam;
      render(<TeamSettings team={team} onUpdate={mockOnUpdate} onDelete={mockOnDelete} />);

      const descriptionInput = screen.getByPlaceholderText("Enter team description (optional)");
      expect(descriptionInput).toHaveAttribute("maxLength", "500");
    });
  });
});
