Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

503 shinytest2 for Show R code modal #1146

Merged
merged 16 commits into from
Mar 19, 2024
Merged
54 changes: 54 additions & 0 deletions tests/testthat/test-shinytest2-show-rcode.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
testthat::test_that("e2e: teal app initializes with Show R Code modal", {
app <- TealAppDriver$new(
data = simple_teal_data(),
modules = example_module(label = "Example Module")
)
app$wait_for_idle(timeout = default_idle_timeout)

# Check if button exists.
button_selector <- app$active_module_element("rcode-button")
testthat::expect_equal(
app$get_text(button_selector),
"Show R code"
)

app$click(selector = button_selector)
app$wait_for_idle(timeout = default_idle_timeout)

# Check header and title content.
testthat::expect_equal(
app$get_text("#shiny-modal div.modal-header > h4"),
"Example Code"
)

# There are two Dismiss buttons with similar id and the same label.
testthat::expect_setequal(
testthat::expect_length(
app$get_text("#shiny-modal button[data-dismiss]"),
2
),
"Dismiss"
)
# Check for Copy buttons.
testthat::expect_equal(
app$active_module_element("rcode-copy_button1") %>%
app$get_text(),
"Copy to Clipboard"
)
testthat::expect_equal(
app$active_module_element("rcode-copy_button2") %>%
app$get_text(),
"Copy to Clipboard"
)

# Check R code output.
r_code <-
app$active_module_element("rcode-verbatim_content") %>%
app$get_text()

testthat::expect_match(r_code, "# Add any code to install/load your NEST environment here", fixed = TRUE)
testthat::expect_match(r_code, "library(teal.code)", fixed = TRUE)
testthat::expect_match(r_code, "stopifnot(rlang::hash(", fixed = TRUE)

app$stop()
})
Loading