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-choices_selected.R b/tests/testthat/test-choices_selected.R index 4cf40b41..88005bd5 100644 --- a/tests/testthat/test-choices_selected.R +++ b/tests/testthat/test-choices_selected.R @@ -197,3 +197,19 @@ 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))) +}) + +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"))) +}) 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)) +}) diff --git a/tests/testthat/test-data_extract_datanames.R b/tests/testthat/test-data_extract_datanames.R index 226f7f04..c7053ee8 100644 --- a/tests/testthat/test-data_extract_datanames.R +++ b/tests/testthat/test-data_extract_datanames.R @@ -83,3 +83,94 @@ 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))) +}) + +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)) +})