import {
  detectOne,
  detectStyle
} from "./chunk-DJQTUDJM.js";
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 "./chunk-I6Y4O3RR.js";
import "./chunk-OMR2DT66.js";
import "./chunk-DQC5FFGV.js";
import {
  __toESM
} from "./chunk-HFNDKYVF.js";

// plots/test/summary.integration.spec.js
var import_tape = __toESM(require_tape(), 1);
var runpp = getRunPp("mass", {
  state: {
    nav: {
      header_mode: "hide_search",
      activeTab: 1
    },
    vocab: {
      dslabel: "TermdbTest",
      genome: "hg38-test"
    }
  },
  debug: 1
});
var tabLabels2Find = ["Barchart", "Violin", "Boxplot"];
(0, import_tape.default)("\n", function(test) {
  test.comment("-***- plots/summary -***-");
  test.end();
});
(0, import_tape.default)('Render summary plot, term: "agedx"', (test) => {
  test.timeoutAfter(6e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "summary",
          childType: "barchart",
          term: {
            id: "agedx"
          }
        }
      ]
    },
    summary: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(summary) {
    summary.on("postRender.test", null);
    testHeader(summary, summary.Inner.dom);
    await testToggleButtons(summary, summary.Inner.dom);
    await testOrientation(summary);
    if (test._ok) summary.Inner.app.destroy();
    test.end();
  }
  function testHeader(summary, dom) {
    const headerText = dom.paneTitleDiv.select("div.sjpp-term-header").node();
    const configTerm = summary.Inner.config.term.term.name;
    test.equal(
      headerText.innerHTML,
      configTerm,
      `Header text = ${headerText.innerHTML} should match term name = ${configTerm}`
    );
  }
  async function testToggleButtons(summary, dom) {
    const toggles = dom.chartToggles.selectAll("div > div> button").nodes().filter((d) => d.__data__.isVisible() == true);
    let foundLabels = 0;
    const notFoundLabels = [];
    for (const toggle of toggles) {
      if (tabLabels2Find.some((d) => d == toggle.__data__.label)) ++foundLabels;
      else notFoundLabels.push(toggle.__data__.label);
    }
    if (notFoundLabels.length) test.fail(`Should not render tab(s) = ${notFoundLabels}`);
    test.equal(tabLabels2Find.length, foundLabels, `Should render tabs: ${tabLabels2Find}`);
    const foundTestPlot = await detectOne({
      elem: summary.Inner.dom.holder.body.node(),
      selector: ".sjpp-violin-plot",
      trigger() {
        toggles.find((d) => d.__data__.childType == "violin").click();
      }
    });
    test.ok(foundTestPlot, `Should render violin after toggle`);
    test.equal(summary.Inner.state.config.childType, "violin", `Should toggle to childType = violin`);
    await detectStyle({
      elem: summary.Inner.dom.plotDivs.barchart.node(),
      matcher(mutations) {
        for (const m of mutations) {
          if (m.attributeName == "style" && m.target.style.display === "") return m;
        }
      },
      trigger() {
        toggles.find((d) => d.__data__.childType == "barchart").click();
      }
    });
    test.equal(summary.Inner.state.config.childType, "barchart", `Should toggle back to childType = 'barchart'`);
  }
  async function testOrientation(summary) {
    await summary.Inner.app.dispatch({
      type: "plot_edit",
      id: summary.Inner.id,
      config: {
        settings: { barchart: { orientation: "vertical" } }
      }
    });
    test.notEqual(
      summary.Inner.config.settings.barchart.orientation,
      summary.Inner.config.settings.violin.orientation,
      `Orientation change for barchart should not affect violin`
    );
  }
});
(0, import_tape.default)('Barchart tab only, term: "diaggrp"', (test) => {
  test.timeoutAfter(3e3);
  const message = `Should only show barchart tab in header`;
  runpp({
    state: {
      plots: [
        {
          chartType: "summary",
          childType: "barchart",
          term: {
            id: "diaggrp"
          }
        }
      ]
    },
    summary: {
      callbacks: {
        "postRender.test": runTest
      }
    }
  });
  async function runTest(summary) {
    const toggles = summary.Inner.dom.chartToggles.selectAll("div > div> button").nodes().filter((d) => d.__data__.isVisible() == true);
    test.ok(toggles.length == 1, `Should only render one tab`);
    if (toggles[0].__data__.childType == "barchart") test.pass(message);
    else test.fail(message);
    if (test._ok) summary.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)('Barchart & violin toggles, term: "diaggrp", term2: "agedx"', (test) => {
  test.timeoutAfter(3e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "summary",
          childType: "barchart",
          term: {
            id: "diaggrp"
          },
          term2: {
            id: "agedx"
          }
        }
      ]
    },
    summary: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(summary) {
    summary.on("postRender.test", null);
    await detectOne({ elem: summary.Inner.dom.holder.body.node(), selector: ".pp-bars-svg" });
    await testToggleButtons(summary, summary.Inner.dom);
    if (test._ok) summary.Inner.app.destroy();
    test.end();
  }
  async function testToggleButtons(summary, dom) {
    const toggles = dom.chartToggles.selectAll("div > div> button").nodes().filter((d) => d.__data__.isVisible() == true);
    toggles.find((d) => d.__data__.childType == "violin").click();
    const foundTestPlot = await detectOne({
      elem: dom.holder.body.node(),
      selector: ".sjpp-violin-plot"
    });
    test.ok(foundTestPlot, `Should render violin after toggle`);
    test.equal(summary.Inner.state.config.childType, "violin", `Should toggle to childType = violin`);
    await detectStyle({
      elem: dom.plotDivs.barchart.node(),
      matcher(mutations) {
        for (const m of mutations) {
          if (m.attributeName == "style" && m.target.style.display === "") return m;
        }
      },
      trigger() {
        toggles.find((d) => d.__data__.childType == "barchart").click();
      }
    });
    test.equal(summary.Inner.state.config.childType, "barchart", `Should toggle back to childType = 'barchart'`);
  }
});
(0, import_tape.default)('Barchart & violin toggles, term: "agedx", term2: "diaggrp"', (test) => {
  test.timeoutAfter(3e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "summary",
          childType: "barchart",
          term: {
            id: "agedx"
          },
          term2: {
            id: "diaggrp"
          }
        }
      ]
    },
    summary: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(summary) {
    summary.on("postRender.test", null);
    const toggles = summary.Inner.dom.chartToggles.selectAll("div > div> button").nodes().filter((d) => d.__data__.isVisible() == true);
    testToggleButtonRendering(toggles);
    await testToggleButtons(summary, toggles);
    if (test._ok) summary.Inner.app.destroy();
    test.end();
  }
  function testToggleButtonRendering(toggles) {
    let foundLabels = 0;
    for (const toggle of toggles) {
      if (tabLabels2Find.some((d) => d == toggle.__data__.label)) ++foundLabels;
    }
    test.equal(
      tabLabels2Find.length,
      toggles.length,
      `Should render ${tabLabels2Find.length} tabs: ${tabLabels2Find} for <2 numeric terms`
    );
  }
  async function testToggleButtons(summary, toggles) {
    toggles.find((d) => d.__data__.childType == "violin").click();
    const foundTestPlot = await detectOne({
      elem: summary.Inner.dom.holder.body.node(),
      selector: ".sjpp-violin-plot"
    });
    test.ok(foundTestPlot, `Should render violin after toggle`);
    test.equal(summary.Inner.state.config.childType, "violin", `Should toggle to childType = violin`);
    await detectStyle({
      elem: summary.Inner.dom.plotDivs.barchart.node(),
      matcher(mutations) {
        for (const m of mutations) {
          if (m.attributeName == "style" && m.target.style.display === "") return m;
        }
      },
      trigger() {
        toggles.find((d) => d.__data__.childType == "barchart").click();
      }
    });
    test.equal(summary.Inner.state.config.childType, "barchart", `Should toggle back to childType = 'barchart'`);
  }
});
(0, import_tape.default)('Barchart, violin, and scatter toggles, term: "agedx", term2: "hrtavg"', (test) => {
  test.timeoutAfter(3e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "summary",
          childType: "barchart",
          term: {
            id: "agedx"
          },
          term2: {
            id: "hrtavg"
          }
        }
      ]
    },
    summary: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(summary) {
    summary.on("postRender.test", null);
    const sandboxDom = summary.Inner.dom;
    const toggles = sandboxDom.chartToggles.selectAll("div > div> button").nodes().filter((d) => d.__data__.isVisible() == true);
    testToggleButtonRendering(toggles);
    await testToggling(summary, toggles);
    if (test._ok) summary.Inner.app.destroy();
    test.end();
  }
  function testToggleButtonRendering(toggles) {
    const tabLabels2Find2 = [...tabLabels2Find];
    tabLabels2Find2.push("Scatter");
    let foundLabels = 0;
    for (const toggle of toggles) {
      if (tabLabels2Find2.some((d) => d == toggle.__data__.label)) ++foundLabels;
    }
    test.equal(
      tabLabels2Find2.length,
      toggles.length,
      `Should render ${tabLabels2Find2.length} tabs: ${tabLabels2Find2} for 2 numeric terms`
    );
  }
  async function testToggling(summary, toggles) {
    toggles.find((d) => d.__data__.childType == "violin").click();
    const foundTestPlot = await detectOne({
      elem: summary.Inner.dom.holder.body.node(),
      selector: ".sjpp-violin-plot"
    });
    test.ok(foundTestPlot, `Should render violin after toggle`);
    test.equal(summary.Inner.state.config.childType, "violin", `Should toggle to childType = violin`);
    await detectStyle({
      elem: summary.Inner.dom.plotDivs.barchart.node(),
      matcher(mutations) {
        for (const m of mutations) {
          if (m.attributeName == "style" && m.target.style.display === "") return m;
        }
      },
      trigger() {
        toggles.find((d) => d.__data__.childType == "barchart").click();
      }
    });
    test.equal(summary.Inner.state.config.childType, "barchart", `Should toggle back to childType = 'barchart'`);
  }
});
(0, import_tape.default)('Overlay continuity, term: "aaclassic_5", term2: "sex"', (test) => {
  test.timeoutAfter(3e3);
  const testTerm = "sex";
  runpp({
    state: {
      plots: [
        {
          chartType: "summary",
          childType: "barchart",
          term: {
            id: "aaclassic_5"
          },
          term2: {
            id: testTerm
          }
        }
      ]
    },
    summary: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(summary) {
    summary.on("postRender.test", null);
    await testOverlay(summary);
    if (test._ok) summary.Inner.app.destroy();
    test.end();
  }
  async function testOverlay(summary) {
    const plots = summary.Inner.components.plots;
    summary.Inner.dom.chartToggles.selectAll("div > div> button").nodes().find((d) => d.__data__.childType == "violin").click();
    await detectOne({ elem: summary.Inner.dom.holder.body.node(), selector: ".sjpp-violin-plot" });
    test.equal(
      plots.violin.Inner.config.term2.term.id,
      testTerm,
      `Overlay term = ${testTerm} carried over to violin plot`
    );
  }
});
//# sourceMappingURL=summary.integration.spec-ZLRIA7G2.js.map
