import type { UpdateSettingsInput } from "@shared/settings-schema.js";
import { render, screen } from "@testing-library/react";
import { FormProvider, useForm } from "react-hook-form";
import { describe, expect, it } from "vitest";
import { Accordion } from "@/components/ui/accordion";
import { JobSourcesSettingsSection } from "./JobSourcesSettingsSection";

const Harness = () => {
  const methods = useForm<UpdateSettingsInput>({
    defaultValues: {
      ashbyCompanies: [],
      greenhouseCompanies: [],
      leverCompanies: [],
      teamtailorCompanies: ["testgorilla"],
      careersPageUrls: [],
    },
  });

  return (
    <FormProvider {...methods}>
      <Accordion type="multiple" defaultValue={["job-sources"]}>
        <JobSourcesSettingsSection
          values={{
            ashbyCompanies: { effective: [], default: [] },
            greenhouseCompanies: { effective: [], default: [] },
            leverCompanies: { effective: [], default: [] },
            smartrecruitersCompanies: { effective: [], default: [] },
            teamtailorCompanies: {
              effective: ["testgorilla"],
              default: [],
            },
            huntflowTenants: { effective: [], default: [] },
            factorialTenants: { effective: [], default: [] },
            workdayTenants: { effective: [], default: [] },
            careersPageUrls: { effective: [], default: [] },
            icimsTenants: { effective: [], default: [] },
            elutaRssLocations: { effective: [], default: [] },
          }}
          isLoading={false}
          isSaving={false}
        />
      </Accordion>
    </FormProvider>
  );
};

describe("JobSourcesSettingsSection", () => {
  it("renders ATS and career page fields", () => {
    render(<Harness />);
    expect(screen.getByText("Job sources & ATS")).toBeInTheDocument();
    expect(screen.getByText("Teamtailor subdomains")).toBeInTheDocument();
    expect(
      screen.getByText("Career page URLs (auto-detect ATS)"),
    ).toBeInTheDocument();
    expect(screen.getByText("testgorilla")).toBeInTheDocument();
  });
});
