Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
Merge branch 'main' into landing_popup@503-introduce-shinytest2@main

# Conflicts:
#	R/TealAppDriver.R
#	man/TealAppDriver.Rd
  • Loading branch information
m7pr committed Mar 19, 2024
2 parents 13d2f75 + d13a73e commit f1501f0
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 28 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: teal
Title: Exploratory Web Apps for Analyzing Clinical Trials Data
Version: 0.15.2.9005
Date: 2024-03-18
Version: 0.15.2.9007
Date: 2024-03-19
Authors@R: c(
person("Dawid", "Kaledkowski", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9533-457X")),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# teal 0.15.2.9005
# teal 0.15.2.9007

# teal 0.15.2

Expand Down
8 changes: 8 additions & 0 deletions R/TealAppDriver.R
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,14 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
rvest::html_attr("onclick")
},
#' @description
#' Wrapper around `get_html` that passes the output directly to `rvest::read_html`.
#'
#' @param selector `(character(1))` passed to `get_html`.
#'
#' @return An XML document.
get_html_rvest = function(selector) {
rvest::read_html(self$get_html(selector))
},
#' Wrapper around `get_url()` method that opens the app in the browser.
#'
#' @return Nothing. Opens the underlying teal app in the browser.
Expand Down
37 changes: 22 additions & 15 deletions man/TealAppDriver.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 57 additions & 2 deletions tests/testthat/test-shinytest2-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,62 @@ testthat::test_that("e2e: teal app initializes with no errors", {
app$stop()
})

testthat::test_that("e2e: teal app initializes with sessionInfo 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 <- "#teal-sessionInfo-button"
testthat::expect_equal(
app$get_text(button_selector),
"Session Info"
)

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 > div > div.modal-header > h4"),
"SessionInfo"
)

# There are two Copy buttons with similar id and the same label.
testthat::expect_setequal(
testthat::expect_length(
app$get_text(
"#shiny-modal [id^='teal-sessionInfo-copy_button']"
),
2
),
"Copy to Clipboard"
)
# 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 session info output.
session_info <- app$get_text("#teal-sessionInfo-verbatim_content")

testthat::expect_match(session_info, "R version", fixed = TRUE)
testthat::expect_match(session_info, "attached base packages:", fixed = TRUE)
testthat::expect_match(session_info, "loaded via a namespace (and not attached):", fixed = TRUE)

testthat::expect_match(session_info, "shiny", fixed = TRUE)
testthat::expect_match(session_info, "teal.slice", fixed = TRUE)
testthat::expect_match(session_info, "teal.reporter", fixed = TRUE)

app$stop()
})

testthat::test_that("e2e: init creates UI containing specified title, favicon, header and footer", {
app_title <- "Custom Teal App Title"
app_favicon <- "https://raw.githubusercontent.com/insightsengineering/hex-stickers/main/PNG/teal.png"
Expand All @@ -30,8 +86,7 @@ testthat::test_that("e2e: init creates UI containing specified title, favicon, h
app_title
)
testthat::expect_equal(
app$get_html("head > link[rel='icon']") %>%
rvest::read_html() %>%
app$get_html_rvest("head > link[rel='icon']") %>%
rvest::html_elements("link") %>%
rvest::html_attr("href"),
app_favicon
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-shinytest2-modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ testthat::test_that("e2e: filter panel is not displayed when datanames is NULL",
app$wait_for_idle(timeout = default_idle_timeout)

testthat::expect_identical(
app$get_html(".teal_secondary_col") %>%
rvest::read_html() %>%
app$get_html_rvest(".teal_secondary_col") %>%
rvest::html_element("div") %>%
rvest::html_attr("style"),
"display: none;"
Expand Down
6 changes: 2 additions & 4 deletions tests/testthat/test-shinytest2-reporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ testthat::test_that("e2e: reporter tab is created when a module has reporter", {
modules = report_module(label = "Module with Reporter")
)

teal_tabs <- app$get_html(selector = "#teal-main_ui-root-active_tab") %>%
rvest::read_html() %>%
teal_tabs <- app$get_html_rvest(selector = "#teal-main_ui-root-active_tab") %>%
rvest::html_elements("a")
tab_names <- setNames(
rvest::html_attr(teal_tabs, "data-value"),
Expand All @@ -24,8 +23,7 @@ testthat::test_that("e2e: reporter tab is not created when a module has no repor
data = simple_teal_data(),
modules = example_module(label = "Example Module")
)
teal_tabs <- app$get_html(selector = "#teal-main_ui-root-active_tab") %>%
rvest::read_html() %>%
teal_tabs <- app$get_html_rvest(selector = "#teal-main_ui-root-active_tab") %>%
rvest::html_elements("a")
tab_names <- setNames(
rvest::html_attr(teal_tabs, "data-value"),
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-shinytest2-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ testthat::test_that("e2e: show/hide hamburger works as expected", {
)

get_class_attributes <- function(app, selector) {
element <- app$get_html(selector = selector) %>%
rvest::read_html() %>%
element <- app$get_html_rvest(selector = selector) %>%
rvest::html_elements(selector)
list(
class = rvest::html_attr(element, "class"),
Expand Down

0 comments on commit f1501f0

Please sign in to comment.