import { describe, expect, it } from "vitest";
import {
  contactTopics,
  getAllVerticals,
  getRelatedVerticals,
  getVerticalBySlug,
  siteConfig,
} from "./content";

describe("content.ts", () => {
  describe("siteConfig", () => {
    it("has required fields", () => {
      expect(siteConfig.name).toBe("Jenado Unlimited");
      expect(siteConfig.tagline).toContain("Craft for mind");
      expect(siteConfig.contactEmail).toContain("@");
      expect(siteConfig.siteUrl).toBeTruthy();
    });
  });

  describe("contactTopics", () => {
    it("contains expected topics", () => {
      const values = contactTopics.map((t) => t.value);
      expect(values).toContain("general");
      expect(values).toContain("honey-bees");
      expect(values).toContain("personal-training");
      expect(values).toContain("sourdough");
    });
  });

  describe("getAllVerticals", () => {
    it("returns an array of verticals", () => {
      const verticals = getAllVerticals();
      expect(Array.isArray(verticals)).toBe(true);
      expect(verticals.length).toBeGreaterThan(0);
    });

    it("sorts alphabetically by title", () => {
      const verticals = getAllVerticals();
      const titles = verticals.map((v) => v.title);
      const sorted = [...titles].sort((a, b) => a.localeCompare(b));
      expect(titles).toEqual(sorted);
    });

    it("each vertical has required shape", () => {
      const verticals = getAllVerticals();
      for (const v of verticals) {
        expect(v).toHaveProperty("slug");
        expect(v).toHaveProperty("title");
        expect(v).toHaveProperty("summary");
        expect(v).toHaveProperty("image");
        expect(v).toHaveProperty("pillars");
        expect(v).toHaveProperty("status");
      }
    });
  });

  describe("getVerticalBySlug", () => {
    it("returns a vertical for a valid slug", () => {
      const v = getVerticalBySlug("honey-bees");
      expect(v).toBeTruthy();
      expect(v?.slug).toBe("honey-bees");
      expect(v?.title).toContain("Honey");
    });

    it("returns undefined for unknown slug", () => {
      const v = getVerticalBySlug("does-not-exist" as any);
      expect(v).toBeUndefined();
    });
  });

  describe("getRelatedVerticals", () => {
    it("excludes the given slug", () => {
      const related = getRelatedVerticals("honey-bees", 5);
      expect(related.every((v) => v.slug !== "honey-bees")).toBe(true);
    });

    it("respects the limit", () => {
      const related = getRelatedVerticals("honey-bees", 2);
      expect(related.length).toBeLessThanOrEqual(2);
    });

    it("returns verticals with correct shape", () => {
      const related = getRelatedVerticals("sourdough", 3);
      for (const v of related) {
        expect(v).toHaveProperty("slug");
        expect(v.slug).not.toBe("sourdough");
      }
    });
  });
});
