diff --git a/DESCRIPTION b/DESCRIPTION index 564b0b8f..02cc9fc7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,4 +45,4 @@ Encoding: UTF-8 Language: en-US LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 diff --git a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-download_menu.png b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-download_menu.png new file mode 100644 index 00000000..65a6e326 Binary files /dev/null and b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-download_menu.png differ diff --git a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-hidden.png b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-hidden.png new file mode 100644 index 00000000..ed3ce36e Binary files /dev/null and b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-hidden.png differ diff --git a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-resize_menu.png b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-resize_menu.png new file mode 100644 index 00000000..2fbecad7 Binary files /dev/null and b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-resize_menu.png differ diff --git a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-visible.png b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-visible.png new file mode 100644 index 00000000..e9f15cc7 Binary files /dev/null and b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-visible.png differ diff --git a/tests/testthat/_snaps/app_tws_ui/table_with_settings_ui/tws-initial_view.png b/tests/testthat/_snaps/app_tws_ui/table_with_settings_ui/tws-initial_view.png new file mode 100644 index 00000000..5e344057 Binary files /dev/null and b/tests/testthat/_snaps/app_tws_ui/table_with_settings_ui/tws-initial_view.png differ diff --git a/tests/testthat/helpers-with-settings.R b/tests/testthat/helpers-with-settings.R index 26e535db..d5cc329c 100644 --- a/tests/testthat/helpers-with-settings.R +++ b/tests/testthat/helpers-with-settings.R @@ -31,6 +31,55 @@ app_tws <- function() { ) } +#' Plot with settings app +#' +#' @description Example plot with setting app for testing using \code{shinytest2} +#' +#' @keywords internal +#' +app_pws <- function() { + shiny::shinyApp( + ui = shiny::fluidPage( + shinyjs::useShinyjs(), + shiny::actionButton("button", "Show/Hide"), + plot_with_settings_ui( + id = "plot_with_settings" + ) + ), + server = function(input, output, session) { + plot_r <- shiny::reactive({ + ggplot2::ggplot(data.frame(x = 1:5, y = 1:5)) + + ggplot2::geom_point(ggplot2::aes(x = 1:5, y = 1:5)) + }) + + show_hide_signal <- shiny::reactiveVal(TRUE) + + shiny::observeEvent(input$button, { + show_hide_signal( + !show_hide_signal() + ) + }) + + plot_data <- plot_with_settings_srv( + id = "plot_with_settings", + plot_r = plot_r, + height = c(400, 100, 1200), + width = c(500, 250, 750), + brushing = TRUE, + clicking = TRUE, + dblclicking = TRUE, + hovering = TRUE, + show_hide_signal = show_hide_signal + ) + + shiny::exportTestValues( + plot_r = plot_r, + plot_data = plot_data + ) + } + ) +} + #' Function to check if a function has a side effect of drawing something #' @param `function` function which possibly draws something. #' @return `logical(1)` whether the function has a side effect of drawing a plot. diff --git a/tests/testthat/test-plot_with_settings_ui.R b/tests/testthat/test-plot_with_settings_ui.R index 43a12d91..5ec845c9 100644 --- a/tests/testthat/test-plot_with_settings_ui.R +++ b/tests/testthat/test-plot_with_settings_ui.R @@ -6,4 +6,39 @@ testthat::test_that("plot_with_settings_ui returns shiny.tag.list", { testthat::expect_s3_class(plot_with_settings_ui("STH"), "shiny.tag.list") }) -library(shinytest2) +testthat::test_that("Plot with settings: UI screenshots", { + skip_on_cran() + skip_on_ci() + app <- AppDriver$new( + app_pws(), + name = "pws", + variant = "app_pws_ui" + ) + threshold <- 60 + kernel_size <- 20 + delay <- 0.3 + + # click on hide/show button + app$click("button") + app$expect_screenshot( + threshold = threshold, kernel_size = kernel_size, delay = delay, name = "hidden" + ) + app$click("button") + app$expect_screenshot( + threshold = threshold, kernel_size = kernel_size, delay = delay, name = "visible" + ) + + app$set_inputs(`plot_with_settings-downbutton-file_name` = "plot1") + app$set_inputs(`plot_with_settings-modal_downbutton-file_name` = "plot2") + + app$click("plot_with_settings-downbutton-downl") + app$expect_screenshot( + threshold = threshold, kernel_size = kernel_size, delay = delay, name = "download_menu" + ) + app$click("plot_with_settings-expbut") + app$expect_screenshot( + threshold = threshold, kernel_size = kernel_size, delay = delay, name = "resize_menu" + ) + + app$stop() +})