import {
  SearchHandler
} from "./chunk-54EMVNPW.js";
import {
  require_tape
} from "./chunk-QWOE5YTB.js";
import "./chunk-SA7APTJR.js";
import "./chunk-HJ6L54YS.js";
import "./chunk-LSEFWW72.js";
import "./chunk-SKREEF3H.js";
import "./chunk-HYOEWQ5P.js";
import "./chunk-HBW42TDT.js";
import "./chunk-G6O3URDN.js";
import "./chunk-FN5XPUPH.js";
import "./chunk-IIT367QZ.js";
import "./chunk-RZGEKL77.js";
import "./chunk-UI7OCM2A.js";
import "./chunk-YZK37YCC.js";
import "./chunk-7EMWHCVW.js";
import "./chunk-7IYJZZQI.js";
import "./chunk-M3J4MINX.js";
import "./chunk-PF4DSFDR.js";
import "./chunk-QH6W3NVF.js";
import "./chunk-NOEAT6CX.js";
import "./chunk-4UWS5Y3N.js";
import "./chunk-DD4R5P6W.js";
import "./chunk-JNITUVXP.js";
import "./chunk-KSGA62R2.js";
import "./chunk-LOZEKOES.js";
import "./chunk-TOU7EVFQ.js";
import "./chunk-OAWQ6LOO.js";
import "./chunk-TLT4YIG3.js";
import "./chunk-KYBIQBXE.js";
import {
  select_default
} from "./chunk-I6Y4O3RR.js";
import "./chunk-OMR2DT66.js";
import "./chunk-DQC5FFGV.js";
import {
  __toESM
} from "./chunk-HFNDKYVF.js";

// termdb/handlers/test/termCollection.unit.spec.ts
var import_tape = __toESM(require_tape(), 1);
function getHolder() {
  return select_default("body").append("div");
}
function getTermCollectionDetails(overrides = {}) {
  return {
    name: "Test Collection",
    type: "gene",
    memberType: "gene",
    termlst: [
      { id: "gene1", name: "TP53", values: { tissue: "Lung" } },
      { id: "gene2", name: "KRAS", values: { tissue: "Colon" } },
      { id: "gene3", name: "BRCA1", values: { tissue: "Breast" } }
    ],
    categoryKeys: [
      { key: "tissue", shown: true },
      { key: "expression", shown: false }
    ],
    propsByTermId: {
      gene1: { color: "#FF0000" },
      gene2: { color: "#00FF00" }
    },
    ...overrides
  };
}
(0, import_tape.default)("\n", function(test) {
  test.comment("-***- termdb/handlers/termCollection -***-");
  test.end();
});
(0, import_tape.default)("init() should render term list table with all terms from details.termlst", async (test) => {
  const handler = new SearchHandler();
  const holder = getHolder();
  const details = getTermCollectionDetails();
  await handler.init({
    holder,
    callback: () => {
    },
    app: {},
    details
  });
  const table = holder.select("table");
  test.ok(table.node(), "Should render a table");
  const rows = table.selectAll("tbody tr");
  test.equal(rows.size(), 3, "Should render three rows for three terms");
  const rowTexts = rows.nodes().map((row) => row.textContent.trim());
  test.ok(rowTexts[0].includes("TP53"), "First row should contain TP53");
  test.ok(rowTexts[1].includes("KRAS"), "Second row should contain KRAS");
  test.ok(rowTexts[2].includes("BRCA1"), "Third row should contain BRCA1");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("init() should render category table when details.categoryKeys is present", async (test) => {
  const handler = new SearchHandler();
  const holder = getHolder();
  const details = getTermCollectionDetails();
  await handler.init({
    holder,
    callback: () => {
    },
    app: {},
    details
  });
  const tables = holder.selectAll("table");
  test.equal(tables.size(), 2, "Should render two tables when categoryKeys is present");
  const categoryTable = tables.nodes()[1];
  const categoryRows = select_default(categoryTable).selectAll("tbody tr");
  test.equal(categoryRows.size(), 2, "Should render two rows for two categories");
  const categoryTexts = categoryRows.nodes().map((row) => row.textContent.trim());
  test.ok(categoryTexts[0].includes("tissue"), "Should display tissue category key");
  test.ok(categoryTexts[1].includes("expression"), "Should display expression category key");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("init() should call callback with selected terms, categoryKeys, and properties", async (test) => {
  const handler = new SearchHandler();
  const holder = getHolder();
  const details = getTermCollectionDetails();
  let callbackResult;
  await handler.init({
    holder,
    callback: (result) => {
      callbackResult = result;
    },
    app: {},
    details
  });
  const termsTable = holder.selectAll("table").nodes()[0];
  const checkboxes = termsTable.querySelectorAll('tbody input[type="checkbox"]');
  checkboxes[0].checked = true;
  checkboxes[1].checked = true;
  checkboxes[2].checked = false;
  const categoryTable = holder.selectAll("table").nodes()[1];
  const categoryCheckboxes = categoryTable.querySelectorAll('tbody input[type="checkbox"]');
  categoryCheckboxes[0].checked = true;
  categoryCheckboxes[1].checked = false;
  const selectBtn = holder.select("button.sjpp_apply_btn").node();
  selectBtn.click();
  test.equal(callbackResult?.type, "termCollection", "Should set type to termCollection");
  test.equal(callbackResult?.name, "Test Collection", "Should pass collection name");
  test.equal(callbackResult?.memberType, "gene", "Should pass memberType");
  test.deepEqual(callbackResult?.termIds, ["gene1", "gene2"], "Should pass selected term IDs");
  test.equal(callbackResult?.termlst.length, 2, "Should pass selected term list with correct length");
  test.equal(callbackResult?.termlst[0].name, "TP53", "First selected term should be TP53");
  test.equal(callbackResult?.termlst[1].name, "KRAS", "Second selected term should be KRAS");
  test.deepEqual(
    callbackResult?.categoryKeys,
    [
      { key: "tissue", shown: true },
      { key: "expression", shown: false }
    ],
    "Should pass updated categoryKeys with shown status"
  );
  test.deepEqual(
    callbackResult?.propsByTermId,
    { gene1: { color: "#FF0000" }, gene2: { color: "#00FF00" } },
    "Should pass propsByTermId for selected terms only"
  );
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("init() should not render category table when details.categoryKeys is missing", async (test) => {
  const handler = new SearchHandler();
  const holder = getHolder();
  const details = getTermCollectionDetails({ categoryKeys: void 0 });
  await handler.init({
    holder,
    callback: () => {
    },
    app: {},
    details
  });
  const tables = holder.selectAll("table");
  test.equal(tables.size(), 1, "Should render only one table when categoryKeys is missing");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("init() should show alert when no terms are selected", async (test) => {
  const handler = new SearchHandler();
  const holder = getHolder();
  const details = getTermCollectionDetails();
  let alertCalled = false;
  const originalAlert = window.alert;
  window.alert = () => {
    alertCalled = true;
  };
  await handler.init({
    holder,
    callback: () => test.fail("Callback should not be called when no terms selected"),
    app: {},
    details
  });
  const termsTable = holder.selectAll("table").nodes()[0];
  const checkboxes = termsTable.querySelectorAll('tbody input[type="checkbox"]');
  for (const cb of checkboxes) {
    ;
    cb.checked = false;
  }
  const selectBtn = holder.select("button.sjpp_apply_btn").node();
  selectBtn.click();
  test.ok(alertCalled, "Should show alert when no terms are selected");
  window.alert = originalAlert;
  if (test["_ok"]) holder.remove();
  test.end();
});
//# sourceMappingURL=termCollection.unit.spec-5JBCTXHX.js.map
