From fa98b751b53e13cd9bb0fddf857f70a8a71ffea6 Mon Sep 17 00:00:00 2001 From: Giulio Date: Fri, 29 Aug 2025 17:58:49 +0300 Subject: [PATCH] Add unit tests for new panels --- DESCRIPTION | 2 +- tests/testthat/test-ColumnGraphPlot.R | 52 ++++++++++++++++++++++++++ tests/testthat/test-PrevalencePlot.R | 48 ++++++++++++++++++++++++ tests/testthat/test-RowGraphPlot.R | 54 +++++++++++++++++++++++++++ tests/testthat/test-ScreePlot.R | 50 +++++++++++++++++++++++++ 5 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/test-ColumnGraphPlot.R create mode 100644 tests/testthat/test-PrevalencePlot.R create mode 100644 tests/testthat/test-RowGraphPlot.R create mode 100644 tests/testthat/test-ScreePlot.R diff --git a/DESCRIPTION b/DESCRIPTION index 89d939e..f1945fe 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: iSEEtree -Version: 1.3.1 +Version: 1.3.2 Authors@R: c(person(given = "Giulio", family = "Benedetti", role = c("aut", "cre"), email = "giulio.benedetti@utu.fi", diff --git a/tests/testthat/test-ColumnGraphPlot.R b/tests/testthat/test-ColumnGraphPlot.R new file mode 100644 index 0000000..37e02e6 --- /dev/null +++ b/tests/testthat/test-ColumnGraphPlot.R @@ -0,0 +1,52 @@ +test_that("ColumnGraphPlot", { + + output <- new.env() + pObjects <- new.env() + rObjects <- new.env() + select_info <- list(single = list(feature = "---", sample = "---"), + multi = list(row = "---", column = "---")) + + data("GlobalPatterns", package = "mia") + tse <- GlobalPatterns + + data("col_graph", package = "miaViz") + metadata(tse)$graph <- col_graph + + panel <- ColumnGraphPlot() + + panel[["layout"]] <- "kk" + + expect_identical(.getEncodedName(panel), "ColumnGraphPlotNA") + expect_identical(.fullName(panel), "Column graph plot") + expect_identical(.panelColor(panel), "purple") + + expect_s3_class(.defineInterface(panel, tse, select_info)[[1]][[1]], "shiny.tag.list") + expect_length(.defineDataInterface(panel, tse, select_info), 3) + + expect_s3_class(.defineOutput(panel), "shiny.tag.list") + expect_match(.generateOutput(panel, tse)[["commands"]][["fun"]], + 'p <- miaViz::plotColGraph(se, name=\"graph\", assay.type=\"counts\",\n show.label=FALSE, layout=\"kk\", edge.type=\"fan\", add.legend=TRUE)', + fixed = TRUE) + + expect_true(.hideInterface(panel, "ColumnSelectionSource")) + expect_false(.multiSelectionResponsive(panel, "row")) + expect_true(.multiSelectionResponsive(panel, "column")) + + expect_contains(slotNames(panel), c("name", "assay.type", "layout", + "show.label", "add.legend", "edge.colour.by", "edge.size.by", + "node.colour.by", "node.shape.by", "node.size.by")) + + expect_contains(.definePanelTour(panel)[[1]], + c("#ColumnGraphPlotNA_DataBoxOpen", "#ColumnGraphPlotNA_VisualBoxOpen", + "#ColumnGraphPlotNA", "#ColumnGraphPlotNA_SelectionBoxOpen")) + + expect_s3_class(.create_visual_box_for_graph(panel, tse), "shiny.tag.list") + + expect_null(.renderOutput(panel, tse, output = output, pObjects = pObjects, rObjects = rObjects)) + expect_s3_class(output$ColumnGraphPlotNA, "shiny.render.function") + expect_s3_class(output$ColumnGraphPlotNA_INTERNAL_PanelMultiSelectInfo, "shiny.render.function") + expect_s3_class(output$ColumnGraphPlotNA_INTERNAL_PanelSelectLinkInfo, "shiny.render.function") + + expect_identical(.exportOutput(panel, tse), "ColumnGraphPlotNA.pdf") + +}) diff --git a/tests/testthat/test-PrevalencePlot.R b/tests/testthat/test-PrevalencePlot.R new file mode 100644 index 0000000..a1c26ae --- /dev/null +++ b/tests/testthat/test-PrevalencePlot.R @@ -0,0 +1,48 @@ +test_that("PrevalencePlot", { + + output <- new.env() + pObjects <- new.env() + rObjects <- new.env() + select_info <- list(single = list(feature = "---", sample = "---"), + multi = list(row = "---", column = "---")) + + data("Tengeler2020", package = "mia") + tse <- Tengeler2020 + + panel <- PrevalencePlot() + + panel[["include.lowest"]] <- TRUE + + expect_identical(.getEncodedName(panel), "PrevalencePlotNA") + expect_identical(.fullName(panel), "Prevalence plot") + expect_identical(.panelColor(panel), "grey") + + expect_s3_class(.defineInterface(panel, tse, select_info)[[1]][[1]], "shiny.tag.list") + expect_length(.defineDataInterface(panel, tse, select_info), 6) + + expect_s3_class(.defineOutput(panel), "shiny.tag.list") + # expect_match(.generateOutput(panel, tse)[["commands"]][["fun"]], + # 'p <- miaViz::plotRowGraph(se, name=\"graph\", assay.type=\"counts\",\n show.label=FALSE, layout=\"kk\", edge.type=\"fan\", add.legend=TRUE)', + # fixed = TRUE) + + expect_true(.hideInterface(panel, "ColumnSelectionSource")) + expect_false(.multiSelectionResponsive(panel, "column")) + expect_true(.multiSelectionResponsive(panel, "row")) + + expect_contains(slotNames(panel), c("detection", "prevalence", "assay.type", + "rank", "include.lowest", "show.rank")) + + expect_contains(.definePanelTour(panel)[[1]], + c("#PrevalencePlotNA_DataBoxOpen", "#PrevalencePlotNA", + "#PrevalencePlotNA_SelectionBoxOpen")) + + expect_s3_class(.create_visual_box_for_prev_plot(panel, tse), "shiny.tag.list") + + expect_null(.renderOutput(panel, tse, output = output, pObjects = pObjects, rObjects = rObjects)) + expect_s3_class(output$PrevalencePlotNA, "shiny.render.function") + expect_s3_class(output$PrevalencePlotNA_INTERNAL_PanelMultiSelectInfo, "shiny.render.function") + expect_s3_class(output$PrevalencePlotNA_INTERNAL_PanelSelectLinkInfo, "shiny.render.function") + + # expect_identical(.exportOutput(panel, tse), "PrevalencePlotNA.pdf") + +}) diff --git a/tests/testthat/test-RowGraphPlot.R b/tests/testthat/test-RowGraphPlot.R new file mode 100644 index 0000000..1f50757 --- /dev/null +++ b/tests/testthat/test-RowGraphPlot.R @@ -0,0 +1,54 @@ +test_that("RowGraphPlot", { + + output <- new.env() + pObjects <- new.env() + rObjects <- new.env() + select_info <- list(single = list(feature = "---", sample = "---"), + multi = list(row = "---", column = "---")) + + data("GlobalPatterns", package = "mia") + tse <- GlobalPatterns + + data("row_graph_order", package = "miaViz") + + tse <- mia::agglomerateByRank(tse, rank = "Order", na.rm = TRUE) + metadata(tse)$graph <- row_graph_order + + panel <- RowGraphPlot() + + panel[["layout"]] <- "kk" + + expect_identical(.getEncodedName(panel), "RowGraphPlotNA") + expect_identical(.fullName(panel), "Row graph plot") + expect_identical(.panelColor(panel), "orange") + + expect_s3_class(.defineInterface(panel, tse, select_info)[[1]][[1]], "shiny.tag.list") + expect_length(.defineDataInterface(panel, tse, select_info), 3) + + expect_s3_class(.defineOutput(panel), "shiny.tag.list") + expect_match(.generateOutput(panel, tse)[["commands"]][["fun"]], + 'p <- miaViz::plotRowGraph(se, name=\"graph\", assay.type=\"counts\",\n show.label=FALSE, layout=\"kk\", edge.type=\"fan\", add.legend=TRUE)', + fixed = TRUE) + + expect_true(.hideInterface(panel, "ColumnSelectionSource")) + expect_false(.multiSelectionResponsive(panel, "column")) + expect_true(.multiSelectionResponsive(panel, "row")) + + expect_contains(slotNames(panel), c("name", "assay.type", "layout", + "show.label", "add.legend", "edge.colour.by", "edge.size.by", + "node.colour.by", "node.shape.by", "node.size.by")) + + expect_contains(.definePanelTour(panel)[[1]], + c("#RowGraphPlotNA_DataBoxOpen", "#RowGraphPlotNA_VisualBoxOpen", + "#RowGraphPlotNA", "#RowGraphPlotNA_SelectionBoxOpen")) + + expect_s3_class(.create_visual_box_for_graph(panel, tse), "shiny.tag.list") + + expect_null(.renderOutput(panel, tse, output = output, pObjects = pObjects, rObjects = rObjects)) + expect_s3_class(output$RowGraphPlotNA, "shiny.render.function") + expect_s3_class(output$RowGraphPlotNA_INTERNAL_PanelMultiSelectInfo, "shiny.render.function") + expect_s3_class(output$RowGraphPlotNA_INTERNAL_PanelSelectLinkInfo, "shiny.render.function") + + expect_identical(.exportOutput(panel, tse), "RowGraphPlotNA.pdf") + +}) diff --git a/tests/testthat/test-ScreePlot.R b/tests/testthat/test-ScreePlot.R new file mode 100644 index 0000000..3ef7538 --- /dev/null +++ b/tests/testthat/test-ScreePlot.R @@ -0,0 +1,50 @@ +test_that("ScreePlot", { + + output <- new.env() + pObjects <- new.env() + rObjects <- new.env() + select_info <- list(single = list(feature = "---", sample = "---"), + multi = list(row = "---", column = "---")) + + data("Tengeler2020", package = "mia") + tse <- Tengeler2020 + panel <- ScreePlot() + + panel[["show.barplot"]] <- FALSE + panel[["show.line"]] <- FALSE + + tse <- scater::runPCA(tse, assay.type = "counts", ncomponents = 5) + + expect_identical(.getEncodedName(panel), "ScreePlotNA") + expect_identical(.fullName(panel), "Scree plot") + expect_identical(.panelColor(panel), "#0066CC") + + expect_s3_class(.defineInterface(panel, tse, select_info)[[1]][[1]], "shiny.tag.list") + expect_length(.defineDataInterface(panel, tse, select_info), 5) + + expect_s3_class(.defineOutput(panel), "shiny.tag.list") + expect_match(.generateOutput(panel, tse)[["commands"]][["fun"]], + "p <- miaViz::plotScree(se, dimred=\"PCA\", show.barplot=FALSE, show.points=TRUE,\n show.line=FALSE, add.proportion=TRUE, add.cumulative=FALSE,\n show.names=FALSE, show.labels=FALSE, n=5)", + fixed = TRUE) + + # expect_true(.hideInterface(panel, "ColumnSelectionSource")) + # expect_false(.multiSelectionResponsive(panel, "column")) + # expect_true(.multiSelectionResponsive(panel, "row")) + + expect_contains(slotNames(panel), c("dimred", "show.barplot", "show.points", + "show.line", "show.labels", "add.proportion", "add.cumulative", "n", + "show.names", "eig.name")) + + expect_contains(.definePanelTour(panel)[[1]], + c("#ScreePlotNA_DataBoxOpen")) + + expect_s3_class(.create_visual_box_for_scree_plot(panel, tse), "shiny.tag.list") + + expect_null(.renderOutput(panel, tse, output = output, pObjects = pObjects, rObjects = rObjects)) + expect_s3_class(output$ScreePlotNA, "shiny.render.function") + # expect_s3_class(output$ScreePlotNA_INTERNAL_PanelMultiSelectInfo, "shiny.render.function") + # expect_s3_class(output$ScreePlotNA_INTERNAL_PanelSelectLinkInfo, "shiny.render.function") + + expect_identical(.exportOutput(panel, tse), "ScreePlotNA.pdf") + +}) \ No newline at end of file