import {
  hg38
} from "./chunk-7VB2BKXW.js";
import {
  sleep
} from "./chunk-DJQTUDJM.js";
import {
  require_tape
} from "./chunk-QWOE5YTB.js";
import {
  SearchHandler,
  vocabInit
} from "./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/geneVariant.integration.spec.ts
var import_tape = __toESM(require_tape(), 1);
async function getVocabApi() {
  const vocabApi2 = vocabInit({ state: { vocab: { genome: "hg38-test", dslabel: "TermdbTest" } } });
  if (!vocabApi2) throw "vocabApi is missing";
  await vocabApi2.getTermdbConfig();
  return vocabApi2;
}
var vocabApi = await getVocabApi();
var handler = new SearchHandler();
function getHolder() {
  const holder = select_default("body").append("div");
  return holder;
}
async function initializeSearchHandler(opts) {
  const callback = opts.callback || (() => {
  });
  await handler.init({
    holder: opts.holder,
    app: { vocabApi },
    genomeObj: hg38,
    callback
  });
}
(0, import_tape.default)("\n", function(test) {
  test.comment("-***- geneVariant search handler -***-");
  test.end();
});
(0, import_tape.default)("Search handler layout", async (test) => {
  const holder = getHolder();
  await initializeSearchHandler({ holder });
  const mutationTypeRadiosDiv = holder.select('[data-testid="sjpp-genevariant-mutationTypeRadios"]');
  test.ok(
    mutationTypeRadiosDiv.selectAll('input[type="radio"]').size() > 0,
    "Mutation type radio buttons should be present"
  );
  const inputTypeRadiosDiv = holder.select('[data-testid="sjpp-genevariant-genesetTypeRadios"]');
  test.equal(
    inputTypeRadiosDiv.selectAll('input[type="radio"]').size(),
    2,
    "Input type radio buttons should be present"
  );
  const searchDiv = holder.select('[data-testid="sjpp-genevariant-geneSearchDiv"]');
  test.equal(searchDiv.selectAll('input[type="search"]').size(), 1, "Gene search input should be present");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("Single gene input", async (test) => {
  let tw;
  const callback = (_tw) => {
    tw = _tw;
  };
  const holder = getHolder();
  await initializeSearchHandler({ holder, callback });
  const geneSearchInput = holder.select('[data-testid="sjpp-genevariant-geneSearchDiv"]').select('input[type="search"]').node();
  geneSearchInput.value = "TP53";
  geneSearchInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  await sleep(100);
  test.equal(tw.term.type, "geneVariant", "term.type should be geneVariant");
  test.equal(tw.q.type, "predefined-groupset", "q.type should be predefined-groupset");
  test.equal(tw.q.predefined_groupset_idx, 0, "q.predefined_groupset_idx should be 0");
  test.equal(tw.term.genes.length, 1, "term.genes[] should have length of 1");
  test.deepEqual(
    tw.term.genes[0],
    { kind: "gene", id: "TP53", gene: "TP53", name: "TP53", type: "geneVariant" },
    "term.genes[0] should have expected structure"
  );
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("Change mutation type", async (test) => {
  let tw;
  const callback = (_tw) => {
    tw = _tw;
  };
  const holder = getHolder();
  await initializeSearchHandler({ holder, callback });
  const mutationTypeRadiosDiv = holder.select('[data-testid="sjpp-genevariant-mutationTypeRadios"]');
  const mutationTypeRadios = mutationTypeRadiosDiv.selectAll('input[type="radio"]');
  const thirdRadio = mutationTypeRadios.nodes()[2];
  thirdRadio.click();
  const inputTypeRadiosDiv = holder.select('[data-testid="sjpp-genevariant-genesetTypeRadios"]');
  const geneSetDiv = inputTypeRadiosDiv.selectAll("div").filter((d) => d.value == "geneset");
  test.equal(geneSetDiv.style("display"), "none", "Gene set option should be hidden for CNV");
  const geneSearchInput = holder.select('[data-testid="sjpp-genevariant-geneSearchDiv"]').select('input[type="search"]').node();
  geneSearchInput.value = "TP53";
  geneSearchInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  await sleep(100);
  test.equal(tw.q.predefined_groupset_idx, 2, "q.predefined_groupset_idx should be 2 upon selecting third radio button");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("Gene set input", async (test) => {
  let tw;
  const callback = (_tw) => {
    tw = _tw;
  };
  const holder = getHolder();
  await initializeSearchHandler({ holder, callback });
  const inputTypeRadiosDiv = holder.select('[data-testid="sjpp-genevariant-genesetTypeRadios"]');
  const inputTypeRadios = inputTypeRadiosDiv.selectAll('input[type="radio"]');
  const secondRadio = inputTypeRadios.nodes()[1];
  secondRadio.click();
  const geneSearchInput = holder.select('[data-testid="sjpp-genevariant-geneSearchDiv"]').select('input[type="search"]').node();
  geneSearchInput.value = "TP53";
  geneSearchInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  await sleep(100);
  geneSearchInput.value = "KRAS";
  geneSearchInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  const buttons = holder.select('[data-testid="sjpp-genevariant-geneSearchDiv"]').selectAll("button").nodes();
  const submitButton = buttons.find((btn) => btn.textContent.trim() === "Submit");
  await sleep(100);
  submitButton.click();
  await sleep(100);
  test.equal(tw.term.genes.length, 2, "term.genes[] should have length of 2");
  test.equal(tw.term.name, "TP53, KRAS", "term.name should concatenate gene names");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("Gene set input - custom name", async (test) => {
  let tw;
  const callback = (_tw) => {
    tw = _tw;
  };
  const holder = getHolder();
  await initializeSearchHandler({ holder, callback });
  const inputTypeRadiosDiv = holder.select('[data-testid="sjpp-genevariant-genesetTypeRadios"]');
  const inputTypeRadios = inputTypeRadiosDiv.selectAll('input[type="radio"]');
  const secondRadio = inputTypeRadios.nodes()[1];
  secondRadio.click();
  const geneSearchInput = holder.select('[data-testid="sjpp-genevariant-geneSearchDiv"]').select('input[type="search"]').node();
  geneSearchInput.value = "TP53";
  geneSearchInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  await sleep(100);
  geneSearchInput.value = "KRAS";
  geneSearchInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  await sleep(100);
  const nameInput = holder.select('[data-testid="sja_genesetinput_name"]').node();
  nameInput.value = "Test gene set";
  const buttons = holder.select('[data-testid="sjpp-genevariant-geneSearchDiv"]').selectAll("button").nodes();
  const submitButton = buttons.find((btn) => btn.textContent.trim() === "Submit");
  await sleep(100);
  submitButton.click();
  await sleep(100);
  test.equal(tw.term.genes.length, 2, "term.genes[] should have length of 2");
  test.equal(tw.term.name, "Test gene set", "term.name should be custom name");
  if (test["_ok"]) holder.remove();
  test.end();
});
//# sourceMappingURL=geneVariant.integration.spec-2C7EWKEV.js.map
