import {
  SearchHandler
} from "./chunk-72X7LSBN.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 {
  SINGLECELL_CELLTYPE
} from "./chunk-NOEAT6CX.js";
import {
  TermTypeGroups
} from "./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/singleCellCellType.unit.spec.ts
var import_tape = __toESM(require_tape(), 1);
function getHolder() {
  return select_default("body").append("div");
}
function getUsecase(plotName = "Plot A") {
  return {
    target: "sampleScatter",
    detail: "term",
    specialCase: {
      config: { name: plotName }
    }
  };
}
(0, import_tape.default)("\n", function(test) {
  test.comment("-***- termdb/handlers/singleCellCellType -***-");
  test.end();
});
(0, import_tape.default)("validateOpts() should require callback, termType2terms, and specialCase.config.name", (test) => {
  const handler = new SearchHandler();
  const holder = getHolder();
  test.throws(
    () => handler.validateOpts({
      holder,
      app: { vocabApi: { termdbConfig: { termType2terms: {} } } },
      usecase: getUsecase("Plot A")
    }),
    /callback is required/,
    "Should throw when callback is missing"
  );
  test.throws(
    () => handler.validateOpts({
      holder,
      callback: () => {
      },
      app: { vocabApi: { termdbConfig: {} } },
      usecase: getUsecase("Plot A")
    }),
    /termType2terms is required in termdbConfig for singleCellCellType handler/,
    "Should throw when termType2terms is missing"
  );
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("init() should render only terms matching usecase plot and call callback on click", async (test) => {
  const handler = new SearchHandler();
  const holder = getHolder();
  let selectedTerm;
  const scctTerms = [
    { id: "t1", name: "Myeloid", type: SINGLECELL_CELLTYPE, plot: "Plot A" },
    { id: "t2", name: "Lymphoid", type: SINGLECELL_CELLTYPE, plot: "Plot A" },
    { id: "t3", name: "Nonmatching", type: SINGLECELL_CELLTYPE, plot: "Plot B" }
  ];
  await handler.init({
    holder,
    callback: (t) => {
      selectedTerm = t;
    },
    app: {
      vocabApi: {
        termdbConfig: {
          termType2terms: {
            [TermTypeGroups.SINGLECELL_CELLTYPE]: scctTerms
          }
        }
      }
    },
    usecase: getUsecase("Plot A")
  });
  const labels = holder.selectAll(".termlabel");
  test.equal(labels.size(), 2, "Should render only two matching terms for Plot A");
  test.deepEqual(
    labels.nodes().map((n) => n.textContent),
    ["Myeloid", "Lymphoid"],
    "Should render labels in the filtered order"
  );
  const firstLabel = labels.nodes()[0];
  firstLabel.click();
  test.equal(selectedTerm?.id, "t1", "Should pass clicked term object to callback");
  test.equal(selectedTerm?.type, SINGLECELL_CELLTYPE, "Callback term type should be singleCellCellType");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("init() should render sayerror when termType2terms key is missing for singleCellCellType", async (test) => {
  const handler = new SearchHandler();
  const holder = getHolder();
  await handler.init({
    holder,
    callback: () => {
    },
    app: {
      vocabApi: {
        termdbConfig: {
          termType2terms: {
            [TermTypeGroups.DICTIONARY_VARIABLES]: []
          }
        }
      }
    },
    usecase: getUsecase("Plot A")
  });
  const errorDiv = holder.select(".sja_errorbar").node();
  test.ok(errorDiv, "Should render an error message when singleCellCellType terms are missing");
  test.ok(
    holder.text().includes(
      `termType2terms[${TermTypeGroups.SINGLECELL_CELLTYPE}]:[] is required in termdbConfig for singleCellCellType handler`
    ),
    "Should show expected configuration error text"
  );
  test.equal(holder.selectAll(".termlabel").size(), 0, "Should not render term labels when config is missing");
  if (test["_ok"]) holder.remove();
  test.end();
});
//# sourceMappingURL=singleCellCellType.unit.spec-RU4RJXFF.js.map
