diff --git a/R/f7Notif.R b/R/f7Notif.R index 6749a904..e054addc 100644 --- a/R/f7Notif.R +++ b/R/f7Notif.R @@ -26,11 +26,11 @@ #' title = "My app", #' f7SingleLayout( #' navbar = f7Navbar(title = "f7Notif"), -#' f7Button(inputId = "goButton", "Go!") +#' f7Block(f7Button(inputId = "goButton", "Go!")) #' ) #' ), #' server = function(input, output, session) { -#' observeEvent(input$goButton,{ +#' observeEvent(input$goButton, { #' f7Notif( #' text = "test", #' icon = f7Icon("bolt_fill"), @@ -46,7 +46,6 @@ f7Notif <- function(text, icon = NULL, title = NULL, titleRightText = NULL, subt closeTimeout = 5000, closeButton = FALSE, closeOnClick = TRUE, swipeToClose = TRUE, ..., session = shiny::getDefaultReactiveDomain()) { - if (!is.null(icon)) icon <- as.character(icon) message <- dropNulls( @@ -72,6 +71,4 @@ f7Notif <- function(text, icon = NULL, title = NULL, titleRightText = NULL, subt json_verbatim = TRUE ) ) - } - diff --git a/inst/examples/dialog/app.R b/inst/examples/dialog/app.R index 225713a6..bb4f5b3b 100644 --- a/inst/examples/dialog/app.R +++ b/inst/examples/dialog/app.R @@ -72,5 +72,4 @@ app <- shinyApp( } ) -app -# if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app +if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app diff --git a/man/f7Dialog.Rd b/man/f7Dialog.Rd index 7da1bef9..86969cbe 100644 --- a/man/f7Dialog.Rd +++ b/man/f7Dialog.Rd @@ -102,6 +102,5 @@ app <- shinyApp( } ) -app -# if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app +if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app } diff --git a/man/f7Notif.Rd b/man/f7Notif.Rd index c689c7e3..70790e90 100644 --- a/man/f7Notif.Rd +++ b/man/f7Notif.Rd @@ -54,11 +54,11 @@ if (interactive()) { title = "My app", f7SingleLayout( navbar = f7Navbar(title = "f7Notif"), - f7Button(inputId = "goButton", "Go!") + f7Block(f7Button(inputId = "goButton", "Go!")) ) ), server = function(input, output, session) { - observeEvent(input$goButton,{ + observeEvent(input$goButton, { f7Notif( text = "test", icon = f7Icon("bolt_fill"), diff --git a/tests/testthat/test-f7Notif.R b/tests/testthat/test-f7Notif.R new file mode 100644 index 00000000..a6665f75 --- /dev/null +++ b/tests/testthat/test-f7Notif.R @@ -0,0 +1,24 @@ +test_that("notif R function", { + session <- as.environment(list( + ns = identity, + sendCustomMessage = function(type, message) { + session$lastCustomMessage <- list(type = type, message = message) + } + )) + + f7Notif( + text = "test", + icon = f7Icon("bolt_fill"), + title = "Notification", + subtitle = "A subtitle", + titleRightText = "now", + session = session + ) + + res <- session$lastCustomMessage + res$message <- jsonlite::fromJSON(res$message) + expect_length(res, 2) + expect_equal(res$type, "notification") + expect_length(res$message, length(formals(f7Notif)) - 2) + expect_equal(res$message$closeTimeout, formals(f7Notif)$closeTimeout) +})