import ContentIndexModel from "../ContentIndexModel";

import data from "./content-index.json";
import contributions from "./content-index-contributions.json";
import ModularUIResponse from "../../../modularui/ModularUIResponse";
import ContentLinkModel from "../ContentLinkModel";

describe("content index model", () => {
  it("should be able to create an empty ContentIndexModel object", () => {
    const model = new ContentIndexModel();

    expect(model).toBeInstanceOf(ContentIndexModel);
    expect(model.type).toBe("ContentIndex");
  });

  it("can handle a search result", () => {
    const response = ModularUIResponse.create({
      key: "contentindexmodel",
      data,
      contributions,
    });

    expect(ContentIndexModel.isApplicableModel(response)).toBe(true);

    const contentIndexModel = new ContentIndexModel(response);
    expect(contentIndexModel.label).toBe("content");

    expect(contentIndexModel.items).toHaveLength(1);

    const firstLink = contentIndexModel.items.first;
    expect(firstLink).toBeInstanceOf(ContentLinkModel);

    expect(firstLink.label).toBe("Another formal content");
    expect(firstLink.abbreviation).toBe("AFC-01");

    expect(firstLink.encodedHref.toString()).toBe(
      "/content/Content%2FSources%2FFormal%2FAnother%2520formal%2520content.formalsource",
    );
  });
});
