diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/app.R b/inst/apps/317-bslib-preset-shiny-dashboard/app.R new file mode 100644 index 0000000000..4e3e8cc0e7 --- /dev/null +++ b/inst/apps/317-bslib-preset-shiny-dashboard/app.R @@ -0,0 +1,371 @@ +library(shiny) +library(bslib) +library(htmltools) + +options( + sass.cache = FALSE, + shiny.autoreload = TRUE, + shiny.testmode = TRUE, + bslib.precompiled = FALSE +) + +toggle_class_buttons <- HTML(' +
+') + + +global_sidebar <- function(..., fg = NULL, bg = NULL) { + sidebar( + title = "Sidebar", + fg = fg, + bg = bg, + "Shared sidebar", + input_dark_mode(id = "dark_mode"), + ..., + toggle_class_buttons + ) +} + +card_a_nav <- + navset_card_underline( + title = "A Nav Card", + sidebar = sidebar( + title = "Sidebar A", + width = "200px", + position = "left", + "Left sidebar" + ), + nav_panel("One", plotly::plotlyOutput("bars")), + nav_panel("Two", "Second panel in the nav card") + ) + +card_a <- + card( + card_header("A Card"), + layout_sidebar( + fillable = TRUE, + sidebar = sidebar( + title = "Sidebar A", + width = "200px", + position = "left", + "Left sidebar" + ), + plotly::plotlyOutput("bars") + ), + card_footer("Footer A") + ) + +card_b <- + card( + card_header("B Card"), + layout_sidebar( + sidebar = sidebar( + title = "Sidebar B", + width = "200px", + position = "right", + "Right sidebar" + ), + plotly::plotlyOutput("line") + ), + card_footer("Footer B") + ) + +row_cards <- layout_columns(card_a_nav, card_b) + +row_value_boxes <- + layout_columns( + row_heights = "minmax(100px, 1fr)", + value_box( + "First", + "Thing One", + showcase = bsicons::bs_icon("pin-angle-fill") + ), + value_box( + "Second", + "Thing Two", + showcase = bsicons::bs_icon("boombox-fill") + ) + ) + +ui_navbar <- function(enable_dashboard = TRUE) { + page_navbar( + title = "Dashboard", + theme = bs_global_get(), + fillable = TRUE, + sidebar = global_sidebar(), + nav_spacer(), + nav_panel( + "Page", + row_value_boxes, + row_cards + ) + ) +} + +ui_navbar_fillable <- function(...) { + page_navbar( + title = "Dashboard", + theme = bs_global_get(), + fillable = TRUE, + nav_spacer(), + nav_item(input_dark_mode(id = "dark_mode")), + nav_item( + popover( + bsicons::bs_icon("gear-fill"), + toggle_class_buttons + ) + ), + nav_panel( + "Dash", + row_value_boxes, + row_cards + ), + nav_panel( + "About", + layout_columns( + card( + card_title("About this"), + lorem::ipsum(3, 2) + ), + card( + card_title("About that"), + lorem::ipsum(4, c(2, 1, 3, 2)) + ) + ) + ) + ) +} + +ui_sidebar <- function(enable_dashboard = TRUE) { + page_sidebar( + title = "Dashboard", + theme = bs_global_get(), + sidebar = global_sidebar(), + # bg = "green", + row_value_boxes, + row_cards + ) +} + +ui_fillable_navbar <- function(enable_dashboard = TRUE) { + page_fillable( + theme = bs_global_get(), + gap = 0, + padding = 0, + class = if (enable_dashboard) "bslib-page-dashboard", + navset_bar( + title = "Dashboard", + sidebar = global_sidebar(), + nav_spacer(), + nav_panel( + "Page", + class = "p-0 m-0", + row_value_boxes, + row_cards + ) |> htmltools::tagAppendAttributes(class = "m-0") + ) + ) +} + +ui_fillable_sidebar <- function(enable_dashboard = TRUE) { + page_fillable( + theme = bs_global_get(), + gap = 0, + padding = 0, + class = if (enable_dashboard) "bslib-page-dashboard", + layout_sidebar( + sidebar = global_sidebar(), + h2("Dashboard"), + row_value_boxes, + row_cards + ) |> htmltools::tagAppendAttributes(class = "m-0") + ) +} + +abs_dark_mode <- input_dark_mode( + id = "dark_mode", + style = htmltools::css( + position = "absolute", + top = "1em", + right = "1em" + ) +) + +ui_flow_dash <- function(enable_dashboard = TRUE) { + set.seed(2023*11*15) + + p <- page_fluid( + theme = bs_global_get(), + h2("Fluid Dashboard Page", class = "my-4"), + row_value_boxes, + lorem::ipsum(2, 2), + row_cards, + abs_dark_mode, + toggle_class_buttons + ) + + if (!enable_dashboard) return(p) + + # In the tests, the dashboard class is added w/ client-side JS, but it could + # be done manually by directly calling body. This path is not directly tested, + # but is included for symmetry with the other UIs and for manual testing. + tags$body(class = "bslib-page-dashboard", p) +} + +ui_flow_sidebar <- function(enable_dashboard = TRUE) { + set.seed(2023*11*15) + + p <- page_fixed( + theme = bs_global_get(), + h2("Fixed Dashboard Page"), + layout_sidebar( + sidebar = global_sidebar(), + row_value_boxes, + lorem::ipsum(2, 2), + row_cards + ) + ) + + if (!enable_dashboard) return(p) + + tags$body(class = "bslib-page-dashboard", p) +} + +ui_fillable_nested <- function(enable_dashboard = TRUE) { + page_fillable( + class = if (enable_dashboard) "bslib-page-dashboard main", + theme = bs_global_get(), + row_value_boxes, + card( + card_header("Outer Plots Card"), + class = "p-0", + layout_sidebar( + sidebar = global_sidebar(), + row_cards + ) + ) + ) +} + +server <- function(input, output, session) { + plotly_defaults <- function(p) { + p <- plotly::layout( + p, + margin = list(l = 0, r = 0, t = 0, b = 0), + font = list( + family = "Open Sans", + color = if (input$dark_mode == "dark") "white" else "#1D1F21" + ), + yaxis = list(gridcolor = if (input$dark_mode == "dark") "#303030"), + xaxis = list(gridcolor = if (input$dark_mode == "dark") "#303030"), + plot_bgcolor = "transparent", + paper_bgcolor = "transparent" + ) + + plotly::config(p, displayModeBar = FALSE) + } + + output$bars <- plotly::renderPlotly({ + plotly::plot_ly( + data.frame( + x = factor(1:5, labels = c("Fair", "Good", "Better", "Best", "Ideal")), + y = c(1610, 5002, 13234, 16905, 21551) + ), + x = ~x, + y = ~y + ) |> + plotly_defaults() + }) + + output$line <- plotly::renderPlotly({ + set.seed(4323) + + plotly::plot_ly( + data.frame( + x = seq.Date(as.Date("2020-01-01"), as.Date("2021-01-01"), by = "day"), + y = cumsum(rnorm(367, sd = 4)) + ), + x = ~x, + y = ~y, + type = "scatter", + mode = "lines" + ) |> + plotly_defaults() + }) +} + +ui <- function(req) { + q <- parseQueryString(req$QUERY_STRING) + if (is.null(q$ui)) q$ui <- "navbar" + q$ui <- gsub("-", "_", q$ui) + if (is.null(q$preset)) q$preset <- "shiny" + if (is.null(q$dashboard_class)) q$dashboard_class <- FALSE + + args <- list( + version = 5, + preset = q$preset, + bslib_dashboard_design = q[["dashboard"]], + bslib_enable_shadows = q[["shadows"]] + ) + + cli::cli_h1("New app scenario") + cli::cli_dl(c(args, dashboard_class = q$dashboard_class)) + + do.call(bs_global_theme, purrr::compact(args)) + + switch( + q$ui, + navbar = ui_navbar(q$dashboard_class), + sidebar = ui_sidebar(q$dashboard_class), + fillable_navbar = ui_fillable_navbar(enable_dashboard = q$dashboard_class), + fillable_sidebar = ui_fillable_sidebar(enable_dashboard = q$dashboard_class), + flow_dash = ui_flow_dash(enable_dashboard = q$dashboard_class), + flow_sidebar = ui_flow_sidebar(enable_dashboard = q$dashboard_class), + fillable_nested = ui_fillable_nested(enable_dashboard = q$dashboard_class), + navbar_fillable = ui_navbar_fillable() + ) +} + +shinyApp(ui, server) diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat.R b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat.R new file mode 100644 index 0000000000..7d25b5b9e4 --- /dev/null +++ b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat.R @@ -0,0 +1 @@ +shinytest2::test_app() diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_01_mode_light.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_01_mode_light.png new file mode 100644 index 0000000000..971ec7f8e2 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_01_mode_light.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_02_class_dashboard.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_02_class_dashboard.png new file mode 100644 index 0000000000..55bcb19b6f Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_02_class_dashboard.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_03_class_no-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_03_class_no-shadow.png new file mode 100644 index 0000000000..05602413dd Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_03_class_no-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_04_class_small-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_04_class_small-shadow.png new file mode 100644 index 0000000000..9c7605f6a6 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_04_class_small-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_05_mode_dark.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_05_mode_dark.png new file mode 100644 index 0000000000..8eca55cd27 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_05_mode_dark.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_06_classic.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_06_classic.png new file mode 100644 index 0000000000..549fd8881d Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_06_classic.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_07_classic_shadows.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_07_classic_shadows.png new file mode 100644 index 0000000000..41425fd1df Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-navbar_07_classic_shadows.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_01_mode_light.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_01_mode_light.png new file mode 100644 index 0000000000..6ec91dd344 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_01_mode_light.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_02_class_dashboard.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_02_class_dashboard.png new file mode 100644 index 0000000000..df3779244e Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_02_class_dashboard.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_03_class_no-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_03_class_no-shadow.png new file mode 100644 index 0000000000..e51f3469fb Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_03_class_no-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_04_class_small-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_04_class_small-shadow.png new file mode 100644 index 0000000000..ca4c4ec4e7 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_04_class_small-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_05_mode_dark.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_05_mode_dark.png new file mode 100644 index 0000000000..f88a501d0d Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_05_mode_dark.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_06_classic.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_06_classic.png new file mode 100644 index 0000000000..a8de8a5395 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_06_classic.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_07_classic_shadows.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_07_classic_shadows.png new file mode 100644 index 0000000000..ec370fff72 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-nested_07_classic_shadows.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_01_mode_light.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_01_mode_light.png new file mode 100644 index 0000000000..2b2fa91ab1 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_01_mode_light.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_02_class_dashboard.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_02_class_dashboard.png new file mode 100644 index 0000000000..e2c7657038 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_02_class_dashboard.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_03_class_no-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_03_class_no-shadow.png new file mode 100644 index 0000000000..dcba01732c Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_03_class_no-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_04_class_small-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_04_class_small-shadow.png new file mode 100644 index 0000000000..ed1e51338e Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_04_class_small-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_05_mode_dark.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_05_mode_dark.png new file mode 100644 index 0000000000..c4c7fed070 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_05_mode_dark.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_06_classic.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_06_classic.png new file mode 100644 index 0000000000..ce5ddec853 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_06_classic.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_07_classic_shadows.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_07_classic_shadows.png new file mode 100644 index 0000000000..dde4dd3d1a Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-fillable-sidebar_07_classic_shadows.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_01_mode_light.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_01_mode_light.png new file mode 100644 index 0000000000..a769b9f584 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_01_mode_light.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_02_class_dashboard.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_02_class_dashboard.png new file mode 100644 index 0000000000..187958fa7e Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_02_class_dashboard.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_03_class_no-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_03_class_no-shadow.png new file mode 100644 index 0000000000..8d63614b6e Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_03_class_no-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_04_class_small-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_04_class_small-shadow.png new file mode 100644 index 0000000000..a724aa3b16 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_04_class_small-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_05_mode_dark.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_05_mode_dark.png new file mode 100644 index 0000000000..629acfd077 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_05_mode_dark.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_06_classic.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_06_classic.png new file mode 100644 index 0000000000..7fda4edf71 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_06_classic.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_07_classic_shadows.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_07_classic_shadows.png new file mode 100644 index 0000000000..1c04aa2418 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-dash_07_classic_shadows.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_01_mode_light.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_01_mode_light.png new file mode 100644 index 0000000000..4608132bbb Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_01_mode_light.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_02_class_dashboard.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_02_class_dashboard.png new file mode 100644 index 0000000000..9639255524 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_02_class_dashboard.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_03_class_no-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_03_class_no-shadow.png new file mode 100644 index 0000000000..cca3706966 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_03_class_no-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_04_class_small-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_04_class_small-shadow.png new file mode 100644 index 0000000000..254faeaffd Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_04_class_small-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_05_mode_dark.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_05_mode_dark.png new file mode 100644 index 0000000000..f27dbfca61 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_05_mode_dark.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_06_classic.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_06_classic.png new file mode 100644 index 0000000000..03d1974169 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_06_classic.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_07_classic_shadows.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_07_classic_shadows.png new file mode 100644 index 0000000000..76c8f5df50 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-flow-sidebar_07_classic_shadows.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_01_mode_light.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_01_mode_light.png new file mode 100644 index 0000000000..67d8b400f4 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_01_mode_light.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_03_class_no-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_03_class_no-shadow.png new file mode 100644 index 0000000000..839389113e Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_03_class_no-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_04_class_small-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_04_class_small-shadow.png new file mode 100644 index 0000000000..e4686fc560 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_04_class_small-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_05_mode_dark.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_05_mode_dark.png new file mode 100644 index 0000000000..7c66441033 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_05_mode_dark.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_06_classic.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_06_classic.png new file mode 100644 index 0000000000..549fd8881d Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_06_classic.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_07_classic_shadows.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_07_classic_shadows.png new file mode 100644 index 0000000000..41425fd1df Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-navbar_07_classic_shadows.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_01_mode_light.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_01_mode_light.png new file mode 100644 index 0000000000..daa93ba18e Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_01_mode_light.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_03_class_no-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_03_class_no-shadow.png new file mode 100644 index 0000000000..b45f5d9067 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_03_class_no-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_04_class_small-shadow.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_04_class_small-shadow.png new file mode 100644 index 0000000000..fdfa8cd393 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_04_class_small-shadow.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_05_mode_dark.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_05_mode_dark.png new file mode 100644 index 0000000000..119ed46a29 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_05_mode_dark.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_06_classic.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_06_classic.png new file mode 100644 index 0000000000..5323a86dd6 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_06_classic.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_07_classic_shadows.png b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_07_classic_shadows.png new file mode 100644 index 0000000000..697e0b5f99 Binary files /dev/null and b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/_snaps/mac-release/317-bslib-preset-shiny-dashboard/317-bslib-preset-shiny-dashboard-sidebar_07_classic_shadows.png differ diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/setup-shinytest2.R b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/setup-shinytest2.R new file mode 100644 index 0000000000..e739c4dd99 --- /dev/null +++ b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/setup-shinytest2.R @@ -0,0 +1,3 @@ +# Load application support files into testing environment +shinytest2::load_app_env() + diff --git a/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/test-317-bslib-preset-shiny-dashboard.R b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/test-317-bslib-preset-shiny-dashboard.R new file mode 100644 index 0000000000..8d179df483 --- /dev/null +++ b/inst/apps/317-bslib-preset-shiny-dashboard/tests/testthat/test-317-bslib-preset-shiny-dashboard.R @@ -0,0 +1,207 @@ +library(shinytest2) +library(glue) + +# R Version to limit variants --------------------------------- +resolve_r_version <- function(name) { + rver <- jsonlite::fromJSON( + glue("https://api.r-hub.io/rversions/resolve/{name}") + ) + paste0( + strsplit(rver$version, ".", fixed = TRUE)[[1]][1:2], + collapse = "." + ) +} + +r_release <- resolve_r_version("release") + +if (platform_variant() != paste0("mac-", r_release)) { + skip("Screenshots only on MacOS with R-release") +} + +this_platform <- platform_variant() +this_platform <- sub(r_release, "release", this_platform, fixed = TRUE) + +# Setup App -------------------------------------------------- +new_app_driver <- function( + app_dir = testthat::test_path("../../"), + height = 800, + width = 1200, + ... +) { + AppDriver$new( + app_dir, + name = "317-bslib-preset-shiny-dashboard", + variant = this_platform, + height = height, + width = width, + seed = 2023 * 11 * 13, + view = interactive(), + options = list(bslib.precompiled = FALSE), + screenshot_args = list( + selector = "viewport", + delay = 1, + options = list(captureBeyondViewport = FALSE) + ), + ... + ) +} + +app <- new_app_driver() +withr::defer(app$stop()) + +# shinytest2_js <- local({ +# js_file <- system.file("internal", "js", "shiny-tracer.js", package = "shinytest2") +# js_content <- readLines(js_file) +# paste(js_content, collapse = "\n") +# }) + +app_for_variant <- function(app, ..., height = 800, width = 1200) { + params <- list(...) + params <- purrr::compact(params) + params <- purrr::imap(params, function(value, name) sprintf("%s=%s", name, value)) + params <- paste0(params, collapse = "&") + + url <- sprintf("%s?%s", app$get_url(), params) + + new_app_driver(url, height = height, width = width) +} + +app_types <- c( + "navbar", + "sidebar", + "fillable-navbar", + "fillable-sidebar", + "flow-dash", + "flow-sidebar", + "fillable-nested" +) + +app_get_toggle_state <- function(app, id) { + app$get_js(glue("document.getElementById('{id}').checked")) +} + +app_set_toggle_state <- function(app, ...) { + states <- list(...) + for (id in names(states)) { + state <- tolower(states[[id]]) + app$run_js(glue(.open = "{{", .close = "}}", " + const toggle = document.getElementById('{{id}}') + const changed = toggle.checked !== {{state}} + if (changed) { + toggle.checked = {{state}} + toggle.onchange.call(toggle) + } + ")) + + app$wait_for_js(glue("document.getElementById('{id}').checked === {state}")) + } +} + +variant_settings <- function( + app, + dashboard_toggle = FALSE, + shadow_toggle = FALSE, + shadow_sm_toggle = FALSE, + shadow_lg_toggle = FALSE +) { + # Both enables desired toggles, while ensuring others are disabled. This + # doesn't go through `app$set_inputs()` or `app$get_values()` because those + # don't currently work when the app is reloaded (missing testmode js). + app_set_toggle_state( + app, + dashboard_toggle = dashboard_toggle, + shadow_toggle = shadow_toggle, + shadow_sm_toggle = shadow_sm_toggle, + shadow_lg_toggle = shadow_lg_toggle + ) + + expect_equal(dashboard_toggle, app_get_toggle_state(app, "dashboard_toggle")) + expect_equal(shadow_toggle, app_get_toggle_state(app, "shadow_toggle")) + expect_equal(shadow_sm_toggle, app_get_toggle_state(app, "shadow_sm_toggle")) + expect_equal(shadow_lg_toggle, app_get_toggle_state(app, "shadow_lg_toggle")) +} + +for (app_type in app_types) { + expect_screenshot <- function(app, variant) { + app$expect_screenshot( + threshold = 15, + name = glue("{app_type}_{variant}") + ) + } + + describe(app_type, { + app_variant <- NULL + is_flow <- grepl("^flow", app_type) + + it("loads the app UI variant", { + app_variant <<- app_for_variant( + app, + ui = app_type, + width = if (is_flow) 1000 else 1200, + height = if (is_flow) 1200 else 800 + ) + + expect_false(is.null(app_variant)) + }) + + skip_if(is.null(app_variant), "Failed to load app variant") + withr::defer(app_variant$stop()) + + it("light mode", { + variant_settings(app_variant) # ensure toggles are all off + expect_screenshot(app_variant, "01_mode_light") + }) + + add_dashboard <- !app_type %in% c("navbar", "sidebar") + + if (add_dashboard) { + it("with bslib-page-dashboard class", { + variant_settings(app_variant, dashboard_toggle = add_dashboard) + expect_screenshot(app_variant, "02_class_dashboard") + }) + } + + it("no shadows", { + variant_settings(app_variant, shadow_toggle = TRUE, dashboard_toggle = add_dashboard) + expect_screenshot(app_variant, "03_class_no-shadow") + }) + + it("small shadows", { + variant_settings(app_variant, shadow_sm_toggle = TRUE, dashboard_toggle = add_dashboard) + expect_screenshot(app_variant, "04_class_small-shadow") + }) + + it("dark mode", { + variant_settings(app_variant, dashboard_toggle = add_dashboard) + app_variant$run_js("document.documentElement.dataset.bsTheme='dark'") + app_variant$wait_for_js("document.documentElement.dataset.bsTheme === 'dark'") + Sys.sleep(1) # wait for transition + expect_screenshot(app_variant, "05_mode_dark") + }) + + it("classic mode (default)", { + app_classic <- app_for_variant( + app, + ui = app_type, + dashboard = "false", + width = if (is_flow) 1000 else 1200, + height = if (is_flow) 1200 else 800 + ) + withr::defer(app_classic$stop()) + expect_screenshot(app_classic, "06_classic") + }) + + it("classic mode (with shadows)", { + app_classic_shade <- app_for_variant( + app, + ui = app_type, + dashboard = "false", + shadows = "true", + width = if (is_flow) 1000 else 1200, + height = if (is_flow) 1200 else 800 + ) + withr::defer(app_classic_shade$stop()) + expect_screenshot(app_classic_shade, "07_classic_shadows") + }) + }) +}