Skip to content

Commit

Permalink
autocomplete shinytest2
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Mar 16, 2024
1 parent 5470659 commit 9bb28df
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 4 deletions.
38 changes: 38 additions & 0 deletions inst/examples/autocomplete/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
library(shiny)
library(shinyMobile)

app <- shinyApp(
ui = f7Page(
title = "My app",
f7SingleLayout(
navbar = f7Navbar(title = "Update autocomplete"),
f7Block(f7Button(inputId = "update", label = "Update autocomplete")),
f7Block(
f7AutoComplete(
inputId = "myautocomplete",
placeholder = "Some text here!",
openIn = "dropdown",
label = "Type a fruit name",
choices = c(
"Apple", "Apricot", "Avocado", "Banana", "Melon",
"Orange", "Peach", "Pear", "Pineapple"
)
),
verbatimTextOutput("autocompleteval")
)
)
),
server = function(input, output, session) {
output$autocompleteval <- renderText(input$myautocomplete)

observeEvent(input$update, {
updateF7AutoComplete(
inputId = "myautocomplete",
value = "plip",
choices = c("plip", "plap", "ploup")
)
})
}
)

if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"input": {
"myautocomplete": "Apple"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"input": {
"myautocomplete": "plip"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions tests/testthat/test-f7ActionSheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ test_that("actionSheet work as expected", {
app$expect_values(input = c("sheet1-action1", "sheet1-action1_button"))

app$click(selector = "#sheet1-go")
app$wait_for_idle(2000)
app$wait_for_idle(3000)
app$expect_values(input = c("sheet1-action1"))

app$click(selector = ".actions-button:first-child")
app$wait_for_idle(2000)
app$wait_for_idle(3000)
app$expect_values(input = c("sheet1-action1", "sheet1-action1_button"))

app$click(selector = "#sheet1-go")
app$wait_for_idle(2000)
app$wait_for_idle(3000)
app$click(selector = ".actions-button:nth-child(2)")
app$expect_values(input = c("sheet1-action1", "sheet1-action1_button"))

app$click(selector = "#sheet1-update")
app$click(selector = "#sheet1-go")
app$wait_for_idle(2000)
app$wait_for_idle(3000)
app$expect_values(input = c("sheet1-action1", "sheet1-action1_button"))
})
16 changes: 16 additions & 0 deletions tests/testthat/test-f7AutoComplete.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
test_that("autocomplete works", {
# Don't run these tests on the CRAN build servers
skip_on_cran()
shiny_app_path <-
system.file("examples/autocomplete/app.R", package = "shinyMobile")
app <- AppDriver$new(
shiny_app_path,
name = "autocomplete-app",
variant = platform_variant()
)
app$expect_values(input = "myautocomplete")
app$click(selector = "#update")
# Wait for any animation to complete
app$wait_for_idle(1000)
app$expect_values(input = "myautocomplete")
})

0 comments on commit 9bb28df

Please sign in to comment.