-
-
Notifications
You must be signed in to change notification settings - Fork 50
Follow-up changes to TealAppDriver #1653
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
base: main
Are you sure you want to change the base?
Changes from 16 commits
133d6f7
8cc34bb
7221be2
b328fac
4627fc7
ea0d6ef
c7c960e
a32a9d9
2f6ffdf
f8ea37e
001ae6f
7a2a004
8a5d57b
8aad92f
7aaa547
a20a471
6e662e8
9f231ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -87,8 +87,8 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. | |||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| # end od check | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private$set_active_ns() | ||||||||||||||||||||||||||
| self$wait_for_idle() | ||||||||||||||||||||||||||
| private$set_active_ns() | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| #' @description | ||||||||||||||||||||||||||
| #' Append parent [`shinytest2::AppDriver`] `click` method with a call to `waif_for_idle()` method. | ||||||||||||||||||||||||||
|
|
@@ -234,7 +234,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. | |||||||||||||||||||||||||
| get_active_module_plot_output = function(plot_id) { | ||||||||||||||||||||||||||
| checkmate::check_string(plot_id) | ||||||||||||||||||||||||||
| self$get_attr( | ||||||||||||||||||||||||||
| self$namespaces()$module(sprintf("%s-plot_main > img", plot_id)), | ||||||||||||||||||||||||||
| self$namespaces(TRUE)$module(sprintf("%s-plot_main > img", plot_id)), | ||||||||||||||||||||||||||
| "src" | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
|
|
@@ -249,7 +249,6 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. | |||||||||||||||||||||||||
| #' @return The `TealAppDriver` object invisibly. | ||||||||||||||||||||||||||
| set_active_module_input = function(input_id, value, ...) { | ||||||||||||||||||||||||||
| checkmate::check_string(input_id) | ||||||||||||||||||||||||||
| checkmate::check_string(value) | ||||||||||||||||||||||||||
| self$set_input( | ||||||||||||||||||||||||||
| self$namespaces()$module(input_id), | ||||||||||||||||||||||||||
| value, | ||||||||||||||||||||||||||
|
|
@@ -554,18 +553,77 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. | |||||||||||||||||||||||||
| filter_panel = character(0) | ||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||
| # private methods ---- | ||||||||||||||||||||||||||
| set_active_ns = function() { | ||||||||||||||||||||||||||
| # Helper function to extract wrapper ID from selector and take first match if multiple found | ||||||||||||||||||||||||||
| extract_wrapper_id = function(selector) { | ||||||||||||||||||||||||||
| wrapper_id <- sub( | ||||||||||||||||||||||||||
| "^#", | ||||||||||||||||||||||||||
| "", | ||||||||||||||||||||||||||
| self$get_attr(selector = selector, attribute = "href") | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| # Take first match if multiple found | ||||||||||||||||||||||||||
| if (length(wrapper_id) > 1) { | ||||||||||||||||||||||||||
| wrapper_id <- wrapper_id[1] | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| wrapper_id | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| # Helper function to check if wrapper ID is valid | ||||||||||||||||||||||||||
| is_valid_wrapper_id = function(wrapper_id) { | ||||||||||||||||||||||||||
| length(wrapper_id) == 1 && wrapper_id != "" && !is.na(wrapper_id) | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| set_active_ns = function(sleep_time = 0.5) { | ||||||||||||||||||||||||||
| # Although wait_for_idle() is called before set_active_ns(), it only ensures Shiny is not processing. | ||||||||||||||||||||||||||
| # wait_for_page_stability() is needed here to ensure the DOM/UI is fully rendered and stable | ||||||||||||||||||||||||||
| # before trying to extract the namespace. | ||||||||||||||||||||||||||
| private$wait_for_page_stability() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| all_inputs <- self$get_values()$input | ||||||||||||||||||||||||||
| active_tab_inputs <- all_inputs[grepl("-active_module_id$", names(all_inputs))] | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use AppDriver$wait_for_value to make sure we have a value and then discard the rest of the added complexity. The spoiler... same can be done with javascript code and |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| active_wrapper_id <- sub( | ||||||||||||||||||||||||||
| "^#", | ||||||||||||||||||||||||||
| "", | ||||||||||||||||||||||||||
| self$get_attr( | ||||||||||||||||||||||||||
| selector = sprintf(".teal-modules-tree li a.module-button[data-value='%s']", active_tab_inputs), | ||||||||||||||||||||||||||
| attribute = "href" | ||||||||||||||||||||||||||
| # If no active_module_id input found, find the selected/active tab button directly | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| if (!length(active_tab_inputs) || active_tab_inputs == "") { | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| active_wrapper_id <- private$extract_wrapper_id( | ||||||||||||||||||||||||||
| ".teal-modules-tree li a.module-button.active, .teal-modules-tree li a.module-button[aria-selected='true']" | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| # If still not found, try any module button with a wrapper href | ||||||||||||||||||||||||||
| if (!private$is_valid_wrapper_id(active_wrapper_id)) { | ||||||||||||||||||||||||||
| active_wrapper_id <- private$extract_wrapper_id( | ||||||||||||||||||||||||||
| ".teal-modules-tree li a.module-button[href*='-wrapper']:not([href='#'])" | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| active_wrapper_id <- private$extract_wrapper_id( | ||||||||||||||||||||||||||
| sprintf(".teal-modules-tree li a.module-button[data-value='%s']", active_tab_inputs) | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Ensure we have a valid wrapper ID | ||||||||||||||||||||||||||
| # get_attr returns character(0) when no elements found, or NA_character_ for missing attributes | ||||||||||||||||||||||||||
| if (!private$is_valid_wrapper_id(active_wrapper_id)) { | ||||||||||||||||||||||||||
| # Try one more time after a short wait - the page might still be loading | ||||||||||||||||||||||||||
| Sys.sleep(sleep_time) | ||||||||||||||||||||||||||
| active_wrapper_id <- private$extract_wrapper_id( | ||||||||||||||||||||||||||
| ".teal-modules-tree li a.module-button[href*='-wrapper']:not([href='#'])" | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Final check - if still not found, throw error with diagnostic information | ||||||||||||||||||||||||||
| if (!private$is_valid_wrapper_id(active_wrapper_id)) { | ||||||||||||||||||||||||||
| found_ids <- paste( | ||||||||||||||||||||||||||
| self$get_attr( | ||||||||||||||||||||||||||
| selector = ".teal-modules-tree li a.module-button[href*='-wrapper']", | ||||||||||||||||||||||||||
| attribute = "href" | ||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||
| collapse = ", " | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| stop(sprintf( | ||||||||||||||||||||||||||
| paste0( | ||||||||||||||||||||||||||
| "Could not determine active module namespace. ", | ||||||||||||||||||||||||||
| "Make sure a module tab is selected and the page has finished loading. Found wrapper IDs: %s" | ||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||
| if (length(found_ids) > 0) found_ids else "none" | ||||||||||||||||||||||||||
| )) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| stop(sprintf( | |
| paste0( | |
| "Could not determine active module namespace. ", | |
| "Make sure a module tab is selected and the page has finished loading. Found wrapper IDs: %s" | |
| ), | |
| if (length(found_ids) > 0) found_ids else "none" | |
| )) | |
| stop( | |
| "Could not determine active module namespace. ", | |
| "Make sure a module tab is selected and the page has finished loading. Found wrapper IDs: " | |
| if (length(found_ids) > 0) found_ids else "none" | |
| )) |
Uh oh!
There was an error while loading. Please reload this page.