Skip to content

Commit

Permalink
Adding unit-test and removing default parameter defined in function c…
Browse files Browse the repository at this point in the history
…all.
  • Loading branch information
kartikeyakirar committed Oct 5, 2023
1 parent b1f8bef commit 9ada482
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 21 deletions.
2 changes: 0 additions & 2 deletions R/boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions R/forestplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions R/km.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions R/pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion R/quality.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions R/scatterplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 7 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,25 @@ 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)
card$append_text(title, "header2")
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
}
2 changes: 0 additions & 2 deletions R/volcanoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions man/card_template.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 9ada482

Please sign in to comment.