Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/column_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 (!is.null(attr(data, "filter_and_columns", exact = TRUE)$columns) && all(attr(data, "filter_and_columns", exact = TRUE)$columns != "")) {

Check warning on line 15 in R/column_functions.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/column_functions.R,line=15,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 142 characters.
paste(attr(data, "dataname"), attr(data, "filter_and_columns")$columns, sep = ".")
} else {
NULL
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-choices_selected.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,20 @@ 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("add_no_selected_choices actually does not add any 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 only if word is NULL or equals `no_select_keyword`", {
testthat::expect_null(no_selected_as_NULL(NULL))
testthat::expect_null(no_selected_as_NULL(""))
testthat::expect_null(no_selected_as_NULL(no_select_keyword))
testthat::expect_failure(testthat::expect_null(no_selected_as_NULL("random")))
})
13 changes: 13 additions & 0 deletions tests/testthat/test-column_functions.R
Original file line number Diff line number Diff line change
@@ -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))
})
91 changes: 91 additions & 0 deletions tests/testthat/test-data_extract_datanames.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Loading