// src/components/keywords/planning/semantic-labels.test.ts
import { describe, expect, test } from "bun:test";
import {
  archetypeLabel,
  flagLabel,
  intentModeLabel,
  phaseLabel,
} from "./semantic-labels";

describe("phaseLabel", () => {
  test("maps each runner phase to FR", () => {
    expect(phaseLabel("fetch")).toBe("Récupération des pages");
    expect(phaseLabel("extract")).toBe("Extraction sémantique");
    expect(phaseLabel("score")).toBe("Calcul du score");
    expect(phaseLabel("persist")).toBe("Enregistrement");
  });

  test("falls back to the raw string for an unknown phase", () => {
    expect(phaseLabel("mystery")).toBe("mystery");
  });
});

describe("archetypeLabel", () => {
  test("maps EN archetype keys to FR", () => {
    expect(archetypeLabel("transactional")).toBe("transactionnel");
    expect(archetypeLabel("editorial")).toBe("éditorial");
    expect(archetypeLabel("unknown")).toBe("indéterminé");
  });

  test("falls back to the raw string for an unmapped archetype", () => {
    expect(archetypeLabel("navigational")).toBe("navigational");
  });
});

describe("intentModeLabel", () => {
  test("maps inferred/manual to FR", () => {
    expect(intentModeLabel("inferred")).toBe("inférée");
    expect(intentModeLabel("manual")).toBe("manuelle");
  });
});

describe("flagLabel", () => {
  test("maps empty_corpus", () => {
    expect(flagLabel("empty_corpus")).toBe(
      "Corpus vide (aucune page exploitable)",
    );
  });

  test("maps the synthetic mixed_intent flag", () => {
    expect(flagLabel("mixed_intent")).toBe(
      "Intention mixte (pas de dominante claire)",
    );
  });

  test("maps lang_mismatch:<position> with the position interpolated", () => {
    expect(flagLabel("lang_mismatch:3")).toBe(
      "Langue différente en position 3",
    );
    expect(flagLabel("lang_mismatch:10")).toBe(
      "Langue différente en position 10",
    );
  });

  test("maps js_rendered_suspected:<position> with the position interpolated", () => {
    expect(flagLabel("js_rendered_suspected:2")).toBe(
      "Rendu JS suspecté en position 2 (page exclue)",
    );
    expect(flagLabel("js_rendered_suspected:10")).toBe(
      "Rendu JS suspecté en position 10 (page exclue)",
    );
  });

  test("maps js_rendered:<position> with the position interpolated", () => {
    expect(flagLabel("js_rendered:2")).toBe(
      "Rendu JS récupéré en position 2",
    );
    expect(flagLabel("js_rendered:10")).toBe(
      "Rendu JS récupéré en position 10",
    );
  });

  test("does not confuse js_rendered_suspected with js_rendered", () => {
    expect(flagLabel("js_rendered_suspected:2")).not.toBe(
      flagLabel("js_rendered:2"),
    );
  });

  test("falls back to the raw string for an unknown flag", () => {
    expect(flagLabel("some_future_flag")).toBe("some_future_flag");
  });
});
