import assert from "node:assert/strict";
import { describe, test } from "node:test";
import { OpportunityCategories } from "@/data/Constants";
import { EMPTY_PROFILE_FILTERS, profileOpportunityChip, resolveProfileOpportunityFilters } from "@/features/profile/components/profileFilters";

describe("profile dropdown and type chips use the same opportunity types", () => {
  test("the development dropdown value activates the development-only role field", () => {
    const option = OpportunityCategories.find(item => item.id === 2)!;
    const applied = resolveProfileOpportunityFilters({ ...EMPTY_PROFILE_FILTERS, opportunity_type: option.value, profile_activity_tag: "provider" });
    assert.equal(applied.opportunity_type, "learn_serve_opportunity");
    assert.equal(applied.profile_activity_tag, "provider");
    assert.equal(profileOpportunityChip(option.value), "development");
  });
  test("legacy short values reopen with a canonical selection", () => {
    assert.equal(resolveProfileOpportunityFilters({ ...EMPTY_PROFILE_FILTERS, opportunity_type: "learn" }).opportunity_type, "learn_serve_opportunity");
    assert.equal(resolveProfileOpportunityFilters({ ...EMPTY_PROFILE_FILTERS, opportunity_type: "volunteer" }).opportunity_type, "volunteer_opportunity");
  });
  test("selecting volunteering removes a hidden development role without losing dates", () => {
    const applied = resolveProfileOpportunityFilters({ ...EMPTY_PROFILE_FILTERS, startDate: "2026-11-01", opportunity_type: "learn_serve_opportunity", profile_activity_tag: "participant" }, "volunteer_opportunity");
    assert.equal(applied.opportunity_type, "volunteer_opportunity");
    assert.equal(applied.profile_activity_tag, "");
    assert.equal(applied.startDate, "2026-11-01");
  });
  test("clearing the type also clears the role and returns the All chip", () => {
    const applied = resolveProfileOpportunityFilters({ ...EMPTY_PROFILE_FILTERS, profile_activity_tag: "provider" });
    assert.equal(applied.profile_activity_tag, "");
    assert.equal(profileOpportunityChip(applied.opportunity_type), "all");
  });
});
