-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jakub Sobolewski
committed
Sep 12, 2023
1 parent
e0d9baa
commit ce0a740
Showing
3 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# ❯ checking for detritus in the temp directory ... NOTE | ||
# Found the following files/directories: | ||
# ‘Crashpad’ | ||
# | ||
# 0 errors ✔ | 0 warnings ✔ | 1 note ✖ | ||
# Error: Error: R CMD check found NOTEs | ||
# Flavors: ubuntu-22.04 (devel), ubuntu-22.04 (release), ubuntu-22.04 (oldrel) | ||
|
||
# References (shinytest2 github): | ||
# 1. https://github.com/rstudio/shinytest2/blob/main/cran-comments.md | ||
# 2. https://github.com/rstudio/shinytest2/blob/main/tests/testthat/setup-disable-crashpad.R | ||
|
||
# Disable crash reporting on CRAN machines. (Can't get the report anyways) | ||
chromote::set_chrome_args(c( | ||
# https://peter.sh/experiments/chromium-command-line-switches/#disable-crash-reporter | ||
#> Disable crash reporter for headless. It is enabled by default in official builds | ||
"--disable-crash-reporter", | ||
chromote::default_chrome_args() | ||
)) | ||
|
||
# Make sure the temp folder is removed when testing is complete | ||
withr::defer({ | ||
|
||
# Clean up chromote sessions | ||
gc() # Run R6 finalizer methods | ||
Sys.sleep(2) # Wait for any supervisors to exit | ||
|
||
# Delete the Crashpad folder if it exists | ||
unlink(file.path(tempdir(), "Crashpad"), recursive = TRUE) | ||
}, envir = testthat::teardown_env()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
init_driver <- function(app) { | ||
shinytest2::AppDriver$new(app, variant = shinytest2::platform_variant()) | ||
} | ||
|
||
items <- function() { | ||
list( | ||
CommandBarItem( | ||
id = "new_item", | ||
key = "new_item_value", | ||
text = "New", | ||
cacheKey = "myCacheKey", | ||
split = TRUE, | ||
iconProps = list(iconName = "Add"), | ||
subMenuProps = list( | ||
items = list( | ||
CommandBarItem( | ||
key = "email_message_value", | ||
id = "email_message", | ||
text = "Email message", | ||
iconProps = list(iconName = "Mail") | ||
) | ||
) | ||
) | ||
), | ||
CommandBarItem( | ||
key = "download_value", | ||
id = "download", | ||
text = "Download", | ||
iconProps = list(iconName = "Download") | ||
) | ||
) | ||
} | ||
|
||
far_items <- function() { | ||
list( | ||
CommandBarItem( | ||
key = "tile_value", | ||
id = "tile", | ||
text = "Grid view", | ||
ariaLabel = "Grid view", | ||
iconOnly = TRUE, | ||
iconProps = list(iconName = "Tiles") | ||
) | ||
) | ||
} | ||
|
||
describe("CommandBar", { | ||
it("should set input of `key` of clicked CommandBarItem", { | ||
skip_on_cran() | ||
|
||
# Arrange | ||
app <- init_driver(shiny::shinyApp( | ||
ui = shiny::tagList( | ||
CommandBar( | ||
items = items(), | ||
farItems = far_items() | ||
) | ||
), | ||
server = function(input, output) { } | ||
)) | ||
withr::defer(app$stop()) | ||
|
||
# Act | ||
app$click(selector = "#download") | ||
value <- app$get_value(input = "download_value") | ||
|
||
# Assert | ||
expect_equal(value, 0) | ||
}) | ||
}) | ||
|
||
|
||
describe("CommandBar.shinyInput", { | ||
test_app <- function() { | ||
shiny::shinyApp( | ||
ui = shiny::tagList( | ||
CommandBar.shinyInput( | ||
inputId = "commandBar", | ||
items = items(), | ||
farItems = far_items() | ||
) | ||
), | ||
server = function(input, output) { } | ||
) | ||
} | ||
|
||
it("should yield NULL input value on startup", { | ||
skip_on_cran() | ||
|
||
# Arrange | ||
app <- init_driver(test_app()) | ||
withr::defer(app$stop()) | ||
|
||
# Act | ||
value <- app$get_value(input = "commandBar") | ||
|
||
# Assert | ||
expect_null(value) | ||
}) | ||
|
||
it("should set input on id of CommandBar with `key` value of clicked CommandBarItem", { | ||
skip_on_cran() | ||
|
||
# Arrange | ||
app <- init_driver(test_app()) | ||
withr::defer(app$stop()) | ||
|
||
# Act | ||
app$click(selector = "#download") | ||
value <- app$get_value(input = "commandBar") | ||
|
||
# Assert | ||
expect_equal(value, "download_value") | ||
}) | ||
|
||
it("should set input on id of CommandBar with `key` value of clicked nested CommandBarItem", { | ||
skip_on_cran() | ||
|
||
# Arrange | ||
app <- init_driver(test_app()) | ||
withr::defer(app$stop()) | ||
|
||
# Act | ||
# Click dropdown button which is a sibling of #new_item when using split = TRUE | ||
app$click(selector = "#new_item + button") | ||
app$click(selector = "#email_message") | ||
value <- app$get_value(input = "commandBar") | ||
|
||
# Assert | ||
expect_equal(value, "email_message_value") | ||
}) | ||
|
||
it("should set input on id of CommandBar with `key` value of a clicked farItem", { | ||
skip_on_cran() | ||
|
||
# Arrange | ||
app <- init_driver(test_app()) | ||
withr::defer(app$stop()) | ||
|
||
# Act | ||
app$click(selector = "#tile") | ||
value <- app$get_value(input = "commandBar") | ||
|
||
# Assert | ||
expect_equal(value, "tile_value") | ||
}) | ||
|
||
it("should work with unset `farItems`", { | ||
skip_on_cran() | ||
|
||
# Arrange | ||
app <- init_driver(shiny::shinyApp( | ||
ui = shiny::tagList( | ||
CommandBar.shinyInput( | ||
inputId = "commandBar", | ||
items = items() | ||
) | ||
), | ||
server = function(input, output) { } | ||
)) | ||
withr::defer(app$stop()) | ||
|
||
# Act | ||
app$click(selector = "#download") | ||
value <- app$get_value(input = "commandBar") | ||
|
||
# Assert | ||
expect_equal(value, "download_value") | ||
}) | ||
|
||
it("should work with unset `items`", { | ||
skip_on_cran() | ||
|
||
# Arrange | ||
app <- init_driver(shiny::shinyApp( | ||
ui = shiny::tagList( | ||
CommandBar.shinyInput( | ||
inputId = "commandBar", | ||
farItems = far_items() | ||
) | ||
), | ||
server = function(input, output) { } | ||
)) | ||
withr::defer(app$stop()) | ||
|
||
# Act | ||
app$click(selector = "#tile") | ||
value <- app$get_value(input = "commandBar") | ||
|
||
# Assert | ||
expect_equal(value, "tile_value") | ||
}) | ||
}) |