insightsengineering / teal.modules.clinical

Provides teal modules for the standard clinical trials outputs
https://insightsengineering.github.io/teal.modules.clinical/
Other
32 stars 17 forks source link

Extensive test for combination of inputs in shinytest2 #1136

Open kartikeyakirar opened 6 months ago

kartikeyakirar commented 6 months ago

Feature description

extension to this :https://github.com/insightsengineering/teal.modules.clinical/pull/1135

As an additional feature test with helper functions, we could also add tests to check the combination of inputs for all the encodings. This would be an extensive test, but it would thoroughly check the depth of combination input testing. I am adding an issue for this potential use case and discussion.

# Function to test all combinations of inputs
test_input_combinations <- function(app_driver, input_ids, input_options, pws = NULL, tws = NULL) {
  # Create a data frame of all possible combinations of encodings
  combinations <- expand.grid(input_options, stringsAsFactors = FALSE)
  names(combinations) <- input_ids

  # Iterate over each row in the combinations data frame
  for (i in seq_len(nrow(combinations))) {
    # Determine the type of output to capture based on the input parameters
    if (!is.null(pws)) {
      output_before <- app_driver$get_active_module_pws_output(pws)
      output_type <- "pws"
    } else if (!is.null(tws)) {
      output_before <- app_driver$get_active_module_tws_output(tws)
      output_type <- "tws"
    } else {
      stop("Either pws or tws must be provided.")
    }

    # Set each input and check for errors
    for (j in seq_along(input_ids)) {
      app_driver$set_active_module_input(input_ids[j], combinations[i, j])
      app_driver$expect_no_validation_error()
    }

    if (output_type == "pws") {
      testthat::expect_false(identical(output_before, app_driver$get_active_module_pws_output(pws)))
    } else {
      testthat::expect_false(identical(output_before, app_driver$get_active_module_tws_output(tws)))
    }
  }
}

# Example usage
input_ids <- c("input1", "input2", "input3")
input_options <- list(
  c("option1_1", "option1_2"),        # Input 1 has 2 options
  c("option2_1", "option2_2", "option2_3", "option2_4", "option2_5", 
    "option2_6", "option2_7", "option2_8", "option2_9", "option2_10"),  # Input 2 has 10 options
  c("option3_1", "option3_2", "option3_3", "option3_4", "option3_5", "option3_6")  # Input 3 has 6 options
)

# Fun call 
test_input_combinations(app_driver, input_ids, input_options, "example_pws")

Code of Conduct

Contribution Guidelines

Security Policy

donyunardi commented 4 months ago

I would like to postpone this until we have consistent passing daily integration tests. Once that happens, we can start discussing it.