From d98909e67b088e2ce40b23c46d8d788e37339175 Mon Sep 17 00:00:00 2001 From: osenan Date: Wed, 17 Dec 2025 19:43:19 -0300 Subject: [PATCH 1/7] tests: add test for add_no_selected_choices --- tests/testthat/test-choices_selected.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/testthat/test-choices_selected.R b/tests/testthat/test-choices_selected.R index 4cf40b41..3a08a78d 100644 --- a/tests/testthat/test-choices_selected.R +++ b/tests/testthat/test-choices_selected.R @@ -197,3 +197,13 @@ testthat::test_that("delayed version of choices_selected - resolve_delayed", { res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = key_list)) testthat::expect_equal(res_obj, exp_obj) }) + +testthat::test_that("if we call add_no_selected_choices we add no selection", { + choices_list <- choices_selected( + choices = c("a", "b", "c"), + selected = "a" + ) + testthat::expect_false(any(grepl("no selection", choices_list$choices))) + choices_list <- add_no_selected_choices(choices_list) + testthat::expect_true(any(grepl("no selection", choices_list$choices))) +}) From cf3f30c72f96e6fd6d4caf44f72265e7b8dc020d Mon Sep 17 00:00:00 2001 From: osenan Date: Wed, 17 Dec 2025 19:57:27 -0300 Subject: [PATCH 2/7] add test for datanames_input --- tests/testthat/test-data_extract_datanames.R | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/testthat/test-data_extract_datanames.R b/tests/testthat/test-data_extract_datanames.R index 226f7f04..1e4fe13c 100644 --- a/tests/testthat/test-data_extract_datanames.R +++ b/tests/testthat/test-data_extract_datanames.R @@ -83,3 +83,31 @@ testthat::test_that("get_extract_datanames returns unique dataname when data_ext testthat::expect_identical(ged_output, "ADSL") testthat::expect_equal(length(ged_output), 1) }) + +testthat::test_that("datanames_input gets the data names provided to module", { + adtte_filters <- filter_spec( + vars = c("PARAMCD", "CNSR"), + sep = "-", + choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), + selected = "OS-1", + multiple = FALSE, + label = "Choose endpoint and Censor" + ) + + response_spec <- data_extract_spec( + dataname = "ADTTE", + filter = adtte_filters, + select = select_spec( + choices = c("AVAL", "BMRKR1", "AGE"), + selected = c("AVAL", "BMRKR1"), + multiple = TRUE, + fixed = FALSE, + label = "Column" + ) + ) + + input_names <- datanames_input(response_spec) + + testthat::expect_s3_class(input_names, "shiny.tag") + testthat::expect_true(grepl("ADTTE", as.character(input_names))) +}) From 199e29c4e77adc29a09450674970fd01a2da80fa Mon Sep 17 00:00:00 2001 From: osenan Date: Fri, 19 Dec 2025 10:18:30 -0300 Subject: [PATCH 3/7] feat: add test for missing function and update function to handle multiple values --- R/column_functions.R | 2 +- tests/testthat/test-column_functions.R | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/test-column_functions.R diff --git a/R/column_functions.R b/R/column_functions.R index a2499218..b49f2997 100644 --- a/R/column_functions.R +++ b/R/column_functions.R @@ -12,7 +12,7 @@ #' @export #' get_dataset_prefixed_col_names <- function(data) { - if (!is.null(attr(data, "filter_and_columns")$columns) && attr(data, "filter_and_columns")$columns != "") { + if (any(!is.null(attr(data, "filter_and_columns")$columns)) && all(attr(data, "filter_and_columns")$columns != "")) { paste(attr(data, "dataname"), attr(data, "filter_and_columns")$columns, sep = ".") } else { NULL diff --git a/tests/testthat/test-column_functions.R b/tests/testthat/test-column_functions.R new file mode 100644 index 00000000..4f42fb8d --- /dev/null +++ b/tests/testthat/test-column_functions.R @@ -0,0 +1,13 @@ +testthat::test_that("get_dataset_prefixed_col_names returns vector of columns", { + data_test <- data.frame() + attr(data_test, "filter_and_columns") <- list(columns = c("col_1")) + + testthat::expect_identical(".col_1", get_dataset_prefixed_col_names(data_test)) +}) + +testthat::test_that("get_dataset_prefixed_col_names returns vector of multiple columns", { + data_test <- data.frame() + attr(data_test, "filter_and_columns") <- list(columns = c("col_1", "col_2")) + + testthat::expect_identical(c(".col_1", ".col_2"), get_dataset_prefixed_col_names(data_test)) +}) From 68fa0ebee75ca7519ab1d5e0d0a6594c6b2fa8a7 Mon Sep 17 00:00:00 2001 From: osenan Date: Fri, 19 Dec 2025 11:28:52 -0300 Subject: [PATCH 4/7] tests: add test for is_single_dataset function --- tests/testthat/test-data_extract_datanames.R | 64 ++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/testthat/test-data_extract_datanames.R b/tests/testthat/test-data_extract_datanames.R index 1e4fe13c..d3bb6f4a 100644 --- a/tests/testthat/test-data_extract_datanames.R +++ b/tests/testthat/test-data_extract_datanames.R @@ -111,3 +111,67 @@ testthat::test_that("datanames_input gets the data names provided to module", { testthat::expect_s3_class(input_names, "shiny.tag") testthat::expect_true(grepl("ADTTE", as.character(input_names))) }) + +testthat::test_that("data_extract_datanames returns TRUE in single dataset", { + adtte_filters <- filter_spec( + vars = c("PARAMCD", "CNSR"), + sep = "-", + choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), + selected = "OS-1", + multiple = FALSE, + label = "Choose endpoint and Censor" + ) + + data_spec <- data_extract_spec( + dataname = "ADTTE", + filter = adtte_filters, + select = select_spec( + choices = c("AVAL", "BMRKR1", "AGE"), + selected = c("AVAL", "BMRKR1"), + multiple = TRUE, + fixed = FALSE, + label = "Column" + ) + ) + + testthat::expect_true(is_single_dataset((data_spec))) + +}) + +testthat::test_that("data_extract_datanames returns FALSE in multiple datasets", { + adtte_filters <- filter_spec( + vars = c("PARAMCD", "CNSR"), + sep = "-", + choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), + selected = "OS-1", + multiple = FALSE, + label = "Choose endpoint and Censor" + ) + + data_spec_1 <- data_extract_spec( + dataname = "ADTTE", + filter = adtte_filters, + select = select_spec( + choices = c("AVAL", "BMRKR1", "AGE"), + selected = c("AVAL", "BMRKR1"), + multiple = TRUE, + fixed = FALSE, + label = "Column" + ) + ) + + + data_spec_2 <- data_extract_spec( + dataname = "ADTTE2", + filter = adtte_filters, + select = select_spec( + choices = c("AVAL", "BMRKR1", "AGE"), + selected = c("AVAL", "BMRKR1"), + multiple = TRUE, + fixed = FALSE, + label = "Column" + ) + ) + + testthat::expect_false(is_single_dataset(data_spec_1, data_spec_2)) +}) From 5041eeaddeb853092e9c49220ff37ffcde458610 Mon Sep 17 00:00:00 2001 From: osenan Date: Fri, 19 Dec 2025 11:37:07 -0300 Subject: [PATCH 5/7] tests: add test for no_selected_as_NULL --- tests/testthat/test-choices_selected.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/testthat/test-choices_selected.R b/tests/testthat/test-choices_selected.R index 3a08a78d..5cc85aa4 100644 --- a/tests/testthat/test-choices_selected.R +++ b/tests/testthat/test-choices_selected.R @@ -207,3 +207,10 @@ testthat::test_that("if we call add_no_selected_choices we add no selection", { choices_list <- add_no_selected_choices(choices_list) testthat::expect_true(any(grepl("no selection", choices_list$choices))) }) + +testthat::test_that("no_selected_as_NULL returns NULL if word is within no selected", { + testthat::expect_null(no_selected_as_NULL(NULL)) + testthat::expect_null(no_selected_as_NULL(no_select_keyword)) + testthat::expect_true(!is.null(no_selected_as_NULL("random"))) +}) + From ab758f4ae2646f9b2bcfcc48ac4f30a42223c079 Mon Sep 17 00:00:00 2001 From: osenan Date: Fri, 19 Dec 2025 11:42:28 -0300 Subject: [PATCH 6/7] chore: fix lintr --- tests/testthat/test-choices_selected.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-choices_selected.R b/tests/testthat/test-choices_selected.R index 5cc85aa4..88005bd5 100644 --- a/tests/testthat/test-choices_selected.R +++ b/tests/testthat/test-choices_selected.R @@ -213,4 +213,3 @@ testthat::test_that("no_selected_as_NULL returns NULL if word is within no selec testthat::expect_null(no_selected_as_NULL(no_select_keyword)) testthat::expect_true(!is.null(no_selected_as_NULL("random"))) }) - From 23628228cf978347817fba4544993d22f7fd5a9d Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 19 Dec 2025 14:44:38 +0000 Subject: [PATCH 7/7] [skip style] [skip vbump] Restyle files --- tests/testthat/test-data_extract_datanames.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-data_extract_datanames.R b/tests/testthat/test-data_extract_datanames.R index d3bb6f4a..c7053ee8 100644 --- a/tests/testthat/test-data_extract_datanames.R +++ b/tests/testthat/test-data_extract_datanames.R @@ -135,7 +135,6 @@ testthat::test_that("data_extract_datanames returns TRUE in single dataset", { ) testthat::expect_true(is_single_dataset((data_spec))) - }) testthat::test_that("data_extract_datanames returns FALSE in multiple datasets", {