Skip to content

Commit

Permalink
check + test f7Notif
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Mar 16, 2024
1 parent e3141d5 commit 1bdfc03
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
7 changes: 2 additions & 5 deletions R/f7Notif.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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(
Expand All @@ -72,6 +71,4 @@ f7Notif <- function(text, icon = NULL, title = NULL, titleRightText = NULL, subt
json_verbatim = TRUE
)
)

}

3 changes: 1 addition & 2 deletions inst/examples/dialog/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ app <- shinyApp(
}
)

app
# if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app
if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app
3 changes: 1 addition & 2 deletions man/f7Dialog.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/f7Notif.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions tests/testthat/test-f7Notif.R
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit 1bdfc03

Please sign in to comment.