From 55bdd0079617b1a90c8f5b002e6514bc9b6d9391 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:26:32 +0100 Subject: [PATCH 1/4] 503 `$get_html_rvest` method for `TealAppDriver` (#1158) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So instead of `app$get_html(selector) %>% rvest::read_html()` we can shortly write `app$read_html(selector)`. --------- Signed-off-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> Co-authored-by: vedhav Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> --- R/TealAppDriver.R | 8 ++++++++ man/TealAppDriver.Rd | 23 ++++++++++++++++++++++- tests/testthat/test-shinytest2-init.R | 3 +-- tests/testthat/test-shinytest2-modules.R | 3 +-- tests/testthat/test-shinytest2-reporter.R | 6 ++---- tests/testthat/test-shinytest2-utils.R | 3 +-- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/R/TealAppDriver.R b/R/TealAppDriver.R index fa30051e4c..2f46b66889 100644 --- a/R/TealAppDriver.R +++ b/R/TealAppDriver.R @@ -354,6 +354,14 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. invisible(self) }, #' @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. diff --git a/man/TealAppDriver.Rd b/man/TealAppDriver.Rd index 46a38b097f..17c1c63059 100644 --- a/man/TealAppDriver.Rd +++ b/man/TealAppDriver.Rd @@ -38,6 +38,7 @@ driving a teal application for performing interactions for \code{shinytest2} tes \item \href{#method-TealAppDriver-add_filter_var}{\code{TealAppDriver$add_filter_var()}} \item \href{#method-TealAppDriver-remove_filter_var}{\code{TealAppDriver$remove_filter_var()}} \item \href{#method-TealAppDriver-set_active_filter_selection}{\code{TealAppDriver$set_active_filter_selection()}} +\item \href{#method-TealAppDriver-get_html_rvest}{\code{TealAppDriver$get_html_rvest()}} \item \href{#method-TealAppDriver-open_url}{\code{TealAppDriver$open_url()}} \item \href{#method-TealAppDriver-clone}{\code{TealAppDriver$clone()}} } @@ -449,10 +450,30 @@ The \code{TealAppDriver} object invisibly. } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-TealAppDriver-get_html_rvest}{}}} +\subsection{Method \code{get_html_rvest()}}{ +Wrapper around \code{get_html} that passes the output directly to \code{rvest::read_html}. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{TealAppDriver$get_html_rvest(selector)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{selector}}{\code{(character(1))} passed to \code{get_html}.} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +An XML document. +Wrapper around \code{get_url()} method that opens the app in the browser. +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-TealAppDriver-open_url}{}}} \subsection{Method \code{open_url()}}{ -Wrapper around \code{get_url()} method that opens the app in the browser. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{TealAppDriver$open_url()}\if{html}{\out{
}} } diff --git a/tests/testthat/test-shinytest2-init.R b/tests/testthat/test-shinytest2-init.R index 8141e1df0b..c2881249a8 100644 --- a/tests/testthat/test-shinytest2-init.R +++ b/tests/testthat/test-shinytest2-init.R @@ -30,8 +30,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 diff --git a/tests/testthat/test-shinytest2-modules.R b/tests/testthat/test-shinytest2-modules.R index 5c5233b226..d377b5564d 100644 --- a/tests/testthat/test-shinytest2-modules.R +++ b/tests/testthat/test-shinytest2-modules.R @@ -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;" diff --git a/tests/testthat/test-shinytest2-reporter.R b/tests/testthat/test-shinytest2-reporter.R index af5305ba4c..ddb3617713 100644 --- a/tests/testthat/test-shinytest2-reporter.R +++ b/tests/testthat/test-shinytest2-reporter.R @@ -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"), @@ -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"), diff --git a/tests/testthat/test-shinytest2-utils.R b/tests/testthat/test-shinytest2-utils.R index f783360de6..99ef2a0bf9 100644 --- a/tests/testthat/test-shinytest2-utils.R +++ b/tests/testthat/test-shinytest2-utils.R @@ -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"), From c41c724ca7a25fdf9c2f7659e03d8c0c02b5491a Mon Sep 17 00:00:00 2001 From: m7pr Date: Mon, 18 Mar 2024 17:27:36 +0000 Subject: [PATCH 2/4] [skip actions] Bump version to 0.15.2.9006 --- DESCRIPTION | 2 +- NEWS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2740d3f1e5..0cd77b5394 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: teal Title: Exploratory Web Apps for Analyzing Clinical Trials Data -Version: 0.15.2.9005 +Version: 0.15.2.9006 Date: 2024-03-18 Authors@R: c( person("Dawid", "Kaledkowski", , "dawid.kaledkowski@roche.com", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 61e2caacbd..52fe676bea 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# teal 0.15.2.9005 +# teal 0.15.2.9006 # teal 0.15.2 From 1890e0594494a2a25c26ceea1cb706d195b730f2 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:50:10 +0100 Subject: [PATCH 3/4] 503 shinytest2 for session info link in bottom of the page (#1145) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of https://github.com/insightsengineering/coredev-tasks/issues/503 --------- Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> --- tests/testthat/test-shinytest2-init.R | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/testthat/test-shinytest2-init.R b/tests/testthat/test-shinytest2-init.R index c2881249a8..39707c9847 100644 --- a/tests/testthat/test-shinytest2-init.R +++ b/tests/testthat/test-shinytest2-init.R @@ -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" From d13a73ea2f1c6fd4abca6106a79b4b0b096139cd Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 19 Mar 2024 09:51:09 +0000 Subject: [PATCH 4/4] [skip actions] Bump version to 0.15.2.9007 --- DESCRIPTION | 4 ++-- NEWS.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0cd77b5394..9b87ce8d94 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: teal Title: Exploratory Web Apps for Analyzing Clinical Trials Data -Version: 0.15.2.9006 -Date: 2024-03-18 +Version: 0.15.2.9007 +Date: 2024-03-19 Authors@R: c( person("Dawid", "Kaledkowski", , "dawid.kaledkowski@roche.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9533-457X")), diff --git a/NEWS.md b/NEWS.md index 52fe676bea..8617f01c4e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# teal 0.15.2.9006 +# teal 0.15.2.9007 # teal 0.15.2