diff --git a/DESCRIPTION b/DESCRIPTION index 53279592..1c740367 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: clinsight Title: ClinSight -Version: 0.0.0.9005 +Version: 0.0.0.9006 Authors@R: c( person("Leonard Daniƫl", "Samson", , "lsamson@gcp-service.com", role = c("cre", "aut")), person("GCP-Service International Ltd.& Co. KG", role = "fnd") diff --git a/NEWS.md b/NEWS.md index 7b59cfd1..a978493b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,3 +17,4 @@ to minimize the package dependencies of the production version. ## Bug fixes - Fixed error of creating adverse events table with empty data frame input. +- Properly handled zero regions selected in review configuration and provided user feedback. diff --git a/R/mod_review_config.R b/R/mod_review_config.R index ed64d9f4..4c9d313f 100644 --- a/R/mod_review_config.R +++ b/R/mod_review_config.R @@ -113,7 +113,6 @@ mod_review_config_server <- function( observeEvent(input$config_review, showModal(review_modal())) observeEvent(input$region_selection, { - req(input$region_selection, input$site_selection) selected_sites <- with(sites, site_code[region %in% input$region_selection]) golem::cat_dev("update region selection to ", selected_sites, "\n") shinyWidgets::updatePickerInput( @@ -122,6 +121,11 @@ mod_review_config_server <- function( choices = selected_sites, selected = selected_sites ) + }, ignoreNULL = FALSE, ignoreInit = TRUE) + + output$review_config_feedback <- renderText({ + req(!isTruthy(input$region_selection) | !isTruthy(input$site_selection)) + "You must select at least one site/region to review." }) observeEvent(input$save_review_config, { diff --git a/tests/testthat/_snaps/mod_review_config/mod_review_config-001.json b/tests/testthat/_snaps/mod_review_config/mod_review_config-001.json index 275b750e..acca5029 100644 --- a/tests/testthat/_snaps/mod_review_config/mod_review_config-001.json +++ b/tests/testthat/_snaps/mod_review_config/mod_review_config-001.json @@ -20,6 +20,13 @@ ] }, "output": { - + "test-review_config_feedback": { + "message": "", + "call": "NULL", + "type": [ + "shiny.silent.error", + "validation" + ] + } } } diff --git a/tests/testthat/_snaps/mod_review_config/mod_review_config-002.json b/tests/testthat/_snaps/mod_review_config/mod_review_config-002.json index 18bf37dd..64597ce4 100644 --- a/tests/testthat/_snaps/mod_review_config/mod_review_config-002.json +++ b/tests/testthat/_snaps/mod_review_config/mod_review_config-002.json @@ -1,14 +1,11 @@ { "input": { "test-config_review": 1, - "test-region_selection": "DEU", + "test-region_selection": null, "test-save_review_config": 0, - "test-site_selection": [ - "Site 01", - "Site 02" - ] + "test-site_selection": null }, "output": { - + "test-review_config_feedback": "You must select at least one site/region to review." } } diff --git a/tests/testthat/_snaps/mod_review_config/mod_review_config-002_.png b/tests/testthat/_snaps/mod_review_config/mod_review_config-002_.png index 8f09ae6f..44cfd3a2 100644 Binary files a/tests/testthat/_snaps/mod_review_config/mod_review_config-002_.png and b/tests/testthat/_snaps/mod_review_config/mod_review_config-002_.png differ diff --git a/tests/testthat/_snaps/mod_review_config/mod_review_config-003.json b/tests/testthat/_snaps/mod_review_config/mod_review_config-003.json index f21deca0..9ee8821e 100644 --- a/tests/testthat/_snaps/mod_review_config/mod_review_config-003.json +++ b/tests/testthat/_snaps/mod_review_config/mod_review_config-003.json @@ -9,6 +9,13 @@ ] }, "output": { - + "test-review_config_feedback": { + "message": "", + "call": "NULL", + "type": [ + "shiny.silent.error", + "validation" + ] + } } } diff --git a/tests/testthat/_snaps/mod_review_config/mod_review_config-003_.png b/tests/testthat/_snaps/mod_review_config/mod_review_config-003_.png index ccf6b133..8f09ae6f 100644 Binary files a/tests/testthat/_snaps/mod_review_config/mod_review_config-003_.png and b/tests/testthat/_snaps/mod_review_config/mod_review_config-003_.png differ diff --git a/tests/testthat/_snaps/mod_review_config/mod_review_config-004.json b/tests/testthat/_snaps/mod_review_config/mod_review_config-004.json new file mode 100644 index 00000000..a9e0668a --- /dev/null +++ b/tests/testthat/_snaps/mod_review_config/mod_review_config-004.json @@ -0,0 +1,21 @@ +{ + "input": { + "test-config_review": 1, + "test-region_selection": "DEU", + "test-save_review_config": 2, + "test-site_selection": [ + "Site 01", + "Site 02" + ] + }, + "output": { + "test-review_config_feedback": { + "message": "", + "call": "NULL", + "type": [ + "shiny.silent.error", + "validation" + ] + } + } +} diff --git a/tests/testthat/_snaps/mod_review_config/mod_review_config-004_.png b/tests/testthat/_snaps/mod_review_config/mod_review_config-004_.png new file mode 100644 index 00000000..ccf6b133 Binary files /dev/null and b/tests/testthat/_snaps/mod_review_config/mod_review_config-004_.png differ diff --git a/tests/testthat/test-mod_review_config.R b/tests/testthat/test-mod_review_config.R index 2d7d257c..6d672a49 100644 --- a/tests/testthat/test-mod_review_config.R +++ b/tests/testthat/test-mod_review_config.R @@ -106,8 +106,11 @@ describe( and sites 'Site 01' and 'Site 02' belonging to region 'DEU', and clicking on [settings], I expect to see the modal to select regions and sites to review, - and given that I deselect regions 'NLD' and 'BEL', - I expect that only the sites 'Site 01' and 'Site 02' are still selected, + and given that I deselect all regions and click on [Save], + I expect that I will get the message 'You must select at least one site/region to review.', + and that the data within the app will not be updated with the empty selection, + and given that I select region 'DEU', + I expect that only the sites 'Site 01' and 'Site 02' will be selected, and given that I click on [Save], I expect that a confirmation will be shown with the text 'Review configuration applied successfully', and that the data within the app only contains data of 'Site 01' and 'Site 02'. ", @@ -146,6 +149,17 @@ describe( withr::defer(app$stop()) app$click("test-config_review") app$expect_values(input = TRUE, output = TRUE) + app$set_inputs(`test-region_selection` = "") + app$expect_values(input = TRUE, output = TRUE) + app$click("test-save_review_config") + filtered_data <- app$get_value(export = "filtered_data") + all_sites <- lapply(filtered_data, \(x){x[["site_code"]]}) |> + unlist() |> + unique() + expect_equal( + all_sites[order(all_sites)], + sort(vars$Sites$site_code) + ) app$set_inputs(`test-region_selection` = "DEU") app$expect_values(input = TRUE, output = TRUE) app$click("test-save_review_config") @@ -162,4 +176,3 @@ describe( ) } ) -