Skip to content

Commit

Permalink
Add unit tests for bslib::popover()
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Jul 26, 2023
1 parent 15cd847 commit f04077b
Show file tree
Hide file tree
Showing 4 changed files with 410 additions and 0 deletions.
142 changes: 142 additions & 0 deletions inst/apps/315-bslib-popovers/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
library(shiny)
library(bslib)
library(plotly)

ui <- page_navbar(
title = "Popover tests",
fillable = FALSE,
id = "navbar",

nav_panel(
"Popover cases",
inputPanel(
class = "px-3 py-5",
h3("Triggers"),
popover(
id = "pop-hello",
"Hello popover",
"Hello popover"
),
popover(
id = "pop-inline",
span("Inline popover"),
"Inline popover"
),
popover(
id = "pop-hyperlink",
a("Hyperlink popover", href = "https://github.com"),
"Hyperlink popover"
),
popover(
id = "pop-action-link",
actionLink("btn_link", "actionLink()"),
"actionLink() message"
),
popover(
id = "pop-action",
actionButton("btn", "A button"),
"Popover 1"
),
popover(
id = "pop-multiple",
tagList(
actionButton("btn2", "A button"),
actionButton("btn3", "A button"),
),
"A popover"
)
),
inputPanel(
class = "px-3 py-5",
h3("Options"),
popover(
span("Offset (50,50)", id = "pop-offset"),
"This tip should appear 50px down/right",
placement = "right",
options = list(offset = c(50, 50))
),
popover(
span("No animation", id = "pop-animation"),
"This tip shouldn't fade in/out",
placement = "right",
options = list(animation = FALSE)
)
)
),
nav_panel(
"Popover updates",
layout_sidebar(
card(
card_header(
popover(
span(
"Card title with popover",
bsicons::bs_icon("question-circle-fill")
),
"Popover message",
id = "popover",
placement = "right"
)
),
plotlyOutput("bars")
),
sidebar = list(
textInput("popover_msg", "Enter a popover message", "Popover message"),
actionButton("show_popover", "Show popover", class = "mb-3"),
actionButton("hide_popover", "Hide popover"),
br(),
input_switch("show_title", "Add a popover title"),
conditionalPanel(
"input.show_title",
textInput("popover_title", "Enter a title", "Popover title"),
)
)
)
),

nav_panel(
"Popover inputs",
uiOutput("num_out"),
popover(
id = "btn_pop",
actionButton("btn4", "Show popover"),
"Change the number",
numericInput("num", NULL, 1),
selectInput("sel", "Select", state.name),
title = "Input controls"
),
actionLink("inc", "Increment number")
)

)

server <- function(input, output, session) {
observe({
update_popover(
"popover", input$popover_msg,
title = if (input$show_title) input$popover_title
)
})

observeEvent(input$show_popover, {
toggle_popover("popover", show = TRUE)
})

observeEvent(input$hide_popover, {
toggle_popover("popover", show = FALSE)
})

output$bars <- renderPlotly({
plot_ly(diamonds, x = ~cut)
})

output$num_out <- renderPrint({
input$num
})

observeEvent(input$inc, {
updateNumericInput(inputId = "num", value = input$num + 1)
})
}

shinyApp(ui, server)
1 change: 1 addition & 0 deletions inst/apps/315-bslib-popovers/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,3 @@
# Load application support files into testing environment
shinytest2::load_app_env()

Loading

0 comments on commit f04077b

Please sign in to comment.