import {
  detectOne
} from "./chunk-DJQTUDJM.js";
import {
  getRunPp
} from "./chunk-W55XSG6K.js";
import {
  require_tape
} from "./chunk-QWOE5YTB.js";
import {
  runproteinpaint
} from "./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 {
  select_default
} from "./chunk-I6Y4O3RR.js";
import "./chunk-OMR2DT66.js";
import "./chunk-DQC5FFGV.js";
import {
  __toESM
} from "./chunk-HFNDKYVF.js";

// plots/matrix/test/oncomatrix.spec.js
var import_tape = __toESM(require_tape(), 1);
var runpp = getRunPp("mass", {
  state: {
    dslabel: "GDC",
    genome: "hg38"
  },
  debug: 1
});
(0, import_tape.default)("\n", function(test) {
  test.comment("-***- plots/matrix.gdc (aka OncoMatrix) -***-");
  test.end();
});
var termlst = [
  { term: { name: "IDH1", type: "geneVariant" } },
  { term: { name: "EGFR", type: "geneVariant" } },
  { id: "case.disease_type" },
  { id: "case.diagnoses.age_at_diagnosis" }
];
(0, import_tape.default)("2 geneVariant, 2 dict terms", function(test) {
  test.timeoutAfter(2e4);
  test.plan(10);
  runpp({
    state: {
      nav: { header_mode: "hidden" },
      // must set to hidden for gdc, since it lacks termdb method to get cohort size..
      plots: [
        {
          chartType: "matrix",
          settings: {
            matrix: {
              // the matrix autocomputes the colw based on available screen width,
              // need to set an exact screen width for consistent tests using getBBox()
              availContentWidth: 1200
            }
          },
          termgroups: [{ lst: termlst }]
        }
      ]
    },
    matrix: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(matrix) {
    matrix.on("postRender.test", null);
    await testMatrixrendering(matrix);
    await testLegendRendering(matrix);
    await testBtnRendering(matrix);
    await testZoom(matrix);
    await testCaseLabelCharLimit(matrix);
    await testRowLabelCharLimit(matrix);
    await testGroupBy(matrix);
    if (test._ok) matrix.Inner.app.destroy();
    test.end();
  }
  async function testMatrixrendering(matrix) {
    await detectOne({ elem: matrix.Inner.dom.seriesesG.node(), selector: "image" });
    test.equal(matrix.Inner.dom.seriesesG.selectAll("image").size(), 1, `should render 1 <image> element`);
    test.equal(
      matrix.Inner.dom.svg.selectAll(".sjpp-matrix-term-label-g").node().querySelectorAll("text").length,
      termlst.length,
      `should render ${termlst.length} <series> elements`
    );
  }
  async function testLegendRendering(matrix) {
    test.true(matrix.Inner.dom.legendG.nodes().length > 0, `should render legend`);
    test.true(matrix.Inner.dom.legendG.selectAll("rect").size() > 0, `should render legend rects`);
    test.true(matrix.Inner.dom.legendG.selectAll("text").size() > 0, `should render legend text`);
  }
  async function testBtnRendering(matrix) {
    test.equal(matrix.Inner.dom.controls.node().querySelectorAll("button").length, 10, `should render buttons`);
  }
  async function testZoom(matrix) {
    await matrix.Inner.app.dispatch({
      type: "plot_edit",
      id: matrix.Inner.id,
      config: {
        settings: {
          matrix: {
            zoomLevel: 10
          }
        }
      }
    });
    test.equal(matrix.Inner.config.settings.matrix.zoomLevel, 10, `should zoom in`);
  }
  async function testCaseLabelCharLimit(matrix) {
    await matrix.Inner.app.dispatch({
      type: "plot_edit",
      id: matrix.Inner.id,
      config: {
        settings: {
          matrix: {
            collabelmaxchars: 10
          }
        }
      }
    });
    test.equal(
      matrix.Inner.config.settings.matrix.collabelmaxchars,
      10,
      `should limit case label characters to ${matrix.Inner.config.settings.matrix.collabelmaxchars}`
    );
  }
  async function testRowLabelCharLimit(matrix) {
    await matrix.Inner.app.dispatch({
      type: "plot_edit",
      id: matrix.Inner.id,
      config: {
        settings: {
          matrix: {
            rowlabelmaxchars: 10
          }
        }
      }
    });
    test.equal(
      matrix.Inner.config.settings.matrix.rowlabelmaxchars,
      10,
      `should limit row label characters to ${matrix.Inner.config.settings.matrix.rowlabelmaxchars}`
    );
  }
  async function testGroupBy(matrix) {
    await matrix.Inner.app.dispatch({
      type: "plot_edit",
      id: matrix.Inner.id,
      config: {
        divideBy: {
          id: "case.primary_site",
          q: {
            type: "values"
          },
          term: {
            id: "case.primary_site",
            name: "Primary Site",
            type: "categorical"
          }
        }
      }
    });
    test.equal(
      matrix.Inner.config.divideBy.id,
      "case.primary_site",
      `should group by ${matrix.Inner.config.divideBy.id}`
    );
  }
});
(0, import_tape.default)("2 geneVariant, 2 dict terms, divideBy", function(test) {
  test.timeoutAfter(2e4);
  test.plan(5);
  runpp({
    state: {
      nav: { header_mode: "hidden" },
      // must set to hidden for gdc, since it lacks termdb method to get cohort size..
      plots: [
        {
          chartType: "matrix",
          settings: {
            matrix: {
              // the matrix autocomputes the colw based on available screen width,
              // need to set an exact screen width for consistent tests using getBBox()
              availContentWidth: 1200
            }
          },
          divideBy: {
            id: "case.disease_type"
          },
          termgroups: [{ lst: termlst }]
        }
      ]
    },
    matrix: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(matrix) {
    matrix.on("postRender.test", null);
    await testSortingFunctionalities(matrix);
    await testMaxCases(matrix);
    if (test._ok) matrix.Inner.app.destroy();
    test.end();
  }
  async function testMaxCases(matrix) {
    test.equal(matrix.Inner.config.settings.matrix.maxSample, 2e3, `should limit max cases to 2000`);
    await matrix.Inner.app.dispatch({
      type: "plot_edit",
      id: matrix.Inner.id,
      config: {
        settings: {
          matrix: {
            maxSample: 1e3
          }
        }
      }
    });
    test.equal(matrix.Inner.config.settings.matrix.maxSample, 1e3, `should limit max cases to 1000`);
  }
  async function testSortingFunctionalities(matrix) {
    await matrix.Inner.app.dispatch({
      type: "plot_edit",
      id: matrix.Inner.id,
      config: {
        settings: {
          matrix: {
            groupSamplesBy: "disease_type"
          }
        }
      }
    });
    test.equal(
      matrix.Inner.config.settings.matrix.groupSamplesBy,
      "disease_type",
      `should group samples by ${matrix.Inner.config.settings.matrix.groupSamplesBy}`
    );
    await matrix.Inner.app.dispatch({
      type: "plot_edit",
      id: matrix.Inner.id,
      config: {
        settings: {
          matrix: {
            sortSampleGrpsBy: "hits"
          }
        }
      }
    });
    test.equal(
      matrix.Inner.config.settings.matrix.sortSampleGrpsBy,
      "hits",
      `should sort sample groups by ${matrix.Inner.config.settings.matrix.sortSampleGrpsBy}`
    );
    await matrix.Inner.app.dispatch({
      type: "plot_edit",
      id: matrix.Inner.id,
      config: {
        settings: {
          matrix: {
            sortSamplesBy: "name"
          }
        }
      }
    });
    test.equal(
      matrix.Inner.config.settings.matrix.sortSamplesBy,
      "name",
      `should sort cases by ${matrix.Inner.config.settings.matrix.sortSamplesBy}`
    );
  }
});
(0, import_tape.default)("2 geneVariant, 2 dict terms, 1 gene exp, 1 survival", function(test) {
  test.timeoutAfter(2e4);
  test.plan(1);
  const termlst2 = [...termlst, { term: { name: "MYC", type: "geneExpression" } }, { id: "Overall Survival" }];
  runpp({
    state: {
      nav: { header_mode: "hidden" },
      // must set to hidden for gdc, since it lacks termdb method to get cohort size..
      plots: [
        {
          chartType: "matrix",
          settings: {
            matrix: {
              // the matrix autocomputes the colw based on available screen width,
              // need to set an exact screen width for consistent tests using getBBox()
              availContentWidth: 1200
            }
          },
          termgroups: [{ lst: termlst2 }]
        }
      ]
    },
    matrix: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(matrix) {
    matrix.on("postRender.test", null);
    const numSeries = termlst2.length;
    test.equal(
      matrix.Inner.dom.svg.selectAll(".sjpp-matrix-term-label-g .sjpp-matrix-label").size(),
      numSeries,
      `should render ${numSeries} <series> elements`
    );
    if (test._ok) matrix.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)("launch matrix with gdc launcher and top mutated genes, gliomas", function(test) {
  test.timeoutAfter(1e5);
  test.plan(2);
  const holder = select_default("body").append("div").node();
  const topGeneNum = 10;
  runproteinpaint({
    holder,
    noheader: 1,
    launchGdcMatrix: true,
    filter0: {
      op: "and",
      content: [{ op: "in", content: { field: "cases.disease_type", value: ["Gliomas"] } }]
    },
    settings: {
      matrix: {
        maxGenes: topGeneNum,
        // asks to load this number of top mutated genes. will be shown in a separate group from termlst
        maxSample: 1e4
      }
    },
    termgroups: [{ lst: termlst }],
    opts: {
      matrix: {
        callbacks: {
          "postRender.test": runTests
        }
      }
    }
  });
  function runTests(matrix) {
    test.true(
      holder.querySelectorAll("svg text").length > 200,
      "should have the expected number of rendered svg text elements"
    );
    const rowcount = topGeneNum + termlst.length;
    test.equal(
      select_default(holder).selectAll(".sjpp-matrix-term-label-g").node().querySelectorAll("text").length,
      rowcount,
      `should render ${rowcount} <series> elements`
    );
    if (test._ok) setTimeout(matrix.destroy, 1e3);
    test.end();
  }
});
(0, import_tape.default)("top mutated genes from APOLLO-LUAD, CNV only", function(test) {
  test.timeoutAfter(1e5);
  test.plan(2);
  const holder = select_default("body").append("div").node();
  const topGeneNum = 10;
  runproteinpaint({
    holder,
    noheader: 1,
    debugmode: true,
    launchGdcMatrix: true,
    filter0: { op: "in", content: { field: "cases.project.project_id", value: ["APOLLO-LUAD"] } },
    settings: {
      matrix: {
        maxGenes: topGeneNum,
        maxSample: 1e4
      }
    },
    opts: {
      matrix: {
        debug: 1,
        callbacks: {
          "postRender.test": runTests
        }
      }
    }
  });
  async function runTests(matrix) {
    await matrix.Inner.app.dispatch({
      type: "plot_edit",
      id: matrix.id,
      config: {
        legendGrpFilter: {
          isAtomic: true,
          type: "tvslst",
          in: true,
          join: "and",
          lst: []
        }
      }
    });
    test.true(
      holder.querySelectorAll("svg text").length > 90,
      "should have the expected number of rendered svg text elements"
    );
    test.equal(
      select_default(holder).selectAll(".sjpp-matrix-term-label-g").node().querySelectorAll("text").length,
      topGeneNum,
      `should render ${topGeneNum} <series> elements`
    );
    if (test._ok) setTimeout(matrix.destroy, 1e3);
    test.end();
  }
});
//# sourceMappingURL=oncomatrix.spec-RLIVVVD6.js.map
