import "./chunk-DHPLHIVP.js";
import {
  Locator,
  detectGte,
  sleep
} 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/survival/test/survival.integration.spec.js
var import_tape = __toESM(require_tape(), 1);
var runpp = getRunPp("mass", {
  state: {
    nav: {
      activeTab: 1
    },
    dslabel: "TermdbTest",
    genome: "hg38-test"
  },
  debug: 1
});
(0, import_tape.default)("\n", function(test) {
  test.comment("-***- plots/survival -***-");
  test.end();
});
(0, import_tape.default)("survival term as term1", function(test) {
  test.timeoutAfter(1e4);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  let survivalDiv;
  async function runTests(survival) {
    survivalDiv = survival.Inner.dom.chartsDiv;
    test.equal(survivalDiv && survivalDiv.selectAll(".sjpp-survival-series").size(), 1, "should render 1 surv series g");
    test.equal(
      survivalDiv && survivalDiv.selectAll(".sjpp-survival-censored-x").size(),
      10,
      "should render 10 survival censored symbols"
    );
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, with categorical overlay", function(test) {
  test.timeoutAfter(1e4);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term2: {
            id: "diaggrp"
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  let survivalDiv;
  async function runTests(survival) {
    survivalDiv = survival.Inner.dom.chartsDiv;
    test.equal(survivalDiv && survivalDiv.selectAll(".sjpp-survival-series").size(), 7, "should render 7 surv series g");
    test.equal(
      survivalDiv && survivalDiv.selectAll(".sjpp-survival-censored-x").size(),
      10,
      "should render 9 survival censored symbols"
    );
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, with numeric overlay", function(test) {
  test.timeoutAfter(1e4);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term2: {
            id: "agedx"
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  let survivalDiv;
  async function runTests(survival) {
    survivalDiv = survival.Inner.dom.chartsDiv;
    test.equal(survivalDiv && survivalDiv.selectAll(".sjpp-survival-series").size(), 2, "should render 2 surv series g");
    test.equal(
      survivalDiv && survivalDiv.selectAll(".sjpp-survival-censored-x").size(),
      10,
      "should render 10 survival censored symbols"
    );
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, with condition overlay (some samples have missing values)", function(test) {
  test.timeoutAfter(1e4);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term2: {
            id: "Auditory System"
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  let survivalDiv;
  async function runTests(survival) {
    survivalDiv = survival.Inner.dom.chartsDiv;
    test.equal(survivalDiv && survivalDiv.selectAll(".sjpp-survival-series").size(), 5, "should render 5 surv series g");
    test.equal(
      survivalDiv && survivalDiv.selectAll(".sjpp-survival-censored-x").size(),
      3,
      "should render 3 survival censored symbols"
    );
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as overlay", function(test) {
  test.timeoutAfter(1e4);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "diaggrp"
          },
          term2: {
            id: "efs"
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  let survivalDiv;
  async function runTests(survival) {
    survivalDiv = survival.Inner.dom.chartsDiv;
    test.equal(survivalDiv && survivalDiv.selectAll(".sjpp-survival-series").size(), 7, "should render 7 surv series g");
    test.equal(
      survivalDiv && survivalDiv.selectAll(".sjpp-survival-censored-x").size(),
      10,
      "should render 10 survival censored symbols"
    );
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, with categorical divide by", function(test) {
  test.timeoutAfter(1e4);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term0: {
            id: "genetic_race"
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(survival) {
    const inner = survival.Inner;
    const survivalDiv = inner.dom.chartsDiv;
    const term0Values = inner.state.config.term0.term.values;
    test.equal(survivalDiv.selectAll(".pp-survival-chart").size(), 3, `Should render 3 survival charts`);
    test.equal(
      survivalDiv.selectAll(".sjpp-survival-atrisk").size(),
      3,
      `Should render 'Number at risk' tables below each chart`
    );
    const term0Labels = Object.values(term0Values).map((v) => v.label);
    const titleNodes = survivalDiv.selectAll(".sjpp-survival-title").nodes();
    for (const d of titleNodes) {
      if (!term0Labels.includes(d.innerText)) test.fail(`Unexpected title: ${d.innerText}`);
    }
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, with numeric divide by", function(test) {
  test.timeoutAfter(1e4);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term0: {
            id: "agedx"
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(survival) {
    const inner = survival.Inner;
    const survivalDiv = inner.dom.chartsDiv;
    test.equal(survivalDiv.selectAll(".pp-survival-chart").size(), 2, `Should render 2 survival charts`);
    test.equal(
      survivalDiv.selectAll(".sjpp-survival-atrisk").size(),
      2,
      `Should render 'Number at risk' tables below each chart`
    );
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, with condition divide by (some samples have missing values)", function(test) {
  test.timeoutAfter(1e4);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term0: {
            id: "Auditory System"
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(survival) {
    const inner = survival.Inner;
    const survivalDiv = inner.dom.chartsDiv;
    const term0Values = inner.state.config.term0.term.values;
    test.equal(survivalDiv.selectAll(".pp-survival-chart").size(), 5, `Should render 5 survival charts`);
    test.equal(
      survivalDiv.selectAll(".sjpp-survival-atrisk").size(),
      5,
      `Should render 'Number at risk' tables below each chart`
    );
    const term0Labels = Object.values(term0Values).map((v) => v.label);
    const titleNodes = survivalDiv.selectAll(".sjpp-survival-title").nodes();
    for (const d of titleNodes) {
      if (!term0Labels.includes(d.innerText)) test.fail(`Unexpected title: ${d.innerText}`);
    }
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, term2 = genetic_race, categorical groupsetting", function(test) {
  test.timeoutAfter(3e3);
  const groups = [
    {
      name: "non-Asian Ancestry",
      type: "values",
      values: [
        { key: "European Ancestry", label: "European Ancestry" },
        { key: "African Ancestry", label: "African Ancestry" },
        { key: "Multi-Ancestry-Admixed", label: "Multi-Ancestry-Admixed" }
      ]
    },
    {
      name: "Asian Ancestry",
      type: "values",
      values: [{ key: "Asian Ancestry", label: "Asian Ancestry" }]
    }
  ];
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term2: {
            id: "genetic_race",
            q: {
              customset: {
                groups
              }
            }
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(survival) {
    survival.on("postRender.test", null);
    const inner = survival.Inner;
    const config = inner.state.config;
    test.equal(
      JSON.stringify(config.term2.q.customset.groups),
      JSON.stringify(groups),
      `Should correctly pass customset groups for term2`
    );
    const numOfTerms = Object.keys(inner.term2toColor).length;
    test.equal(
      inner.dom.chartsDiv.selectAll(".sjpp-survival-series").size(),
      numOfTerms,
      `Should render ${numOfTerms} surv series g`
    );
    const censoredSym = inner.currData.filter((d) => d.ncensor);
    test.equal(
      inner.dom.chartsDiv.selectAll(".sjpp-survival-censored-x").size(),
      censoredSym.length,
      `should render ${censoredSym.length} survival censored symbols`
    );
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, term0 = genetic_race, categorical groupsetting", function(test) {
  test.timeoutAfter(1e4);
  const groups = [
    {
      name: "non-Asian Ancestry",
      type: "values",
      values: [
        { key: "European Ancestry", label: "European Ancestry" },
        { key: "African Ancestry", label: "African Ancestry" },
        { key: "Multi-Ancestry-Admixed", label: "Multi-Ancestry-Admixed" }
      ]
    },
    {
      name: "Asian Ancestry",
      type: "values",
      values: [{ key: "Asian Ancestry", label: "Asian Ancestry" }]
    }
  ];
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term0: {
            id: "genetic_race",
            q: {
              customset: {
                groups
              }
            }
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(survival) {
    survival.on("postRender.test", null);
    const inner = survival.Inner;
    const config = inner.state.config;
    const term0Values = config.term0.term.values;
    test.equal(
      JSON.stringify(config.term0.q.customset.groups),
      JSON.stringify(groups),
      `Should correctly pass customset groups for term0`
    );
    const termNum = inner.serverData.refs.orderedKeys.chart;
    test.equal(
      inner.dom.chartsDiv.selectAll(".pp-survival-chart").size(),
      termNum.length,
      `Should render ${termNum.length} survival charts`
    );
    test.equal(
      inner.dom.chartsDiv.selectAll(".sjpp-survival-atrisk").size(),
      termNum.length,
      `Should render 'Number at risk' tables below each chart`
    );
    const titleNodes = inner.dom.chartsDiv.selectAll(".sjpp-survival-title").nodes();
    termNum.forEach((v) => {
      if (!titleNodes.some((d) => d.innerText == v)) test.fail(`Missing title for term0 value = ${v}`);
    });
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, term2 = agedx, regular bins", function(test) {
  test.timeoutAfter(1e4);
  test.plan(4);
  const testBinSize = 5;
  const testStop = 5;
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term2: {
            id: "agedx",
            name: "Age (years) at Cancer Diagnosis",
            type: "float",
            bins: {
              default: {
                type: "regular-bin",
                bin_size: testBinSize,
                startinclusive: true,
                first_bin: {
                  startunbounded: true,
                  stop: testStop
                }
              },
              label_offset: 1
            }
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(survival) {
    survival.on("postRender.test", null);
    test.equal(survival.Inner.state.config.term2.q.type, "regular-bin", `Should correctly pass 'regular-bin' to config`);
    test.equal(
      survival.Inner.state.config.term2.q.bin_size,
      testBinSize,
      `Should correctly pass q.bin_size = ${testBinSize} to config`
    );
    test.equal(
      survival.Inner.state.config.term2.q.first_bin.stop,
      testStop,
      `Should correctly pass q.first_bin.stop = ${testStop} to config`
    );
    const newStop = 1;
    const config = structuredClone(survival.Inner.state.config);
    const expectedCount = 8;
    const survCurves = await detectGte({
      elem: survival.Inner.dom.chartsDiv.node(),
      selector: ".sjpp-survival-series",
      count: expectedCount,
      async trigger() {
        config.term2.q.bin_size = 3;
        config.term2.q.first_bin.stop = newStop;
        survival.Inner.app.dispatch({
          type: "plot_edit",
          id: survival.Inner.id,
          config
        });
      }
    });
    test.equal(survCurves.length, expectedCount, `Should display the correct bin size = ${expectedCount}`);
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, term2 = agedx, custom bins", function(test) {
  test.timeoutAfter(1e4);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term2: {
            id: "agedx",
            q: {
              type: "custom-bin",
              mode: "discrete",
              lst: [
                { startunbounded: true, stop: 7, stopinclusive: false, label: "<7" },
                { startinclusive: true, stopinclusive: true, start: 7, stop: 12, label: "7 to 12" },
                { start: 12, startinclusive: false, stopunbounded: true, label: ">12" }
              ]
            }
          },
          settings: {
            survival: {}
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(survival) {
    survival.on("postRender.test", null);
    const inner = survival.Inner;
    const config = inner.state.config;
    test.equal(config.term2.q.type, "custom-bin", `Should correctly pass 'custom-bin' to config`);
    const config2 = structuredClone(config);
    const expectedCount = 3;
    const survCurves = await detectGte({
      elem: survival.Inner.dom.chartsDiv.node(),
      selector: ".sjpp-survival-series",
      count: expectedCount,
      async trigger() {
        config2.term2.q.lst[2] = { startinclusive: true, stopinclusive: true, start: 12, stop: 15, label: "12 to 15" };
        config2.term2.q.lst.push({ start: 15, startinclusive: false, stopunbounded: true, label: ">15" });
        inner.app.dispatch({
          type: "plot_edit",
          id: inner.id,
          config: config2
        });
      }
    });
    test.equal(survCurves.length, expectedCount, `Should display the correct num of bins = ${expectedCount}`);
    if (test._ok) inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, term0 = agedx, custom bins", function(test) {
  test.timeoutAfter(2e4);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term0: {
            id: "agedx",
            term: {
              type: "float",
              bins: {
                default: {
                  type: "regular-bin",
                  bin_size: 5,
                  startinclusive: true,
                  first_bin: {
                    startunbounded: true,
                    stop: 5
                  },
                  label_offset: 1
                },
                label_offset: 1
              },
              name: "Age (years) at Cancer Diagnosis",
              id: "agedx"
            },
            q: {
              isAtomic: true,
              mode: "discrete",
              type: "custom-bin",
              lst: [
                {
                  startunbounded: true,
                  stop: 12,
                  stopinclusive: false,
                  label: "<12"
                },
                {
                  start: 12,
                  startinclusive: true,
                  stopunbounded: true,
                  label: "\u226512"
                }
              ],
              hiddenValues: {}
            }
          }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(survival) {
    survival.on("postRender.test", null);
    const inner = survival.Inner;
    const config = inner.state.config;
    test.equal(config.term0.q.type, "custom-bin", `Should correctly pass 'custom-bin' to config`);
    const config2 = structuredClone(config);
    const expectedCount = 3;
    const survCurves = await detectGte({
      elem: survival.Inner.dom.chartsDiv.node(),
      selector: ".sjpp-survival-series",
      count: expectedCount,
      async trigger() {
        config2.term0.q.lst = [
          { startunbounded: true, stop: 5, stopinclusive: false, label: "<5" },
          { start: 5, stop: 8, startinclusive: true, stopinclusive: false, label: "5 to <8" },
          { start: 8, startinclusive: true, stopunbounded: true, label: ">=8" }
        ];
        await inner.app.dispatch({
          type: "plot_edit",
          id: inner.id,
          config: config2
        });
      }
    });
    test.equal(survCurves.length, expectedCount, `Should display the correct num of bins = ${expectedCount}`);
    if (test._ok) inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, term2 = geneVariant", function(test) {
  test.timeoutAfter(5e3);
  test.plan(4);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term2: { term: { type: "geneVariant", gene: "TP53" } }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  let survivalDiv;
  async function runTests(survival) {
    survival.on("postRender.test", null);
    const { chartsDiv, legendTip } = survival.Inner.dom;
    survivalDiv = chartsDiv;
    test.equal(survivalDiv && survivalDiv.selectAll(".sjpp-survival-series").size(), 2, "should render 2 surv series g");
    test.equal(
      survivalDiv && survivalDiv.selectAll(".sjpp-survival-censored-x").size(),
      10,
      "should render 10 survival censored symbols"
    );
    const atRiskLegend0 = await Locator.init(survivalDiv.node()).find(`[data-testid='sjpp-atrisk-seriesId']`).click(0);
    const colorInput = await Locator.init(legendTip.d).shows('input[type="color"]').get(0);
    colorInput.value = "#0000ff";
    colorInput.dispatchEvent(new Event("change", { cancelable: true }));
    legendTip.hide();
    await sleep(100);
    test.equal(atRiskLegend0?.parentNode?.getAttribute("fill"), "rgb(0, 0, 255)", "should change the series color");
    await survival.Inner.app.dispatch({
      type: "plot_edit",
      id: survival.id,
      config: {
        settings: {
          survival: {
            atRiskVisible: false
          }
        }
      }
    });
    await sleep(100);
    test.equal(
      survivalDiv.selectAll(".sjpp-atrisk-title").size(),
      0,
      "should hide at-risk legend when settings.survival.atRiskVisible is false"
    );
    if (test._ok) {
      survival.Inner.app.destroy();
      legendTip.hide();
    }
    test.end();
  }
});
(0, import_tape.default)("survival term as term1, term2 = geneExpression", function(test) {
  test.timeoutAfter(8e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "survival",
          term: {
            id: "efs"
          },
          term2: { term: { type: "geneExpression", gene: "TP53" } }
        }
      ]
    },
    survival: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  let survivalDiv;
  async function runTests(survival) {
    survivalDiv = survival.Inner.dom.chartsDiv;
    test.equal(survivalDiv && survivalDiv.selectAll(".sjpp-survival-series").size(), 2, "should render 2 surv series g");
    test.equal(
      survivalDiv && survivalDiv.selectAll(".sjpp-survival-censored-x").size(),
      10,
      "should render 10 survival censored symbols"
    );
    if (test._ok) survival.Inner.app.destroy();
    test.end();
  }
});
//# sourceMappingURL=survival.integration.spec-7IWBTPJG.js.map
