import { createHref } from "../createHref";
import Href from "../../../models/href/Href";

describe("createHref", () => {
  it("can filter out qs parameters", () => {
    const dynamicPart = "project/folder/model.bixml/ConceptId";
    const location = {
      search: "?entryDate=2024-03-08&index=C&notAllowed=true",
    };
    const expectedSearch = "?index=C&notAllowed=true&entryDate=2010-01-01";

    expect(createHref("concepts", dynamicPart)).toEqual(
      new Href("/concepts/" + dynamicPart),
    );
    expect(createHref("concepts", dynamicPart, "2010-01-01", location)).toEqual(
      new Href("/concepts/" + dynamicPart + expectedSearch),
    );
    expect(
      createHref("concepts", dynamicPart, "2010-01-01", location, ["index"]),
    ).toEqual(
      new Href("/concepts/" + dynamicPart + "?index=C&entryDate=2010-01-01"),
    );
    expect(
      createHref(
        "concepts",
        dynamicPart + location.search,
        "2010-01-01",
        location,
        ["index"],
      ),
    ).toEqual(
      new Href("/concepts/" + dynamicPart + "?index=C&entryDate=2010-01-01"),
    );

    expect(createHref("concepts", dynamicPart + "#hash")).toEqual(
      new Href("/concepts/" + dynamicPart + "#hash"),
    );
  });
});
