Skip to content

Commit

Permalink
add test for validateF7Input
Browse files Browse the repository at this point in the history
  • Loading branch information
hypebright committed Mar 28, 2024
1 parent aedb9b8 commit e542a37
Showing 5 changed files with 94 additions and 45 deletions.
2 changes: 1 addition & 1 deletion R/f7-validate-inputs.R
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
#' @param error Error text.
#' @param session Shiny session object.
#'
#' @note Only works for \link{f7Text}, \link{f7Password}, \link{f7TextArea} and \link{f7Select}.
#' @note Only works for \link{f7Text}, \link{f7Password} and \link{f7TextArea}.
#' See more at \url{https://framework7.io/docs/inputs.html}.
#'
#' @example inst/examples/validateinput/app.R
7 changes: 0 additions & 7 deletions inst/examples/validateinput/app.R
Original file line number Diff line number Diff line change
@@ -22,13 +22,6 @@ app <- shinyApp(
f7Password(
inputId = "password",
label = "Password"
),
hr(),
f7Select(
inputId = "select",
label = "Select",
choices = c("A", "B", "C"),
selected = character(0)
)
)
),
86 changes: 49 additions & 37 deletions man/validation.Rd

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

4 changes: 4 additions & 0 deletions tests/testthat/_snaps/mac-4.3/validateF7Input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# input validation works as expected

"<input id=\"caption2\" value=\"1\" type=\"text\" class=\"input-with-value shiny-bound-input\" required=\"required\" validate=\"\" pattern=\"[0-9]*\" data-error-message=\"Only numbers please!\">"

40 changes: 40 additions & 0 deletions tests/testthat/test-validateF7Input.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
test_that("Input validation R function works", {
session <- as.environment(list(
ns = identity,
sendCustomMessage = function(type, message) {
session$lastCustomMessage <- list(type = type, message = message)
}
))

validateF7Input(
inputId = "caption2",
pattern = "[0-9]*",
error = "Only numbers please!",
session = session
)

res <- session$lastCustomMessage
expect_length(res, 2)
expect_equal(res$type, "validate-input")
expect_length(res$message, length(formals(validateF7Input)) - 2)
expect_equal(res$message$target, "caption2")
})

library(shinytest2)
test_that("input validation works as expected", {
# Don't run these tests on the CRAN build servers
skip_on_cran()
shiny_app_path <-
system.file("examples/validateinput/app.R", package = "shinyMobile")

app <- AppDriver$new(
shiny_app_path,
name = "validateinput-app",
variant = platform_variant()
)

app$wait_for_idle(1000)
# Expect props to be present in HTML: there are no Shiny inputs/outputs related to tooltips
app$expect_html(selector = "#caption2")

})

0 comments on commit e542a37

Please sign in to comment.