-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic tests covering the various ways of rendering a bslib::sideb…
…ar() (with and without fill)
- Loading branch information
Showing
4 changed files
with
143 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
library(shiny) | ||
library(bslib) | ||
library(crosstalk) | ||
library(plotly) | ||
|
||
plotly_bars <- plot_ly(x = LETTERS[1:3], y = 1:3) %>% | ||
add_bars() | ||
|
||
sidebar_long <- sidebar(lorem::ipsum(3, 3)) | ||
sidebar_short <- sidebar(p("A simple sidebar")) | ||
|
||
ui <- page_navbar( | ||
title = "Sidebar kitchen sink", | ||
fillable = c("Fill", "Fill+Scroll", "Global card sidebar"), | ||
id = "navbar", | ||
sidebar = sidebar( | ||
open = FALSE, | ||
position = "right", | ||
id = "global_sidebar", | ||
bg = "#1E1E1E", | ||
shiny::markdown( | ||
"Learn more about `bslib::sidebar()` [here](https://rstudio.github.io/bslib/articles/sidebars.html)" | ||
) | ||
), | ||
header = tagList( | ||
tags$style(HTML(".plotly .modebar-container { display: none; }")), | ||
span("header", class = "bg-dark"), | ||
span("content", class = "bg-dark") | ||
), | ||
footer = tagList( | ||
span("footer", class = "bg-dark"), | ||
span("content", class = "bg-dark") | ||
), | ||
nav( | ||
"Fill", | ||
plotly_bars, | ||
br(), | ||
layout_sidebar(sidebar_short, plotly_bars, fillable = TRUE), | ||
br(), | ||
card( | ||
card_header("Depth"), | ||
layout_sidebar(sidebar_short, plotly_bars, fillable = TRUE) | ||
) | ||
), | ||
nav( | ||
"Fill+Scroll", | ||
plotly_bars, | ||
br(), | ||
layout_sidebar(sidebar_long, plotly_bars), | ||
br(), | ||
card( | ||
card_header("Depth"), | ||
layout_sidebar(sidebar_long, plotly_bars) | ||
) | ||
), | ||
nav( | ||
"Scroll", | ||
plotly_bars, | ||
br(), | ||
layout_sidebar(sidebar_long, plotly_bars), | ||
br(), | ||
card( | ||
card_header("Depth"), | ||
layout_sidebar(sidebar_long, plotly_bars) | ||
) | ||
), | ||
nav( | ||
"Global card sidebar", | ||
# Wrapping this up with layout_column_wrap() should keep | ||
# the row height the same (even when switch tabs) | ||
layout_column_wrap( | ||
width = 1, | ||
navs_pill_card( | ||
title = "Global sidebar", | ||
id = "card_tab_sidebar", | ||
sidebar = sidebar_long, | ||
full_screen = TRUE, | ||
nav("Tab 1", plotly_bars, plotly_bars), | ||
nav("Tab 2", plotly_bars) | ||
), | ||
navs_pill_card( | ||
title = "Global sidebar", | ||
id = "card_pill_sidebar", | ||
sidebar = sidebar_long, | ||
full_screen = TRUE, | ||
nav("Pill 1", plotly_bars, plotly_bars), | ||
nav("Pill 2", plotly_bars) | ||
) | ||
) | ||
), | ||
nav_spacer(), | ||
nav_item(actionButton("toggle_sidebar", "Learn more")) | ||
) | ||
|
||
|
||
server <- function(input, output) { | ||
|
||
observeEvent(input$toggle_sidebar, { | ||
sidebar_toggle("global_sidebar") | ||
}) | ||
|
||
} | ||
|
||
shinyApp(ui, server) |
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 @@ | ||
shinytest2::test_app() |
2 changes: 2 additions & 0 deletions
2
inst/apps/308-sidebar-kitchen-sink/tests/testthat/setup-shinytest2.R
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,2 @@ | ||
# Load application support files into testing environment | ||
shinytest2::load_app_env() |
36 changes: 36 additions & 0 deletions
36
inst/apps/308-sidebar-kitchen-sink/tests/testthat/test-shinytest2.R
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,36 @@ | ||
library(shinytest2) | ||
|
||
test_that("{shinytest2} recording: 308-sidebar-kitchen-sink", { | ||
height <- 1200 | ||
width <- 1600 | ||
|
||
app <- AppDriver$new( | ||
variant = platform_variant(), | ||
name = "308-sidebar-kitchen-sink", | ||
view = interactive(), | ||
height = height, | ||
width = width | ||
) | ||
|
||
app$expect_screenshot() | ||
|
||
app$set_inputs(navbar = "Fill+Scroll") | ||
app$expect_screenshot() | ||
|
||
# Contents should render to their natural height on mobile | ||
app$set_window_size(width = 500, height = 1000) | ||
app$expect_screenshot() | ||
app$set_window_size(width = width, height = height) | ||
|
||
app$set_inputs(navbar = "Scroll") | ||
app$expect_screenshot() | ||
|
||
app$set_inputs(navbar = "Global card sidebar") | ||
app$set_inputs(card_tab_sidebar = "Tab 2") | ||
Sys.sleep(1) # Wait for the tab to receive focus | ||
app$expect_screenshot() | ||
|
||
app$click("toggle_sidebar") | ||
Sys.sleep(1) # Wait for transition to complete | ||
app$expect_screenshot() | ||
}) |