// TRACES: UR-067 | DR-117

import { describe, it, expect } from "vitest";
import {
  FAVORITE_SCOPES,
  FAVORITE_SCOPE_LABELS,
  resolveFavoritesScope,
  favoritesRouteUrl,
  emptyStateMessage,
} from "./favoritesView";

describe("favoritesView", () => {
  describe("resolveFavoritesScope", () => {
    it("round-trips every offered tab", () => {
      for (const scope of FAVORITE_SCOPES) {
        expect(resolveFavoritesScope(scope)).toBe(scope);
      }
    });

    it("defaults to All for a missing param", () => {
      expect(resolveFavoritesScope(null)).toBe("all");
      expect(resolveFavoritesScope(undefined)).toBe("all");
      expect(resolveFavoritesScope("")).toBe("all");
    });

    it("defaults to All for a stale or hand-edited param rather than blanking the page", () => {
      expect(resolveFavoritesScope("books")).toBe("all");
      expect(resolveFavoritesScope("MOVIES")).toBe("all");
    });
  });

  describe("favoritesRouteUrl", () => {
    it("omits the default scope so the base URL stays clean", () => {
      expect(favoritesRouteUrl("all")).toBe("/library/favorites");
    });

    it("addresses every other tab explicitly, and round-trips through resolve", () => {
      for (const scope of FAVORITE_SCOPES) {
        const url = favoritesRouteUrl(scope);
        const param = new URL(url, "http://x").searchParams.get("scope");
        expect(resolveFavoritesScope(param)).toBe(scope);
      }
    });
  });

  it("labels every scope, using the app's vocabulary rather than Jellyfin's", () => {
    for (const scope of FAVORITE_SCOPES) {
      expect(FAVORITE_SCOPE_LABELS[scope]).toBeTruthy();
    }
    // "tv" is the backend's scope name; users see "Shows".
    expect(FAVORITE_SCOPE_LABELS.tv).toBe("Shows");
  });

  it("gives each tab its own empty state, telling the user what to do next", () => {
    for (const scope of FAVORITE_SCOPES) {
      expect(emptyStateMessage(scope)).toContain("heart");
    }
    expect(emptyStateMessage("movies")).toContain("movies");
  });
});
