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 landing_popup_module #1138

Merged
merged 41 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2b4ae04
playing with tests for landing_popup_module
m7pr Mar 8, 2024
30bae39
verify completeness of text of landing_popup_module
m7pr Mar 8, 2024
c507d4f
tests for landingpopup
m7pr Mar 8, 2024
fa0f3e1
2 more simple tests for landing_popup_module
m7pr Mar 8, 2024
79b5e66
rename test
m7pr Mar 8, 2024
723af24
move helper functions to a new section
m7pr Mar 8, 2024
ca6e9ad
remove comment
m7pr Mar 8, 2024
680a129
Update tests/testthat/test-shinytest2-landing_popup.R
m7pr Mar 8, 2024
c4ff20a
[skip style] [skip vbump] Restyle files
github-actions[bot] Mar 8, 2024
ae83190
Update tests/testthat/test-shinytest2-landing_popup.R
m7pr Mar 11, 2024
7e92eed
Update tests/testthat/test-shinytest2-landing_popup.R
m7pr Mar 11, 2024
342c16e
Update tests/testthat/test-shinytest2-landing_popup.R
m7pr Mar 11, 2024
5e547e6
replace extract_text with app$get_text
m7pr Mar 11, 2024
07d5655
simplify the test for a closed modal
m7pr Mar 11, 2024
2e4e6cd
prefix tests
m7pr Mar 11, 2024
58d8efe
fixing lintr and typos
m7pr Mar 11, 2024
d642019
Update tests/testthat/test-shinytest2-landing_popup.R
m7pr Mar 12, 2024
42de969
slow down the test with app$wait_for_idle(timeout = default_idle_time…
m7pr Mar 12, 2024
289a97b
fix a test for onclick
m7pr Mar 13, 2024
bfb6d1a
[skip style] [skip vbump] Restyle files
github-actions[bot] Mar 13, 2024
c5f018e
Update tests/testthat/test-shinytest2-landing_popup.R
m7pr Mar 14, 2024
2fa3953
use extract_onlick in the onclick test
m7pr Mar 14, 2024
2f05416
move extract_onclick to TealAppDriver methods
m7pr Mar 14, 2024
97456b7
move phash directly to a test
m7pr Mar 14, 2024
9c3c7a4
remove open_filter_manager
m7pr Mar 19, 2024
13d2f75
Update R/TealAppDriver.R
m7pr Mar 19, 2024
f1501f0
merge
m7pr Mar 19, 2024
b649b79
[skip style] [skip vbump] Restyle files
github-actions[bot] Mar 19, 2024
61238d1
bring named list to buttons test
m7pr Mar 19, 2024
e8fa293
substitute extract_onlick with app$get_onlick
m7pr Mar 19, 2024
4bfa968
Merge branch 'main' into landing_popup@503-introduce-shinytest2@main
m7pr Mar 20, 2024
78a9889
Merge branch 'main' into landing_popup@503-introduce-shinytest2@main
m7pr Mar 20, 2024
c6924b6
Merge branch 'main' into landing_popup@503-introduce-shinytest2@main
averissimo Mar 21, 2024
0678c3f
Update tests/testthat/test-shinytest2-landing_popup.R
m7pr Mar 21, 2024
3d2a928
Update tests/testthat/test-shinytest2-landing_popup.R
m7pr Mar 21, 2024
aa22e2e
Update tests/testthat/test-shinytest2-landing_popup.R
m7pr Mar 21, 2024
0a19ae1
Update R/TealAppDriver.R
m7pr Mar 21, 2024
19e1787
add skip_if_too_deep(5)
m7pr Mar 21, 2024
2a67909
change read_html %>% get_hrml into get_html_rvest
m7pr Mar 21, 2024
c7ecce7
update documentation
m7pr Mar 21, 2024
dbd96a6
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions R/TealAppDriver.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
invisible(self)
},
#' @description
#' Extract `html` attribute (found by a `selector`).
#'
#' @param selector (`character(1)`) specifying the selector to be used to get the content of a specific node.
#' @param attribute (`character(1)`) name of an attribute to retrieve from a node specified by `selector`.
#'
#' @return The `character` vector.
get_attr = function(selector, attribute) {
self$get_html_rvest("html") %>%
rvest::html_nodes(selector) %>%
rvest::html_attr(attribute)
},
#' @description
#' Wrapper around `get_html` that passes the output directly to `rvest::read_html`.
#'
#' @param selector `(character(1))` passed to `get_html`.
Expand Down
23 changes: 23 additions & 0 deletions man/TealAppDriver.Rd

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

3 changes: 1 addition & 2 deletions man/teal_slices.Rd

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

168 changes: 168 additions & 0 deletions tests/testthat/test-shinytest2-landing_popup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
testthat::test_that("e2e: teal app with landing_popup_module initializes with no errors", {
skip_if_too_deep(5)
app <- TealAppDriver$new(
data = simple_teal_data(),
modules = modules(
landing_popup_module(
title = "Welcome",
content = tags$b("A welcome message!", style = "color: red;")
),
example_module()
)
)

app$wait_for_idle(timeout = default_idle_timeout)
testthat::expect_equal(
app$get_text("#landingpopup b"),
"A welcome message!"
)
app$stop()
})

testthat::test_that("e2e: app with default landing_popup_module creates modal containing a button", {
skip_if_too_deep(5)
app <- TealAppDriver$new(
data = simple_teal_data(),
modules = modules(
landing_popup_module(),
example_module()
)
)
app$wait_for_idle(timeout = default_idle_timeout)

testthat::expect_equal(
app$get_text("#shiny-modal-wrapper button"),
"Accept"
)

app$stop()
})

testthat::test_that("e2e: when default landing_popup_module is closed, it shows the underlying teal app", {
skip_if_too_deep(5)
app <- TealAppDriver$new(
data = simple_teal_data(),
modules = modules(
landing_popup_module(),
example_module()
)
)
app$wait_for_idle(timeout = default_idle_timeout)

# Button is clicked.
app$click(selector = "#shiny-modal-wrapper button[data-dismiss='modal']")
app$wait_for_idle(timeout = default_idle_timeout)

# There is no more modal displayed.
testthat::expect_null(app$get_html("#shiny-modal-wrapper"))

app$stop()
})


# customized landing_popup_module ---------------------------------------------------------------------------------

testthat::test_that(
"e2e: app with customized landing_popup_module creates modal containing specified title, content and buttons",
{
skip_if_too_deep(5)
phash <- function(text) paste0("#", text)

modal_title <- "Custom Landing Popup Module Title"
modal_content_message <- "A welcome message!"
modal_content <- tags$b(modal_content_message, style = "color: red;")

modal_btns <- list(
go = list(text = "Proceed"),
more = list(text = "Read more", onclick = "window.open('http://google.com', '_blank')", id = "read"),
reject = list(text = "Reject", onclick = "window.close()", id = "close")
)
modal_buttons <-
tagList(
shiny::modalButton(modal_btns$go$text),
shiny::actionButton(
modal_btns$more$id,
label = modal_btns$more$text,
onclick = modal_btns$more$onclick
),
shiny::actionButton(
modal_btns$reject$id,
label = modal_btns$reject$text,
onclick = modal_btns$reject$onclick
)
)

app <- TealAppDriver$new(
data = simple_teal_data(),
modules = modules(
landing_popup_module(
title = modal_title,
content = modal_content,
buttons = modal_buttons
),
example_module()
)
)

app$wait_for_idle(timeout = default_idle_timeout)

testthat::expect_equal(
app$get_text(".modal-title"),
modal_title
)

testthat::expect_equal(
trimws(app$get_text(".modal-body")),
modal_content_message
)

testthat::expect_equal(
app$get_text(".btn-default:nth-child(1)"),
m7pr marked this conversation as resolved.
Show resolved Hide resolved
modal_btns$go$text
)

testthat::expect_equal(
app$get_text(phash(modal_btns$more$id)),
modal_btns$more$text
)

testthat::expect_equal(
app$get_attr(phash(modal_btns$more$id), "onclick"),
modal_btns$more$onclick
)

testthat::expect_equal(
app$get_text(phash(modal_btns$reject$id)),
modal_btns$reject$text
)

testthat::expect_equal(
app$get_attr(phash(modal_btns$reject$id), "onclick"),
modal_btns$reject$onclick
)

app$stop()
}
)

testthat::test_that("e2e: when customized button in landing_popup_module is clicked, it redirects to a certain page", {
skip_if_too_deep(5)
onclick_text <- "window.open('http://google.com', '_blank')"
app <- TealAppDriver$new(
data = simple_teal_data(),
modules = modules(
landing_popup_module(
buttons = actionButton("read", "Read more", onclick = onclick_text)
),
example_module()
)
)
app$wait_for_idle(timeout = default_idle_timeout)

testthat::expect_equal(
app$get_attr("#read", "onclick"),
onclick_text
)

app$stop()
})
Loading