import {
  getRunPp
} from "./chunk-W55XSG6K.js";
import {
  require_tape
} from "./chunk-QWOE5YTB.js";
import "./chunk-74ZU4BT6.js";
import "./chunk-IW57W7EQ.js";
import "./chunk-ZTYNN6G5.js";
import "./chunk-DKVUOBIE.js";
import "./chunk-PRZWSBMA.js";
import "./chunk-LTOBEUM2.js";
import "./chunk-MKAF2BHB.js";
import "./chunk-WKNI3HRQ.js";
import "./chunk-VGYTAYFK.js";
import "./chunk-67DBIM6H.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 {
  selectAll_default
} from "./chunk-I6Y4O3RR.js";
import "./chunk-OMR2DT66.js";
import "./chunk-DQC5FFGV.js";
import {
  __toESM
} from "./chunk-HFNDKYVF.js";

// plots/test/sampleScatter.spec.js
var import_tape = __toESM(require_tape(), 1);
var runpp = getRunPp("mass", {
  state: {
    vocab: {
      dslabel: "PNET",
      genome: "hg19"
    }
  },
  debug: 1
});
function sleep(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}
var state = {
  plots: [
    {
      chartType: "sampleScatter",
      colorTW: { id: "TSNE Category" },
      name: "Methylome TSNE"
    }
  ]
};
var open_state = {
  nav: { header_mode: "hide_search" },
  plots: [
    {
      chartType: "sampleScatter",
      colorTW: { id: "TSNE Category" },
      name: "Methylome TSNE"
    }
  ]
};
(0, import_tape.default)("\n", function(test) {
  test.comment("-***- mass/sampleScatter -***-");
  test.end();
});
(0, import_tape.default)("PNET plot + filter + colorTW=gene", function(test) {
  test.timeoutAfter(3e3);
  test.plan(1);
  const s2 = JSON.parse(JSON.stringify(state));
  s2.termfilter = {
    filter: {
      type: "tvslst",
      join: "",
      in: true,
      lst: [{ type: "tvs", tvs: { term: { id: "Gender" }, values: [{ key: "M", label: "Male" }] } }]
    }
  };
  s2.plots[0].colorTW = { term: { type: "geneVariant", name: "TP53", gene: "TP53" } };
  runpp({
    state: s2,
    sampleScatter: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  function runTests(scatter) {
    testPlot();
    if (test._ok) scatter.Inner.app.destroy();
    test.end();
    function testPlot() {
      const scatterDiv = scatter.Inner.model.charts[0].chartDiv;
      const serieG = scatterDiv.select(".sjpcb-scatter-series");
      const numSymbols = serieG.selectAll("path").size();
      console.log(numSymbols == scatter.Inner.model.charts[0].data.samples.length);
      test.true(
        numSymbols == scatter.Inner.model.charts[0].data.samples.length,
        `Should be ${scatter.Inner.model.charts[0].data.samples.length}. Rendered ${numSymbols} symbols.`
      );
    }
  }
});
import_tape.default.skip("Add shape, clicking term and replace by search", function(test) {
  test.timeoutAfter(8e3);
  runpp({
    state: open_state,
    sampleScatter: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  const origTerm = "TSNE Category";
  const testTerm = "Mutational Burden";
  async function runTests(scatter) {
    scatter.on("postRender.test", null);
    await sleep(500);
    triggerAddBtn(scatter);
    await sleep(300);
    triggerPillChange();
    await sleep(100);
    testShapeRendering(scatter, testTerm);
    await sleep(500);
    triggerShapeReplace();
    await sleep(300);
    changeShapeBySearch();
    await sleep(100);
    testShapeRendering(scatter, origTerm);
    if (test._ok) scatter.Inner.app.destroy();
    test.end();
  }
  function triggerAddBtn(scatter) {
    const addBtn = scatter.Inner.view.dom.controls.selectAll("div").nodes().find((c) => c.style.display == "block" && c?.childNodes[1]?.innerHTML == "+");
    addBtn.dispatchEvent(new Event("click"));
  }
  function triggerPillChange() {
    selectAll_default(".ts_pill").filter((d) => d.name == testTerm).node().click();
  }
  function testShapeRendering(scatter, term) {
    const shapeLegend = scatter.Inner.model.charts[0].chartDiv.selectAll("g").nodes().find((c) => c?.childNodes[0].innerHTML == term);
    let groups = [];
    for (const [i, group] of shapeLegend.childNodes.entries()) {
      if (i == 0) continue;
      const label = group.childNodes[1].innerHTML.split(",");
      groups.push({
        label: label[0],
        samples: label[1].match(/[\d\.]+/g)
        //Maybe test all samples rendered?
      });
    }
    test.ok(
      scatter.Inner.shapeLegend.size == groups.length + 1,
      `Legend categories (# = ${groups.length + 1}) should equal size of shapeLegend (# = ${scatter.Inner.shapeLegend.size}) `
    );
    compareData2DOMLegend(scatter, groups);
  }
  function compareData2DOMLegend(scatter, groups) {
    for (const group of groups) {
      const mapLeg = scatter.Inner.shapeLegend.get(group.label);
      test.ok(
        mapLeg.sampleCount == group.samples[0],
        `Should show matching n = ${mapLeg.sampleCount} for ${group.label}. Legend: n = ${group.samples[0]}`
      );
    }
  }
  function triggerShapeReplace() {
    selectAll_default(".ts_pill").filter((d) => d.name == testTerm).node().click();
    selectAll_default(".sja_sharp_border").filter((d) => d.label == "Replace").node().click();
  }
  async function changeShapeBySearch() {
    const termSearchDiv = selectAll_default(".tree_search").nodes().find((e) => e.placeholder.endsWith("genes"));
    termSearchDiv.value = origTerm;
    termSearchDiv.dispatchEvent(new Event("input"));
    await sleep(1e3);
    selectAll_default(".sja_tree_click_term").filter((d) => d.name == origTerm).node().click();
  }
});
//# sourceMappingURL=sampleScatter.spec-CD52FEOC.js.map
