Skip to content

Commit

Permalink
Add basic tests covering the various ways of rendering a bslib::sideb…
Browse files Browse the repository at this point in the history
…ar() (with and without fill)
  • Loading branch information
cpsievert committed May 8, 2023
1 parent d1ca18f commit 5eebc63
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
104 changes: 104 additions & 0 deletions inst/apps/308-sidebar-kitchen-sink/app.R
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)
1 change: 1 addition & 0 deletions inst/apps/308-sidebar-kitchen-sink/tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shinytest2::test_app()
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()
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()
})

0 comments on commit 5eebc63

Please sign in to comment.