Skip to content

Commit

Permalink
503 shinytest2 for Show R code modal (#1146)
Browse files Browse the repository at this point in the history
Part of insightsengineering/coredev-tasks#503

---------

Signed-off-by: Marcin <[email protected]>
Co-authored-by: André Veríssimo <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 19, 2024
1 parent d13a73e commit ec8fbfc
Showing 1 changed file with 54 additions and 0 deletions.
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()
})

0 comments on commit ec8fbfc

Please sign in to comment.