From b839100548946c8fed0b4eed920fce07f8f26a85 Mon Sep 17 00:00:00 2001 From: federiva Date: Thu, 27 Apr 2023 18:31:22 -0300 Subject: [PATCH 1/5] tests: Adding tests --- tests/testthat/test_modal.R | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/tests/testthat/test_modal.R b/tests/testthat/test_modal.R index 0e07e8a2..8b15b361 100644 --- a/tests/testthat/test_modal.R +++ b/tests/testthat/test_modal.R @@ -110,3 +110,85 @@ test_that("test modalDialog", { )) }) + + +testthat::test_that( + "show_modal with asis as TRUE sends exactly the id passed to the + session$sendCustomMessage function", + { + # Prepare the stub to check what is passed to the + # session$sendCustomMessage method + stub_custom_message <- + function(message, parameters) { + list(message = message, + parameters = parameters) + } + mockery::stub(where = show_modal, what = "session$sendCustomMessage", stub_custom_message) + # Mocking the Shiny session + session <- shiny::MockShinySession$new() + # Mocking a module's session + module_session <- session$makeScope("new") + # Act + result <- show_modal("id", session = module_session, asis = TRUE) + + # Assert + testthat::expect_equal(result$message, "showSemanticModal") + testthat::expect_equal(result$parameters$id, "id") + testthat::expect_equal(result$parameters$action, "show") + } +) + +testthat::test_that( + "show_modal with asis as FALSE namespaces the id passed to the + session$sendCustomMessage function when it IS IN the context + of a sessionproxy (shiny module)", + { + # Prepare the stub to check what is passed to the + # session$sendCustomMessage method + stub_custom_message <- function(message, parameters) { + list( + message = message, + parameters = parameters + ) + } + mockery::stub(where = show_modal, what = "session$sendCustomMessage", stub_custom_message) + # Mocking the Shiny session + session <- shiny::MockShinySession$new() + # Mocking a module's session + module_session <- session$makeScope("new") + # Act + result <- show_modal("id", session = module_session, asis = FALSE) + + # Assert + testthat::expect_equal(result$message, "showSemanticModal") + testthat::expect_equal(result$parameters$id, "new-id") + testthat::expect_equal(result$parameters$action, "show") + } +) + + +testthat::test_that( + "show_modal with asis as FALSE do not namespace the id passed to the + session$sendCustomMessage function when it IS NOT in the context + of a sessionproxy (shiny module)", + { + # Prepare the stub to check what is passed to the + # session$sendCustomMessage method + stub_custom_message <- function(message, parameters) { + list( + message = message, + parameters = parameters + ) + } + mockery::stub(where = show_modal, what = "session$sendCustomMessage", stub_custom_message) + # Mocking the Shiny session + session <- shiny::MockShinySession$new() + # Act + result <- show_modal("id", session = session, asis = FALSE) + + # Assert + testthat::expect_equal(result$message, "showSemanticModal") + testthat::expect_equal(result$parameters$id, "id") + testthat::expect_equal(result$parameters$action, "show") + } +) From d6374501a7002e156f87e393c8260d112c20e908 Mon Sep 17 00:00:00 2001 From: federiva Date: Thu, 27 Apr 2023 18:31:29 -0300 Subject: [PATCH 2/5] docs: updating docs --- man/show_modal.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/show_modal.Rd b/man/show_modal.Rd index 8bfa2cfa..a1201391 100644 --- a/man/show_modal.Rd +++ b/man/show_modal.Rd @@ -25,7 +25,7 @@ hide_modal(id, session = shiny::getDefaultReactiveDomain(), asis = TRUE) \code{shinyServer}.} \item{asis}{A boolean indicating if the id must be handled as is (TRUE) or -will be it must be namespaced (FALSE)} +FALSE if it meants to be namespaced} } \description{ This displays a hidden Semantic UI modal. From dcd9ab3a4be21faaf10460309a100efe1c9cb1c4 Mon Sep 17 00:00:00 2001 From: federiva Date: Thu, 27 Apr 2023 18:31:40 -0300 Subject: [PATCH 3/5] fix: evaluating asis parameter --- R/modal.R | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/R/modal.R b/R/modal.R index f994f069..2be5280c 100644 --- a/R/modal.R +++ b/R/modal.R @@ -278,7 +278,7 @@ attach_rule <- function(id, behavior, target, value) { #' @param session The \code{session} object passed to function given to #' \code{shinyServer}. #' @param asis A boolean indicating if the id must be handled as is (TRUE) or -#' will be it must be namespaced (FALSE) +#' FALSE if it meants to be namespaced #' @seealso modal #' #' @rdname show_modal @@ -286,7 +286,9 @@ attach_rule <- function(id, behavior, target, value) { #' @export show_modal <- function(id, session = shiny::getDefaultReactiveDomain(), asis = TRUE) { - id <- ifelse(inherits(session, "session_proxy"), session$ns(id), id) + if (!asis) { + id <- ifelse(inherits(session, "session_proxy"), session$ns(id), id) + } session$sendCustomMessage("showSemanticModal", list(id = id, action = "show")) # nolint } @@ -299,7 +301,9 @@ showModal <- function(ui, session = shiny::getDefaultReactiveDomain()) { #' @export remove_modal <- function(id, session = shiny::getDefaultReactiveDomain(), asis = TRUE) { - id <- ifelse(inherits(session, "session_proxy"), session$ns(id), id) + if (!asis) { + id <- ifelse(inherits(session, "session_proxy"), session$ns(id), id) + } shiny::removeUI(paste0("#", id)) } @@ -320,6 +324,8 @@ removeModal <- function(session = shiny::getDefaultReactiveDomain()) { #' @export hide_modal <- function(id, session = shiny::getDefaultReactiveDomain(), asis = TRUE) { - id <- ifelse(inherits(session, "session_proxy"), session$ns(id), id) + if (!asis) { + id <- ifelse(inherits(session, "session_proxy"), session$ns(id), id) + } session$sendCustomMessage("showSemanticModal", list(id = id, action = "hide")) # nolint } From 2bac03344bace1eaba6c313a2fb8aeedd1ada61b Mon Sep 17 00:00:00 2001 From: federiva Date: Thu, 27 Apr 2023 18:40:16 -0300 Subject: [PATCH 4/5] build: Adding mockery --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 68cd4703..14e259d5 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -52,5 +52,6 @@ Suggests: plotly, rmarkdown, markdown, - rcmdcheck + rcmdcheck, + mockery RoxygenNote: 7.2.1 From 98f9dad57f0d58f2b69cb4c122106e2613a677b4 Mon Sep 17 00:00:00 2001 From: federiva Date: Thu, 4 May 2023 10:27:55 -0300 Subject: [PATCH 5/5] build: updating version number --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 14e259d5..aebe875a 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: shiny.semantic Type: Package Title: Semantic UI Support for Shiny -Version: 0.4.3 +Version: 0.4.3.9000 Authors@R: c(person("Filip", "Stachura", email = "filip@appsilon.com", role = "aut"), person("Dominik", "Krzeminski", email = "dominik@appsilon.com", role = "aut"), person("Krystian", "Igras", email = "krystian@appsilon.com", role = "aut"),