From 9ada482e2e2b0d88f5fcd56a291deb46f52c475d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 Oct 2023 17:14:31 +0530 Subject: [PATCH] Adding unit-test and removing default parameter defined in function call. --- R/boxplot.R | 2 -- R/forestplot.R | 2 -- R/km.R | 2 -- R/pca.R | 2 -- R/quality.R | 1 - R/scatterplot.R | 2 -- R/utils.R | 12 +++++++----- R/volcanoplot.R | 2 -- man/card_template.Rd | 4 +--- tests/testthat/test-utils.R | 22 ++++++++++++++++++++++ 10 files changed, 30 insertions(+), 21 deletions(-) diff --git a/R/boxplot.R b/R/boxplot.R index 8db0f65e..2f931e0f 100644 --- a/R/boxplot.R +++ b/R/boxplot.R @@ -189,8 +189,6 @@ srv_g_boxplot <- function(id, card <- card_template( title = "Boxplot", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/forestplot.R b/R/forestplot.R index 19315ba5..2647aa67 100644 --- a/R/forestplot.R +++ b/R/forestplot.R @@ -234,8 +234,6 @@ srv_g_forest_tte <- function(id, card <- card_template( title = "Forest Plot", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/km.R b/R/km.R index 321d216b..f3dd69c7 100644 --- a/R/km.R +++ b/R/km.R @@ -226,8 +226,6 @@ srv_g_km <- function(id, card <- card_template( title = "Kaplan-Meier Plot", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/pca.R b/R/pca.R index f0488f37..76c809cb 100644 --- a/R/pca.R +++ b/R/pca.R @@ -361,8 +361,6 @@ srv_g_pca <- function(id, card <- card_template( title = "PCA", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/quality.R b/R/quality.R index 679b2176..4caedc93 100644 --- a/R/quality.R +++ b/R/quality.R @@ -358,7 +358,6 @@ srv_g_quality <- function(id, title = "Quality Control Plot", label = label, description = tools::toTitleCase(input$plot_type), - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/scatterplot.R b/R/scatterplot.R index 1ec6d746..c46c805f 100644 --- a/R/scatterplot.R +++ b/R/scatterplot.R @@ -189,8 +189,6 @@ srv_g_scatterplot <- function(id, card <- card_template( title = "Scatter Plot", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/utils.R b/R/utils.R index c484146c..1573a876 100644 --- a/R/utils.R +++ b/R/utils.R @@ -82,14 +82,18 @@ include_js_files <- function(pattern = "*") { # nolint #' @param title (`character(1)`) title of the card (unless overwritten by label) #' @param label (`character(1)`) label provided by the user when adding the card #' @param description (`character(1)`) optional additional description -#' @param with_filter (`logical(1)`) flag indicating to add filter state #' @param filter_panel_api (`FilterPanelAPI`) object with API that allows the generation #' of the filter state in the report #' #' @return (`TealReportCard`) populated with a title, description and filter state #' #' @keywords internal -card_template <- function(title, label, description = NULL, with_filter, filter_panel_api) { +card_template <- function(title, label, description = NULL, filter_panel_api) { + checkmate::assert_string(title) + checkmate::assert_string(label) + checkmate::assert_string(description, null.ok = TRUE) + checkmate::assert_class(filter_panel_api, classes = "FilterPanelAPI") + card <- teal::TealReportCard$new() title <- if (label == "") title else label card$set_name(title) @@ -97,8 +101,6 @@ card_template <- function(title, label, description = NULL, with_filter, filter_ if (!is.null(description)) { card$append_text(description, "header3") } - if (with_filter) { - card$append_fs(filter_panel_api$get_filter_state()) - } + card$append_fs(filter_panel_api$get_filter_state()) card } diff --git a/R/volcanoplot.R b/R/volcanoplot.R index e283b681..9b53c0ca 100644 --- a/R/volcanoplot.R +++ b/R/volcanoplot.R @@ -211,8 +211,6 @@ srv_g_volcanoplot <- function(id, card <- card_template( title = "Volcano Plot", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/man/card_template.Rd b/man/card_template.Rd index 1627ac17..89769c62 100644 --- a/man/card_template.Rd +++ b/man/card_template.Rd @@ -4,7 +4,7 @@ \alias{card_template} \title{Template function to generate reporter card for \code{teal.modules.hermes}} \usage{ -card_template(title, label, description = NULL, with_filter, filter_panel_api) +card_template(title, label, description = NULL, filter_panel_api) } \arguments{ \item{title}{(\code{character(1)}) title of the card (unless overwritten by label)} @@ -13,8 +13,6 @@ card_template(title, label, description = NULL, with_filter, filter_panel_api) \item{description}{(\code{character(1)}) optional additional description} -\item{with_filter}{(\code{logical(1)}) flag indicating to add filter state} - \item{filter_panel_api}{(\code{FilterPanelAPI}) object with API that allows the generation of the filter state in the report} } diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 951f1c4a..bc53fe47 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -18,3 +18,25 @@ test_that("h_extract_words works as expected", { "All elements must have at least 1 characters, but element 1 has 0 characters." ) }) + +testthat::test_that("card_template function returns TealReportCard object with appropriate content and labels", { + fd <- teal.slice::init_filtered_data(list(iris = list(dataset = iris))) + filter_panel_api <- teal.slice::FilterPanelAPI$new(fd) + + card <- shiny::isolate(card_template(title = "Card title", + label = "Card label", + description = NULL, + filter_panel_api = filter_panel_api)) + testthat::expect_s3_class(card, c("TealReportCard")) + testthat::expect_equal(card$get_name(), "Card label") + testthat::expect_length(card$get_content(), 3) + + card <- shiny::isolate(card_template(title = "Card title", + label = "", + description = "Description text", + filter_panel_api = filter_panel_api)) + testthat::expect_s3_class(card, c("TealReportCard")) + testthat::expect_equal(card$get_name(), "Card title") + testthat::expect_length(card$get_content(), 4) +}) +