-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Conversation
Hey @averissimo @gogonzo @vedhav Took a stab at |
I think the whole |
CLA Assistant Lite bot ✅ All contributors have signed the CLA |
Thanks @averissimo for letting me know that |
Unit Tests Summary 1 files 28 suites 11s ⏱️ Results for commit dbd96a6. ♻️ This comment has been updated with latest results. |
Unit Test Performance Difference
Additional test case details
Results for commit 1c29a4c ♻️ This comment has been updated with latest results. |
Hey @averissimo maybe you have an idea why the buttons on
test do not redirect after clicking. Trying to test the |
I tried a bunch of JS ideas and can't get the event to be triggered in
The best I can get is the function definition from the element itself app$get_js("document.getElementById(\"read\").onclick.toString()")
#> [1] "function onclick(event) {\nwindow.open('http://google.com', '_blank')\n}" |
Code Coverage Summary
Diff against main
Results for commit: dbd96a6 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
So @averissimo you say we can't click the button to achieve the |
I don't think the problem is with the On click works for the first one, but not the second. library(shiny)
app <- shinyApp(
fluidPage(
div(
id = "clicky",
"click me",
onclick = "Shiny.setInputValue('test', { 'key1' : 'val1', 'key2' : 'val2' }, {priority: 'event'})"
),
div(
id = "clicky2",
"click me",
onclick = "window.open('http://google.com', '_blank')"
),
verbatimTextOutput("test")
),
function(input, output, session) {
output$test <- renderPrint({
str(input$test)
})
}
)
driver <- shinytest2::AppDriver$new(app)
driver$view()
driver$click(selector = "#clicky")
driver$click(selector = "#clicky2") |
Thanks. But what matters the most that you can get the JS code from under the button info app$get_js("document.getElementById(\"read\").onclick.toString()") And this way we can actually see what was put during the app creation, and this is what I wanted to test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small changes:
- I think we can avoid the
:nth-child(1)
as only 1 element will havedata-dismiss
attribute. - Please unify how buttons are specified on all PRs with
button
or.btn
or.btn-default
- I would prefer one of the first 2, but I think any of them would be fine
It would be nice to detect onclick behavior via without resorting to string matching.
I've come up with this: (after failing to use a r shiny::textInput
with js Shiny::setInputValue
call to change it)
onclick_text <- "document.getElementById('unique_input_id').value = 'Lorem ipsum';"
app <- TealAppDriver$new(
data = simple_teal_data(),
modules = modules(
landing_popup_module(
buttons = actionButton("read", "Read more", onclick = onclick_text),
content = tags$input(id = "unique_input_id")
),
example_module()
)
)
app$wait_for_idle(timeout = default_idle_timeout)
onclick_text_app <- app$click(selector = "#read")
# Looks for side-effects of button click (i.e. input value change).
testthat::expect_equal(
app$get_js("document.getElementById('unique_input_id').value"),
"Lorem ipsum"
)
Per your last commit @averissimo , I think we now have a very concise way of doing this test with |
Ah, I see you are referring to |
Yes, I'm not sure about it though as this is a Shiny functionality, not a landing module one. Maybe we should only test that the landing popup appears. Everything else is Shiny-related. It's a slippery slope if we start to test Shiny and htmltools themselves. |
got it @averissimo and totally agree. I would stop the develpoment and keep the state as it's currently is. |
Signed-off-by: Marcin <[email protected]>
@averissimo would you be able to have one last final look in here when you have time? no pressure |
landing_popup_module
landing_popup_module
ugh, there is test failing for reporter part. but this PR does not involve testing reporter |
it was failing on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, I have one more comment, let's discuss it 😄
It boils down to the specificity of get_onclick
.
It would be nice to:
- have access to other attributes in the future tests
- getting
onclick
from<a>
elements or another element- (
<div>
on screenshot below also hasonclick
attr)
- (
As extra bonus, it also becomes a vectorial function.
app$get_attr("button", "onclick")
#> [1] "toggleFilterPanel();" NA
#> [3] NA NA
#> [5] NA NA
#> [7] "window.open('http://google.com', '_blank')" "window.close()"
Other occurrences of getting attributes in the code could use this new method. I can create a follow-up PR to this one and change those if you accept the changes |
Please add |
@averissimo sure! go for it, thanks! |
Co-authored-by: André Veríssimo <[email protected]> Signed-off-by: Marcin <[email protected]>
Co-authored-by: André Veríssimo <[email protected]> Signed-off-by: Marcin <[email protected]>
Co-authored-by: André Veríssimo <[email protected]> Signed-off-by: Marcin <[email protected]>
Co-authored-by: André Veríssimo <[email protected]> Signed-off-by: Marcin <[email protected]>
@averissimo thanks for the proposition of |
cleaned up some documentation and just pushed it for final review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Nice work 💯
Part of https://github.com/insightsengineering/coredev-tasks/issues/503
Just a warm-up. Trying to understand
shinytest2
tests in action. Tooklanding_popup_module
to the battlefield.