import {
  hg38
} from "./chunk-7VB2BKXW.js";
import {
  SearchHandler
} from "./chunk-2XCUERHJ.js";
import {
  sleep
} from "./chunk-DJQTUDJM.js";
import {
  require_tape
} from "./chunk-QWOE5YTB.js";
import {
  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 {
  TermTypes
} from "./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/dnaMethylation.integration.spec.ts
var import_tape = __toESM(require_tape(), 1);
var vocabApi = await getVocabApi();
var handler = new SearchHandler();
(0, import_tape.default)("\n", function(test) {
  test.comment("-***- dnaMethylation search handler -***-");
  test.end();
});
(0, import_tape.default)("Search handler layout", async (test) => {
  const holder = getHolder();
  await initializeSearchHandler({ holder });
  const geneSearchInput = holder.select(".sja_genesearchinput").node();
  test.ok(geneSearchInput, "should display gene search input");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("Coordinate search", async (test) => {
  let term;
  const callback = (_term) => {
    term = _term;
  };
  const holder = getHolder();
  await initializeSearchHandler({ holder, callback });
  const geneSearchInput = holder.select(".sja_genesearchinput").node();
  const chr = "chr17";
  const start = 7661778;
  const stop = 7687537;
  const coord = `${chr}:${start}-${stop}`;
  geneSearchInput.value = coord;
  geneSearchInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  await sleep(100);
  test.equal(term.chr, chr, "term.chr should equal input chr");
  test.equal(term.start, start, "term.start should equal input start");
  test.equal(term.stop, stop, "term.stop should equal input stop");
  test.equal(term.type, TermTypes.DNA_METHYLATION, "term.type should be dnaMethylation");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("Single position search (chr:pos format)", async (test) => {
  let term;
  const callback = (_term) => {
    term = _term;
  };
  const holder = getHolder();
  await initializeSearchHandler({ holder, callback });
  const geneSearchInput = holder.select(".sja_genesearchinput").node();
  geneSearchInput.value = "chr17:7669073";
  geneSearchInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  await sleep(100);
  test.equal(term.chr, "chr17", "term.chr should equal input chr");
  test.equal(term.start, 7669073, "term.start should be exact position, not 400bp-expanded");
  test.equal(term.stop, 7669074, "term.stop should be start+1 for a single CpG site");
  test.equal(term.type, TermTypes.DNA_METHYLATION, "term.type should be dnaMethylation");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("Single position search (chr:pos-pos format)", async (test) => {
  let term;
  const callback = (_term) => {
    term = _term;
  };
  const holder = getHolder();
  await initializeSearchHandler({ holder, callback });
  const geneSearchInput = holder.select(".sja_genesearchinput").node();
  geneSearchInput.value = "chr17:7669073-7669073";
  geneSearchInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  await sleep(100);
  test.equal(term.chr, "chr17", "term.chr should equal input chr");
  test.equal(term.start, 7669073, "term.start should be exact position, not 400bp-expanded");
  test.equal(term.stop, 7669074, "term.stop should be start+1 for a single CpG site");
  test.equal(term.type, TermTypes.DNA_METHYLATION, "term.type should be dnaMethylation");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("Gene search", async (test) => {
  let term;
  const callback = (_term) => {
    term = _term;
  };
  const holder = getHolder();
  await initializeSearchHandler({ holder, callback });
  const geneSearchInput = holder.select(".sja_genesearchinput").node();
  const geneSymbol = "TP53";
  geneSearchInput.value = geneSymbol;
  geneSearchInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  await sleep(100);
  const blockSvg = holder.select('[data-testid="sjpp_block_svg"]').node();
  test.ok(blockSvg, "should render block svg");
  const submitBtn = holder.select('[data-testid="sjpp-dnaMethylation-submitDiv"]').select("button").node();
  submitBtn.click();
  await sleep(100);
  test.equal(term.chr, "chr17", "term.chr should be TP53 chr");
  test.equal(term.start, 7661778, "term.start should be TP53 start");
  test.equal(term.stop, 7687537, "term.stop should be TP53 stop");
  test.equal(term.type, TermTypes.DNA_METHYLATION, "term.type should be dnaMethylation");
  if (test["_ok"]) holder.remove();
  test.end();
});
(0, import_tape.default)("Gene search with navigation", async (test) => {
  let term;
  const callback = (_term) => {
    term = _term;
  };
  const holder = getHolder();
  await initializeSearchHandler({ holder, callback });
  const geneSearchInput = holder.select(".sja_genesearchinput").node();
  const geneSymbol = "TP53";
  geneSearchInput.value = geneSymbol;
  geneSearchInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  await sleep(1e3);
  const blockCoordInput = holder.select(".sja_Block_div").select("input").node();
  const chr = "chr17";
  const start = 7682350;
  const stop = 7684350;
  const coord = `${chr}:${start}-${stop}`;
  blockCoordInput.value = coord;
  blockCoordInput.dispatchEvent(new KeyboardEvent("keyup", { key: "Enter", code: "Enter", bubbles: true }));
  await sleep(1e3);
  const submitBtn = holder.select('[data-testid="sjpp-dnaMethylation-submitDiv"]').select("button").node();
  submitBtn.click();
  await sleep(100);
  test.equal(term.chr, chr, "term.chr should equal input chr");
  test.equal(term.start, 7682349, "term.start should equal input start");
  test.equal(term.stop, 7684349, "term.stop should equal input stop");
  test.equal(term.type, TermTypes.DNA_METHYLATION, "term.type should be dnaMethylation");
  if (test["_ok"]) holder.remove();
  test.end();
});
async function getVocabApi() {
  const vocabApi2 = vocabInit({ state: { vocab: { genome: "hg38-test", dslabel: "TermdbTest" } } });
  if (!vocabApi2) throw "vocabApi is missing";
  await vocabApi2.getTermdbConfig();
  return vocabApi2;
}
function getHolder() {
  const holder = select_default("body").append("div");
  return holder;
}
async function initializeSearchHandler(opts) {
  const callback = opts.callback || (() => {
  });
  const hg38_copy = structuredClone(hg38);
  hg38_copy.hasSNP = false;
  await handler.init({
    holder: opts.holder,
    app: { vocabApi },
    genomeObj: hg38_copy,
    callback
  });
}
//# sourceMappingURL=dnaMethylation.integration.spec-DO3PV4MO.js.map
