From d2d4e1a827c79aaf7c0702f75676fcaa32d350ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Wed, 10 Apr 2024 15:18:20 +0200 Subject: [PATCH 01/25] feat: support for e2e tests in PCA module --- R/tm_a_pca.R | 2 +- tests/testthat/test-shinytest2-tm_a_pca.R | 155 ++++++++++++++++++++++ 2 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/test-shinytest2-tm_a_pca.R diff --git a/R/tm_a_pca.R b/R/tm_a_pca.R index 42261b2f0..20e2c1cb9 100644 --- a/R/tm_a_pca.R +++ b/R/tm_a_pca.R @@ -264,7 +264,7 @@ ui_a_pca <- function(id, ...) { collapsed = TRUE, conditionalPanel( condition = sprintf( - "input['%s'] == 'Elbow Plot' || input['%s'] == 'Eigenvector plot'", + "input['%s'] == 'Elbow plot' || input['%s'] == 'Eigenvector plot'", ns("plot_type"), ns("plot_type") ), diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R new file mode 100644 index 000000000..71a4b34ef --- /dev/null +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -0,0 +1,155 @@ +testthat::test_that("e2e - tm_a_pca: data extract changes output", { + skip_if_too_deep(5) + + require(shinytest2) + + data <- within(teal_data(), { + require(nestcolor) + require(ggplot2) + + USArrests <- USArrests + }) + datanames(data) <- "USArrests" + + + app <- TealAppDriver$new( + data = data, + modules = tm_a_pca( + dat = data_extract_spec( + dataname = "USArrests", + select = select_spec( + choices = variable_choices( + data = data[["USArrests"]], + c("Murder", "Assault", "UrbanPop", "Rape") + ), + selected = c("Murder", "Assault"), + multiple = TRUE + ) + ) + ) + ) + + # Data selection (adds rows to tables) + app$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "Assault")) + app$expect_no_validation_error() + + testthat::expect_match(app$get_active_module_output("tbl_eigenvector"), "Assault") + + testthat::expect_failure( + testthat::expect_match(app$get_active_module_output("tbl_eigenvector"), "UrbanPop") + ) + + app$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "UrbanPop")) + app$expect_no_validation_error() + + testthat::expect_match(app$get_active_module_output("tbl_eigenvector"), "UrbanPop") + + app$stop() +}) + +testthat::test_that("e2e - tm_a_pca: encodings update main panel", { + skip_if_too_deep(5) + + require(shinytest2) + + data <- within(teal_data(), { + require(nestcolor) + + USArrests <- USArrests + }) + datanames(data) <- "USArrests" + + app <- TealAppDriver$new( + data = data, + modules = tm_a_pca( + dat = data_extract_spec( + dataname = "USArrests", + select = select_spec( + choices = variable_choices( + data = data[["USArrests"]], + c("Murder", "Assault", "UrbanPop", "Rape") + ), + selected = c("Murder", "Assault"), + multiple = TRUE + ) + ) + ) + ) + + app$view() + browser() + # Display section (hides tables) + + app$set_module_input("tables_display", c()) + app$expect_no_validation_error() + + testthat::expect_type(app$get_active_module_output("tbl_importance"), "list") + testthat::expect_setequal(names(app$get_active_module_output("tbl_importance")), c("message", "call", "type")) + + testthat::expect_type(app$get_active_module_output("tbl_eigenvector"), "list") + testthat::expect_setequal(names(app$get_active_module_output("tbl_eigenvector")), c("message", "call", "type")) + + # Plot type (select each) + + # Changing input will trigger an output change + app$set_module_input("plot_type", "Circle plot") + app$expect_no_validation_error() + + app$set_module_input("plot_type", "Biplot") + app$expect_no_validation_error() + + app$set_module_input("plot_type", "Eigenvector plot") + app$expect_no_validation_error() + + app$set_module_input("plot_type", "Elbow plot") # Initial value + app$expect_no_validation_error() + + # Pre-processing + + app$set_module_input("standardization", "center") + app$set_module_input("standardization", "center_scale") + app$set_module_input("standardization", "none") # Initial value + + # NA Action + + app$set_module_input("na_action", "drop") + app$set_module_input("na_action", "none") + + # Selected plot specific settings is not visible for Elbow plot + no_plot_settings_selector <- sprintf("#%s-%s %s", app$active_module_ns(), "plot_settings", "span.help-block") + x_axis_selector <- sprintf("#%s-%s", app$active_module_ns(), "x_axis") + color_by_selector <- sprintf("#%s-%s", app$active_module_ns(), "response-dataset_USArrests_singleextract-select_input") + + app$set_module_input("plot_type", "Elbow plot", wait = FALSE) + testthat::expect_true(app$is_visible(no_plot_settings_selector)) + testthat::expect_false(app$is_visible(x_axis_selector)) + testthat::expect_false(app$is_visible(color_by_selector)) + + app$set_module_input("plot_type", "Circle plot", wait = FALSE) + testthat::expect_true(app$is_visible(x_axis_selector)) + + app$set_module_input("plot_type", "Biplot", wait = FALSE) + testthat::expect_true(app$is_visible(color_by_selector)) + + # Theme + + app$set_module_input("ggtheme-selectized", "bw") + app$expect_no_validation_error() + app$set_module_input("ggtheme-selectized", "light") + app$expect_no_validation_error() + app$set_module_input("ggtheme-selectized", "dark") + app$expect_no_validation_error() + + # Font size + + app$set_module_input("font_size", "8") + app$expect_no_validation_error() + + app$set_module_input("font_size", "20") + app$expect_no_validation_error() + + app$set_module_input("font_size", "15") + app$expect_no_validation_error() + + app$stop() +}) From a20da5a9c41aed4c65cdbc7ffa53f83714a13564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Wed, 10 Apr 2024 15:39:48 +0200 Subject: [PATCH 02/25] fix: remove app view expressions --- tests/testthat/test-shinytest2-tm_a_pca.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index 71a4b34ef..b93907f7e 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -76,8 +76,6 @@ testthat::test_that("e2e - tm_a_pca: encodings update main panel", { ) ) - app$view() - browser() # Display section (hides tables) app$set_module_input("tables_display", c()) From a1a0c94c68f1711206fbf553f84c78bc1b606210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Wed, 10 Apr 2024 17:28:20 +0200 Subject: [PATCH 03/25] e2e feat: add remaining data extract input --- tests/testthat/test-shinytest2-tm_a_pca.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index b93907f7e..fa451dde3 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -44,6 +44,18 @@ testthat::test_that("e2e - tm_a_pca: data extract changes output", { testthat::expect_match(app$get_active_module_output("tbl_eigenvector"), "UrbanPop") + # Original Coordinate + app$set_module_input("plot_type", "Biplot") + app$set_module_input("variables", c("Murder")) + app$expect_no_validation_error() + + # Color by + app$set_module_input("response-dataset_USArrests_singleextract-select", c("Assault")) + app$expect_no_validation_error() + + app$set_module_input("response-dataset_USArrests_singleextract-select", c("Murder")) + app$expect_validation_error() + app$stop() }) From 5fb88858d1adb75bc238f028f8e5058a15aaf67b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:56:57 +0200 Subject: [PATCH 04/25] fix: linter errors --- tests/testthat/test-shinytest2-tm_a_pca.R | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index fa451dde3..ba4d497d7 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -7,11 +7,10 @@ testthat::test_that("e2e - tm_a_pca: data extract changes output", { require(nestcolor) require(ggplot2) - USArrests <- USArrests + USArrests <- USArrests # nolint: object_name. }) datanames(data) <- "USArrests" - app <- TealAppDriver$new( data = data, modules = tm_a_pca( @@ -67,7 +66,7 @@ testthat::test_that("e2e - tm_a_pca: encodings update main panel", { data <- within(teal_data(), { require(nestcolor) - USArrests <- USArrests + USArrests <- USArrests # nolint: object_name. }) datanames(data) <- "USArrests" @@ -125,10 +124,14 @@ testthat::test_that("e2e - tm_a_pca: encodings update main panel", { app$set_module_input("na_action", "drop") app$set_module_input("na_action", "none") - # Selected plot specific settings is not visible for Elbow plot + # Selected plot's specific settings is not visible no_plot_settings_selector <- sprintf("#%s-%s %s", app$active_module_ns(), "plot_settings", "span.help-block") x_axis_selector <- sprintf("#%s-%s", app$active_module_ns(), "x_axis") - color_by_selector <- sprintf("#%s-%s", app$active_module_ns(), "response-dataset_USArrests_singleextract-select_input") + color_by_selector <- sprintf( + "#%s-%s", + app$active_module_ns(), + "response-dataset_USArrests_singleextract-select_input" + ) app$set_module_input("plot_type", "Elbow plot", wait = FALSE) testthat::expect_true(app$is_visible(no_plot_settings_selector)) @@ -136,9 +139,12 @@ testthat::test_that("e2e - tm_a_pca: encodings update main panel", { testthat::expect_false(app$is_visible(color_by_selector)) app$set_module_input("plot_type", "Circle plot", wait = FALSE) + testthat::expect_false(app$is_visible(no_plot_settings_selector)) testthat::expect_true(app$is_visible(x_axis_selector)) app$set_module_input("plot_type", "Biplot", wait = FALSE) + testthat::expect_false(app$is_visible(no_plot_settings_selector)) + testthat::expect_true(app$is_visible(x_axis_selector)) testthat::expect_true(app$is_visible(color_by_selector)) # Theme From 08292fdce1ba08d8c4a6c534fd9671d2ad18e960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:09:52 +0200 Subject: [PATCH 05/25] fix: adds ggplot2 prefix to all calls --- R/tm_a_pca.R | 87 +++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/R/tm_a_pca.R b/R/tm_a_pca.R index 20e2c1cb9..4dccb1323 100644 --- a/R/tm_a_pca.R +++ b/R/tm_a_pca.R @@ -520,12 +520,12 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl theme = list( legend.position = "right", legend.spacing.y = quote(grid::unit(-5, "pt")), - legend.title = quote(element_text(vjust = 25)), + legend.title = quote(ggplot2::element_text(vjust = 25)), axis.text.x = substitute( - element_text(angle = angle_value, hjust = hjust_value), + ggplot2::element_text(angle = angle_value, hjust = hjust_value), list(angle_value = angle_value, hjust_value = hjust_value) ), - text = substitute(element_text(size = font_size), list(font_size = font_size)) + text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)) ) ) @@ -550,24 +550,24 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ) cols <- c(getOption("ggplot2.discrete.colour"), c("lightblue", "darkred", "black"))[1:3] - g <- ggplot(mapping = aes_string(x = "component", y = "value")) + - geom_bar( - aes(fill = "Single variance"), + g <- ggplot2::ggplot(mapping = ggplot2::aes_string(x = "component", y = "value")) + + ggplot2::geom_bar( + ggplot2::aes(fill = "Single variance"), data = dplyr::filter(elb_dat, metric == "Proportion of Variance"), color = "black", stat = "identity" ) + - geom_point( - aes(color = "Cumulative variance"), + ggplot2::geom_point( + ggplot2::aes(color = "Cumulative variance"), data = dplyr::filter(elb_dat, metric == "Cumulative Proportion") ) + - geom_line( - aes(group = 1, color = "Cumulative variance"), + ggplot2::geom_line( + ggplot2::aes(group = 1, color = "Cumulative variance"), data = dplyr::filter(elb_dat, metric == "Cumulative Proportion") ) + labs + - scale_color_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[3])) + - scale_fill_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[1])) + + ggplot2::scale_color_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[3])) + + ggplot2::scale_fill_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[1])) + ggthemes + themes @@ -597,9 +597,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl dev_ggplot2_args <- teal.widgets::ggplot2_args( theme = list( - text = substitute(element_text(size = font_size), list(font_size = font_size)), + text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)), axis.text.x = substitute( - element_text(angle = angle_val, hjust = hjust_val), + ggplot2::element_text(angle = angle_val, hjust = hjust_val), list(angle_val = angle, hjust_val = hjust) ) ) @@ -629,15 +629,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl y = sin(seq(0, 2 * pi, length.out = 100)) ) - g <- ggplot(pca_rot) + - geom_point(aes_string(x = x_axis, y = y_axis)) + - geom_label( - aes_string(x = x_axis, y = y_axis, label = "label"), + g <- ggplot2::ggplot(pca_rot) + + ggplot2::geom_point(ggplot2::aes_string(x = x_axis, y = y_axis)) + + ggplot2::geom_label( + ggplot2::aes_string(x = x_axis, y = y_axis, label = "label"), nudge_x = 0.1, nudge_y = 0.05, fontface = "bold" ) + - geom_path(aes(x, y, group = 1), data = circle_data) + - geom_point(aes(x = x, y = y), data = data.frame(x = 0, y = 0), shape = "x", size = 5) + + ggplot2::geom_path(ggplot2::aes(x, y, group = 1), data = circle_data) + + ggplot2::geom_point(ggplot2::aes(x = x, y = y), data = data.frame(x = 0, y = 0), shape = "x", size = 5) + labs + ggthemes + themes @@ -648,7 +648,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl y_axis = y_axis, variables = variables, ggthemes = parsed_ggplot2_args$ggtheme, - labs = `if`(is.null(parsed_ggplot2_args$labs), quote(labs()), parsed_ggplot2_args$labs), + labs = `if`(is.null(parsed_ggplot2_args$labs), quote(ggplot2::labs()), parsed_ggplot2_args$labs), themes = parsed_ggplot2_args$theme ) ) @@ -726,13 +726,16 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ) } - pca_plot_biplot_expr <- list(quote(ggplot())) + pca_plot_biplot_expr <- list(quote(ggplot2::ggplot())) if (length(resp_col) == 0) { pca_plot_biplot_expr <- c( pca_plot_biplot_expr, substitute( - geom_point(aes_string(x = x_axis, y = y_axis), data = pca_rot, alpha = alpha, size = size), + ggplot2::geom_point( + ggplot2::aes_string(x = x_axis, y = y_axis), + data = pca_rot, alpha = alpha, size = size + ), list(x_axis = input$x_axis, y_axis = input$y_axis, alpha = input$alpha, size = input$size) ) ) @@ -743,7 +746,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl response <- ANL[[resp_col]] aes_biplot <- substitute( - aes_string(x = x_axis, y = y_axis, color = "response"), + ggplot2::aes_string(x = x_axis, y = y_axis, color = "response"), env = list(x_axis = x_axis, y_axis = y_axis) ) @@ -764,7 +767,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl qenv, quote(pca_rot$response <- as.factor(response)) ) - quote(scale_color_brewer(palette = "Dark2")) + quote(ggplot2::scale_color_brewer(palette = "Dark2")) } else if (inherits(response, "Date")) { qenv <- teal.code::eval_code( qenv, @@ -772,7 +775,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ) quote( - scale_color_gradient( + ggplot2::scale_color_gradient( low = c(getOption("ggplot2.discrete.colour")[2], "darkred")[1], high = c(getOption("ggplot2.discrete.colour"), "lightblue")[1], labels = function(x) as.Date(x, origin = "1970-01-01") @@ -783,7 +786,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl qenv, quote(pca_rot$response <- response) ) - quote(scale_color_gradient( + quote(ggplot2::scale_color_gradient( low = c(getOption("ggplot2.discrete.colour")[2], "darkred")[1], high = c(getOption("ggplot2.discrete.colour"), "lightblue")[1] )) @@ -792,7 +795,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl pca_plot_biplot_expr <- c( pca_plot_biplot_expr, substitute( - geom_point(aes_biplot, data = pca_rot, alpha = alpha, size = size), + ggplot2::geom_point(aes_biplot, data = pca_rot, alpha = alpha, size = size), env = list(aes_biplot = aes_biplot, alpha = alpha, size = size) ), scales_biplot @@ -803,8 +806,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl pca_plot_biplot_expr <- c( pca_plot_biplot_expr, substitute( - geom_segment( - aes_string(x = "xstart", y = "ystart", xend = x_axis, yend = y_axis), + ggplot2::geom_segment( + ggplot2::aes_string(x = "xstart", y = "ystart", xend = x_axis, yend = y_axis), data = rot_vars, lineend = "round", linejoin = "round", arrow = grid::arrow(length = grid::unit(0.5, "cm")) @@ -812,8 +815,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl env = list(x_axis = x_axis, y_axis = y_axis) ), substitute( - geom_label( - aes_string( + ggplot2::geom_label( + ggplot2::aes_string( x = x_axis, y = y_axis, label = "label" @@ -824,7 +827,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ), env = list(x_axis = x_axis, y_axis = y_axis) ), - quote(geom_point(aes(x = xstart, y = ystart), data = rot_vars, shape = "x", size = 5)) + quote(ggplot2::geom_point(ggplot2::aes(x = xstart, y = ystart), data = rot_vars, shape = "x", size = 5)) ) } @@ -834,9 +837,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl dev_ggplot2_args <- teal.widgets::ggplot2_args( labs = dev_labs, theme = list( - text = substitute(element_text(size = font_size), list(font_size = font_size)), + text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)), axis.text.x = substitute( - element_text(angle = angle_val, hjust = hjust_val), + ggplot2::element_text(angle = angle_val, hjust = hjust_val), list(angle_val = angle, hjust_val = hjust) ) ) @@ -885,9 +888,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl dev_ggplot2_args <- teal.widgets::ggplot2_args( theme = list( - text = substitute(element_text(size = font_size), list(font_size = font_size)), + text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)), axis.text.x = substitute( - element_text(angle = angle_val, hjust = hjust_val), + ggplot2::element_text(angle = angle_val, hjust = hjust_val), list(angle_val = angle, hjust_val = hjust) ) ) @@ -906,10 +909,10 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ggplot_exprs <- c( list( - quote(ggplot(pca_rot)), + quote(ggplot2::ggplot(pca_rot)), substitute( - geom_bar( - aes_string(x = "Variable", y = pc), + ggplot2::geom_bar( + ggplot2::aes_string(x = "Variable", y = pc), stat = "identity", color = "black", fill = c(getOption("ggplot2.discrete.colour"), "lightblue")[1] @@ -917,8 +920,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl env = list(pc = pc) ), substitute( - geom_text( - aes( + ggplot2::geom_text( + ggplot2::aes( x = Variable, y = pc_name, label = round(pc_name, 3), From 7ebe92a3d9d40f77b2b68ba4c713f2da671de5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:25:25 +0200 Subject: [PATCH 06/25] fix: adds prefix to missing vars() call --- R/tm_a_pca.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_a_pca.R b/R/tm_a_pca.R index 4dccb1323..5eb1f1e26 100644 --- a/R/tm_a_pca.R +++ b/R/tm_a_pca.R @@ -694,7 +694,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl rot_vars <- pca$rotation[, c(x_axis, y_axis)] %>% dplyr::as_tibble(rownames = "label") %>% - dplyr::mutate_at(vars(c(x_axis, y_axis)), function(x) r * x / sqrt(max(v_scale))) + dplyr::mutate_at(ggplot2::vars(c(x_axis, y_axis)), function(x) r * x / sqrt(max(v_scale))) }, env = list(x_axis = x_axis, y_axis = y_axis) ) From 3cbee3f4fd332dc57b99a6c4f2784433db7e1d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:08:30 +0200 Subject: [PATCH 07/25] fix: remove requirement for loading shinytest2 and adds wait --- tests/testthat/test-shinytest2-tm_a_pca.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index ba4d497d7..2a711d47a 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -1,11 +1,8 @@ testthat::test_that("e2e - tm_a_pca: data extract changes output", { skip_if_too_deep(5) - require(shinytest2) - data <- within(teal_data(), { require(nestcolor) - require(ggplot2) USArrests <- USArrests # nolint: object_name. }) @@ -29,7 +26,8 @@ testthat::test_that("e2e - tm_a_pca: data extract changes output", { ) # Data selection (adds rows to tables) - app$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "Assault")) + app$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "Assault"), wait = FALSE) + app$wait_for_idle() app$expect_no_validation_error() testthat::expect_match(app$get_active_module_output("tbl_eigenvector"), "Assault") @@ -39,6 +37,7 @@ testthat::test_that("e2e - tm_a_pca: data extract changes output", { ) app$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "UrbanPop")) + app$wait_for_idle() app$expect_no_validation_error() testthat::expect_match(app$get_active_module_output("tbl_eigenvector"), "UrbanPop") @@ -46,13 +45,16 @@ testthat::test_that("e2e - tm_a_pca: data extract changes output", { # Original Coordinate app$set_module_input("plot_type", "Biplot") app$set_module_input("variables", c("Murder")) + app$wait_for_idle() app$expect_no_validation_error() # Color by app$set_module_input("response-dataset_USArrests_singleextract-select", c("Assault")) + app$wait_for_idle() app$expect_no_validation_error() app$set_module_input("response-dataset_USArrests_singleextract-select", c("Murder")) + app$wait_for_idle() app$expect_validation_error() app$stop() From ebb00ebaf9d8aa0a3a19b1ee803dc689dbb31b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:29:43 +0200 Subject: [PATCH 08/25] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com> Signed-off-by: André Veríssimo <211358+averissimo@users.noreply.github.com> --- tests/testthat/test-shinytest2-tm_a_pca.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index 2a711d47a..ff86a5e55 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -1,7 +1,7 @@ testthat::test_that("e2e - tm_a_pca: data extract changes output", { skip_if_too_deep(5) - data <- within(teal_data(), { + data <- within(teal.data::teal_data(), { require(nestcolor) USArrests <- USArrests # nolint: object_name. @@ -11,10 +11,10 @@ testthat::test_that("e2e - tm_a_pca: data extract changes output", { app <- TealAppDriver$new( data = data, modules = tm_a_pca( - dat = data_extract_spec( + dat = teal.transform::data_extract_spec( dataname = "USArrests", - select = select_spec( - choices = variable_choices( + select = teal.transform::select_spec( + choices = teal.transform::variable_choices( data = data[["USArrests"]], c("Murder", "Assault", "UrbanPop", "Rape") ), From e5c37835b2f4e6bd85755a48c374564a98f9f70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:32:02 +0200 Subject: [PATCH 09/25] feat: move app driver initialization to helper --- tests/testthat/helper-functions.R | 28 ++++ tests/testthat/test-shinytest2-tm_a_pca.R | 182 ++++++++-------------- 2 files changed, 96 insertions(+), 114 deletions(-) diff --git a/tests/testthat/helper-functions.R b/tests/testthat/helper-functions.R index 1bc8546bb..ed66eb661 100644 --- a/tests/testthat/helper-functions.R +++ b/tests/testthat/helper-functions.R @@ -10,3 +10,31 @@ mock_data_extract_spec <- function(dataname = "MOCK_DATASET", ) ) } + +# Based on example +local_app_tm_a_pca <- function() { + data <- within(teal.data::teal_data(), { + require(nestcolor) + + USArrests <- USArrests # nolint: object_name. + }) + datanames(data) <- "USArrests" + + + TealAppDriver$new( + data = data, + modules = tm_a_pca( + dat = teal.transform::data_extract_spec( + dataname = "USArrests", + select = teal.transform::select_spec( + choices = teal.transform::variable_choices( + data = data[["USArrests"]], + c("Murder", "Assault", "UrbanPop", "Rape") + ), + selected = c("Murder", "Assault"), + multiple = TRUE + ) + ) + ) + ) +} diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index ff86a5e55..d8a67ebfd 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -1,173 +1,127 @@ testthat::test_that("e2e - tm_a_pca: data extract changes output", { skip_if_too_deep(5) - data <- within(teal.data::teal_data(), { - require(nestcolor) - - USArrests <- USArrests # nolint: object_name. - }) - datanames(data) <- "USArrests" - - app <- TealAppDriver$new( - data = data, - modules = tm_a_pca( - dat = teal.transform::data_extract_spec( - dataname = "USArrests", - select = teal.transform::select_spec( - choices = teal.transform::variable_choices( - data = data[["USArrests"]], - c("Murder", "Assault", "UrbanPop", "Rape") - ), - selected = c("Murder", "Assault"), - multiple = TRUE - ) - ) - ) - ) + app_driver <- local_app_tm_a_pca() # Data selection (adds rows to tables) - app$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "Assault"), wait = FALSE) - app$wait_for_idle() - app$expect_no_validation_error() + app_driver$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "Assault"), wait = FALSE) + app_driver$wait_for_idle() + app_driver$expect_no_validation_error() - testthat::expect_match(app$get_active_module_output("tbl_eigenvector"), "Assault") + testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "Assault") testthat::expect_failure( - testthat::expect_match(app$get_active_module_output("tbl_eigenvector"), "UrbanPop") + testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "UrbanPop") ) - app$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "UrbanPop")) - app$wait_for_idle() - app$expect_no_validation_error() + app_driver$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "UrbanPop")) + app_driver$wait_for_idle() + app_driver$expect_no_validation_error() - testthat::expect_match(app$get_active_module_output("tbl_eigenvector"), "UrbanPop") + testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "UrbanPop") # Original Coordinate - app$set_module_input("plot_type", "Biplot") - app$set_module_input("variables", c("Murder")) - app$wait_for_idle() - app$expect_no_validation_error() + app_driver$set_module_input("plot_type", "Biplot") + app_driver$set_module_input("variables", c("Murder")) + app_driver$wait_for_idle() + app_driver$expect_no_validation_error() # Color by - app$set_module_input("response-dataset_USArrests_singleextract-select", c("Assault")) - app$wait_for_idle() - app$expect_no_validation_error() + app_driver$set_module_input("response-dataset_USArrests_singleextract-select", c("Assault")) + app_driver$wait_for_idle() + app_driver$expect_no_validation_error() - app$set_module_input("response-dataset_USArrests_singleextract-select", c("Murder")) - app$wait_for_idle() - app$expect_validation_error() + app_driver$set_module_input("response-dataset_USArrests_singleextract-select", c("Murder")) + app_driver$wait_for_idle() + app_driver$expect_validation_error() - app$stop() + app_driver$stop() }) testthat::test_that("e2e - tm_a_pca: encodings update main panel", { skip_if_too_deep(5) - require(shinytest2) - - data <- within(teal_data(), { - require(nestcolor) - - USArrests <- USArrests # nolint: object_name. - }) - datanames(data) <- "USArrests" - - app <- TealAppDriver$new( - data = data, - modules = tm_a_pca( - dat = data_extract_spec( - dataname = "USArrests", - select = select_spec( - choices = variable_choices( - data = data[["USArrests"]], - c("Murder", "Assault", "UrbanPop", "Rape") - ), - selected = c("Murder", "Assault"), - multiple = TRUE - ) - ) - ) - ) + app_driver <- local_app_tm_a_pca() # Display section (hides tables) - app$set_module_input("tables_display", c()) - app$expect_no_validation_error() + app_driver$set_module_input("tables_display", c()) + app_driver$expect_no_validation_error() - testthat::expect_type(app$get_active_module_output("tbl_importance"), "list") - testthat::expect_setequal(names(app$get_active_module_output("tbl_importance")), c("message", "call", "type")) + testthat::expect_type(app_driver$get_active_module_output("tbl_importance"), "list") + testthat::expect_setequal(names(app_driver$get_active_module_output("tbl_importance")), c("message", "call", "type")) - testthat::expect_type(app$get_active_module_output("tbl_eigenvector"), "list") - testthat::expect_setequal(names(app$get_active_module_output("tbl_eigenvector")), c("message", "call", "type")) + testthat::expect_type(app_driver$get_active_module_output("tbl_eigenvector"), "list") + testthat::expect_setequal(names(app_driver$get_active_module_output("tbl_eigenvector")), c("message", "call", "type")) # Plot type (select each) # Changing input will trigger an output change - app$set_module_input("plot_type", "Circle plot") - app$expect_no_validation_error() + app_driver$set_module_input("plot_type", "Circle plot") + app_driver$expect_no_validation_error() - app$set_module_input("plot_type", "Biplot") - app$expect_no_validation_error() + app_driver$set_module_input("plot_type", "Biplot") + app_driver$expect_no_validation_error() - app$set_module_input("plot_type", "Eigenvector plot") - app$expect_no_validation_error() + app_driver$set_module_input("plot_type", "Eigenvector plot") + app_driver$expect_no_validation_error() - app$set_module_input("plot_type", "Elbow plot") # Initial value - app$expect_no_validation_error() + app_driver$set_module_input("plot_type", "Elbow plot") # Initial value + app_driver$expect_no_validation_error() # Pre-processing - app$set_module_input("standardization", "center") - app$set_module_input("standardization", "center_scale") - app$set_module_input("standardization", "none") # Initial value + app_driver$set_module_input("standardization", "center") + app_driver$set_module_input("standardization", "center_scale") + app_driver$set_module_input("standardization", "none") # Initial value # NA Action - app$set_module_input("na_action", "drop") - app$set_module_input("na_action", "none") + app_driver$set_module_input("na_action", "drop") + app_driver$set_module_input("na_action", "none") # Selected plot's specific settings is not visible - no_plot_settings_selector <- sprintf("#%s-%s %s", app$active_module_ns(), "plot_settings", "span.help-block") - x_axis_selector <- sprintf("#%s-%s", app$active_module_ns(), "x_axis") + no_plot_settings_selector <- sprintf("#%s-%s %s", app_driver$active_module_ns(), "plot_settings", "span.help-block") + x_axis_selector <- sprintf("#%s-%s", app_driver$active_module_ns(), "x_axis") color_by_selector <- sprintf( "#%s-%s", - app$active_module_ns(), + app_driver$active_module_ns(), "response-dataset_USArrests_singleextract-select_input" ) - app$set_module_input("plot_type", "Elbow plot", wait = FALSE) - testthat::expect_true(app$is_visible(no_plot_settings_selector)) - testthat::expect_false(app$is_visible(x_axis_selector)) - testthat::expect_false(app$is_visible(color_by_selector)) + app_driver$set_module_input("plot_type", "Elbow plot", wait = FALSE) + testthat::expect_true(app_driver$is_visible(no_plot_settings_selector)) + testthat::expect_false(app_driver$is_visible(x_axis_selector)) + testthat::expect_false(app_driver$is_visible(color_by_selector)) - app$set_module_input("plot_type", "Circle plot", wait = FALSE) - testthat::expect_false(app$is_visible(no_plot_settings_selector)) - testthat::expect_true(app$is_visible(x_axis_selector)) + app_driver$set_module_input("plot_type", "Circle plot", wait = FALSE) + testthat::expect_false(app_driver$is_visible(no_plot_settings_selector)) + testthat::expect_true(app_driver$is_visible(x_axis_selector)) - app$set_module_input("plot_type", "Biplot", wait = FALSE) - testthat::expect_false(app$is_visible(no_plot_settings_selector)) - testthat::expect_true(app$is_visible(x_axis_selector)) - testthat::expect_true(app$is_visible(color_by_selector)) + app_driver$set_module_input("plot_type", "Biplot", wait = FALSE) + testthat::expect_false(app_driver$is_visible(no_plot_settings_selector)) + testthat::expect_true(app_driver$is_visible(x_axis_selector)) + testthat::expect_true(app_driver$is_visible(color_by_selector)) # Theme - app$set_module_input("ggtheme-selectized", "bw") - app$expect_no_validation_error() - app$set_module_input("ggtheme-selectized", "light") - app$expect_no_validation_error() - app$set_module_input("ggtheme-selectized", "dark") - app$expect_no_validation_error() + app_driver$set_module_input("ggtheme-selectized", "bw") + app_driver$expect_no_validation_error() + app_driver$set_module_input("ggtheme-selectized", "light") + app_driver$expect_no_validation_error() + app_driver$set_module_input("ggtheme-selectized", "dark") + app_driver$expect_no_validation_error() # Font size - app$set_module_input("font_size", "8") - app$expect_no_validation_error() + app_driver$set_module_input("font_size", "8") + app_driver$expect_no_validation_error() - app$set_module_input("font_size", "20") - app$expect_no_validation_error() + app_driver$set_module_input("font_size", "20") + app_driver$expect_no_validation_error() - app$set_module_input("font_size", "15") - app$expect_no_validation_error() + app_driver$set_module_input("font_size", "15") + app_driver$expect_no_validation_error() - app$stop() + app_driver$stop() }) From f578c62898678d3144f0b2413f1fd4059327c277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:48:39 +0200 Subject: [PATCH 10/25] feat: split complex test into smaller tests --- tests/testthat/helper-TealAppDriver.R | 33 ++++++++++++++++++++++- tests/testthat/helper-functions.R | 28 ------------------- tests/testthat/test-shinytest2-tm_a_pca.R | 26 +++++++++++++----- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/tests/testthat/helper-TealAppDriver.R b/tests/testthat/helper-TealAppDriver.R index 39e5c28d9..726628b57 100644 --- a/tests/testthat/helper-TealAppDriver.R +++ b/tests/testthat/helper-TealAppDriver.R @@ -1,7 +1,7 @@ # Import non-exported TealAppDriver from `teal` package TealAppDriver <- getFromNamespace("TealAppDriver", "teal") # nolint: object_name. -# Helper function +# Data helper functions for reusable datasets --------------------------------- simple_teal_data <- function() { data <- within(teal.data::teal_data(), { require(nestcolor) @@ -27,3 +27,34 @@ simple_cdisc_data <- function(datasets = c("ADSL", "ADRS", "ADTTE")) { teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[datasets] data } + +# local app drivers for module testing ---------------------------------------- +# based on examples + +local_app_tm_a_pca <- function() { + # Dataset only used once + data <- within(teal.data::teal_data(), { + require(nestcolor) + + USArrests <- USArrests # nolint: object_name. + }) + teal.data::datanames(data) <- "USArrests" + + + TealAppDriver$new( + data = data, + modules = tm_a_pca( + dat = teal.transform::data_extract_spec( + dataname = "USArrests", + select = teal.transform::select_spec( + choices = teal.transform::variable_choices( + data = data[["USArrests"]], + c("Murder", "Assault", "UrbanPop", "Rape") + ), + selected = c("Murder", "Assault"), + multiple = TRUE + ) + ) + ) + ) +} diff --git a/tests/testthat/helper-functions.R b/tests/testthat/helper-functions.R index ed66eb661..1bc8546bb 100644 --- a/tests/testthat/helper-functions.R +++ b/tests/testthat/helper-functions.R @@ -10,31 +10,3 @@ mock_data_extract_spec <- function(dataname = "MOCK_DATASET", ) ) } - -# Based on example -local_app_tm_a_pca <- function() { - data <- within(teal.data::teal_data(), { - require(nestcolor) - - USArrests <- USArrests # nolint: object_name. - }) - datanames(data) <- "USArrests" - - - TealAppDriver$new( - data = data, - modules = tm_a_pca( - dat = teal.transform::data_extract_spec( - dataname = "USArrests", - select = teal.transform::select_spec( - choices = teal.transform::variable_choices( - data = data[["USArrests"]], - c("Murder", "Assault", "UrbanPop", "Rape") - ), - selected = c("Murder", "Assault"), - multiple = TRUE - ) - ) - ) - ) -} diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index d8a67ebfd..08b47e9ce 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -1,4 +1,4 @@ -testthat::test_that("e2e - tm_a_pca: data extract changes output", { +testthat::test_that("e2e - tm_a_pca: Data selection (data_extract) changes eigenvector table", { skip_if_too_deep(5) app_driver <- local_app_tm_a_pca() @@ -13,21 +13,33 @@ testthat::test_that("e2e - tm_a_pca: data extract changes output", { testthat::expect_failure( testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "UrbanPop") ) +}) + +testthat::test_that("e2e - tm_a_pca: Original coordinates (data_extract) changes output of plot", { + skip_if_too_deep(5) + + app_driver <- local_app_tm_a_pca() + + app_driver$set_module_input("plot_type", "Circle plot") + app_driver$wait_for_idle() app_driver$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "UrbanPop")) app_driver$wait_for_idle() app_driver$expect_no_validation_error() testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "UrbanPop") +}) + +testthat::test_that("e2e - tm_a_pca: Color by columns (data_extract) must be from non-selected variable set", { + skip_if_too_deep(5) + + app_driver <- local_app_tm_a_pca() - # Original Coordinate app_driver$set_module_input("plot_type", "Biplot") - app_driver$set_module_input("variables", c("Murder")) app_driver$wait_for_idle() - app_driver$expect_no_validation_error() - # Color by - app_driver$set_module_input("response-dataset_USArrests_singleextract-select", c("Assault")) + # Change colors of data points + app_driver$set_module_input("response-dataset_USArrests_singleextract-select", c("UrbanPop")) app_driver$wait_for_idle() app_driver$expect_no_validation_error() @@ -38,7 +50,7 @@ testthat::test_that("e2e - tm_a_pca: data extract changes output", { app_driver$stop() }) -testthat::test_that("e2e - tm_a_pca: encodings update main panel", { +testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate errors", { skip_if_too_deep(5) app_driver <- local_app_tm_a_pca() From 119db66a81aaf8b6c1ccece09416b6b94715d299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 12 Apr 2024 10:46:15 +0200 Subject: [PATCH 11/25] chore: rename helper name --- tests/testthat/helper-TealAppDriver.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/helper-TealAppDriver.R b/tests/testthat/helper-TealAppDriver.R index 726628b57..99db5d797 100644 --- a/tests/testthat/helper-TealAppDriver.R +++ b/tests/testthat/helper-TealAppDriver.R @@ -31,7 +31,7 @@ simple_cdisc_data <- function(datasets = c("ADSL", "ADRS", "ADTTE")) { # local app drivers for module testing ---------------------------------------- # based on examples -local_app_tm_a_pca <- function() { +app_driver_tm_a_pca <- function() { # Dataset only used once data <- within(teal.data::teal_data(), { require(nestcolor) From 59594fdb31644718b73bf0e59a8ada1889d5d67f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 12 Apr 2024 10:47:42 +0200 Subject: [PATCH 12/25] chore: remove wait_for_idle as it was implementd upstream --- tests/testthat/test-shinytest2-tm_a_pca.R | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index 08b47e9ce..923bd9c93 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -5,7 +5,6 @@ testthat::test_that("e2e - tm_a_pca: Data selection (data_extract) changes eigen # Data selection (adds rows to tables) app_driver$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "Assault"), wait = FALSE) - app_driver$wait_for_idle() app_driver$expect_no_validation_error() testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "Assault") @@ -21,10 +20,8 @@ testthat::test_that("e2e - tm_a_pca: Original coordinates (data_extract) changes app_driver <- local_app_tm_a_pca() app_driver$set_module_input("plot_type", "Circle plot") - app_driver$wait_for_idle() app_driver$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "UrbanPop")) - app_driver$wait_for_idle() app_driver$expect_no_validation_error() testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "UrbanPop") @@ -36,15 +33,12 @@ testthat::test_that("e2e - tm_a_pca: Color by columns (data_extract) must be fro app_driver <- local_app_tm_a_pca() app_driver$set_module_input("plot_type", "Biplot") - app_driver$wait_for_idle() # Change colors of data points app_driver$set_module_input("response-dataset_USArrests_singleextract-select", c("UrbanPop")) - app_driver$wait_for_idle() app_driver$expect_no_validation_error() app_driver$set_module_input("response-dataset_USArrests_singleextract-select", c("Murder")) - app_driver$wait_for_idle() app_driver$expect_validation_error() app_driver$stop() From e7d14b587becb97774f79700fd95c7d06b76e59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 12 Apr 2024 12:46:08 +0200 Subject: [PATCH 13/25] fix: rename missing instances --- tests/testthat/test-shinytest2-tm_a_pca.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index 923bd9c93..afc2661f9 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -1,7 +1,7 @@ testthat::test_that("e2e - tm_a_pca: Data selection (data_extract) changes eigenvector table", { skip_if_too_deep(5) - app_driver <- local_app_tm_a_pca() + app_driver <- app_tm_a_pca() # Data selection (adds rows to tables) app_driver$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "Assault"), wait = FALSE) @@ -17,7 +17,7 @@ testthat::test_that("e2e - tm_a_pca: Data selection (data_extract) changes eigen testthat::test_that("e2e - tm_a_pca: Original coordinates (data_extract) changes output of plot", { skip_if_too_deep(5) - app_driver <- local_app_tm_a_pca() + app_driver <- app_tm_a_pca() app_driver$set_module_input("plot_type", "Circle plot") @@ -30,7 +30,7 @@ testthat::test_that("e2e - tm_a_pca: Original coordinates (data_extract) changes testthat::test_that("e2e - tm_a_pca: Color by columns (data_extract) must be from non-selected variable set", { skip_if_too_deep(5) - app_driver <- local_app_tm_a_pca() + app_driver <- app_tm_a_pca() app_driver$set_module_input("plot_type", "Biplot") @@ -47,7 +47,7 @@ testthat::test_that("e2e - tm_a_pca: Color by columns (data_extract) must be fro testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate errors", { skip_if_too_deep(5) - app_driver <- local_app_tm_a_pca() + app_driver <- app_tm_a_pca() # Display section (hides tables) From c5fe9e54c4d73a8d4dde7ffa270f13240120673c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 12 Apr 2024 17:09:02 +0200 Subject: [PATCH 14/25] fix: missing _driver on call --- tests/testthat/test-shinytest2-tm_a_pca.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index afc2661f9..4c33e1c3d 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -1,7 +1,7 @@ testthat::test_that("e2e - tm_a_pca: Data selection (data_extract) changes eigenvector table", { skip_if_too_deep(5) - app_driver <- app_tm_a_pca() + app_driver <- app_driver_tm_a_pca() # Data selection (adds rows to tables) app_driver$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "Assault"), wait = FALSE) @@ -17,7 +17,7 @@ testthat::test_that("e2e - tm_a_pca: Data selection (data_extract) changes eigen testthat::test_that("e2e - tm_a_pca: Original coordinates (data_extract) changes output of plot", { skip_if_too_deep(5) - app_driver <- app_tm_a_pca() + app_driver <- app_driver_tm_a_pca() app_driver$set_module_input("plot_type", "Circle plot") @@ -30,7 +30,7 @@ testthat::test_that("e2e - tm_a_pca: Original coordinates (data_extract) changes testthat::test_that("e2e - tm_a_pca: Color by columns (data_extract) must be from non-selected variable set", { skip_if_too_deep(5) - app_driver <- app_tm_a_pca() + app_driver <- app_driver_tm_a_pca() app_driver$set_module_input("plot_type", "Biplot") @@ -47,7 +47,7 @@ testthat::test_that("e2e - tm_a_pca: Color by columns (data_extract) must be fro testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate errors", { skip_if_too_deep(5) - app_driver <- app_tm_a_pca() + app_driver <- app_driver_tm_a_pca() # Display section (hides tables) From 1791583cdd635e4cd16d36f0a07a1656a63d48fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Mon, 15 Apr 2024 12:57:37 +0200 Subject: [PATCH 15/25] fix: move helper to test file --- tests/testthat/helper-TealAppDriver.R | 31 ----------------------- tests/testthat/test-shinytest2-tm_a_pca.R | 28 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/tests/testthat/helper-TealAppDriver.R b/tests/testthat/helper-TealAppDriver.R index 99db5d797..d2dc7fc70 100644 --- a/tests/testthat/helper-TealAppDriver.R +++ b/tests/testthat/helper-TealAppDriver.R @@ -27,34 +27,3 @@ simple_cdisc_data <- function(datasets = c("ADSL", "ADRS", "ADTTE")) { teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[datasets] data } - -# local app drivers for module testing ---------------------------------------- -# based on examples - -app_driver_tm_a_pca <- function() { - # Dataset only used once - data <- within(teal.data::teal_data(), { - require(nestcolor) - - USArrests <- USArrests # nolint: object_name. - }) - teal.data::datanames(data) <- "USArrests" - - - TealAppDriver$new( - data = data, - modules = tm_a_pca( - dat = teal.transform::data_extract_spec( - dataname = "USArrests", - select = teal.transform::select_spec( - choices = teal.transform::variable_choices( - data = data[["USArrests"]], - c("Murder", "Assault", "UrbanPop", "Rape") - ), - selected = c("Murder", "Assault"), - multiple = TRUE - ) - ) - ) - ) -} diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index 4c33e1c3d..0a23b83a0 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -1,3 +1,31 @@ +app_driver_tm_a_pca <- function() { + # Dataset only used once + data <- within(teal.data::teal_data(), { + require(nestcolor) + + USArrests <- USArrests # nolint: object_name. + }) + teal.data::datanames(data) <- "USArrests" + + + TealAppDriver$new( + data = data, + modules = tm_a_pca( + dat = teal.transform::data_extract_spec( + dataname = "USArrests", + select = teal.transform::select_spec( + choices = teal.transform::variable_choices( + data = data[["USArrests"]], + c("Murder", "Assault", "UrbanPop", "Rape") + ), + selected = c("Murder", "Assault"), + multiple = TRUE + ) + ) + ) + ) +} + testthat::test_that("e2e - tm_a_pca: Data selection (data_extract) changes eigenvector table", { skip_if_too_deep(5) From c7af8ca63a75fbb70d42d06383c685e61b4e7f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Mon, 15 Apr 2024 13:00:36 +0200 Subject: [PATCH 16/25] adds some expect_no_validation_error --- tests/testthat/test-shinytest2-tm_a_pca.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index 0a23b83a0..3e932547d 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -106,8 +106,11 @@ testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate # Pre-processing app_driver$set_module_input("standardization", "center") + app_driver$expect_no_validation_error app_driver$set_module_input("standardization", "center_scale") + app_driver$expect_no_validation_error app_driver$set_module_input("standardization", "none") # Initial value + app_driver$expect_no_validation_error # NA Action From 4356c729f113e7021ed494eb3836020030afa2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:09:16 +0200 Subject: [PATCH 17/25] docs: revert prefixes --- R/tm_a_pca.R | 88 ++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/R/tm_a_pca.R b/R/tm_a_pca.R index 5eb1f1e26..6fe0bd34f 100644 --- a/R/tm_a_pca.R +++ b/R/tm_a_pca.R @@ -520,12 +520,12 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl theme = list( legend.position = "right", legend.spacing.y = quote(grid::unit(-5, "pt")), - legend.title = quote(ggplot2::element_text(vjust = 25)), + legend.title = quote(element_text(vjust = 25)), axis.text.x = substitute( - ggplot2::element_text(angle = angle_value, hjust = hjust_value), + element_text(angle = angle_value, hjust = hjust_value), list(angle_value = angle_value, hjust_value = hjust_value) ), - text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)) + text = substitute(element_text(size = font_size), list(font_size = font_size)) ) ) @@ -550,24 +550,24 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ) cols <- c(getOption("ggplot2.discrete.colour"), c("lightblue", "darkred", "black"))[1:3] - g <- ggplot2::ggplot(mapping = ggplot2::aes_string(x = "component", y = "value")) + - ggplot2::geom_bar( - ggplot2::aes(fill = "Single variance"), + g <- ggplot(mapping = aes_string(x = "component", y = "value")) + + geom_bar( + aes(fill = "Single variance"), data = dplyr::filter(elb_dat, metric == "Proportion of Variance"), color = "black", stat = "identity" ) + - ggplot2::geom_point( - ggplot2::aes(color = "Cumulative variance"), + geom_point( + aes(color = "Cumulative variance"), data = dplyr::filter(elb_dat, metric == "Cumulative Proportion") ) + - ggplot2::geom_line( - ggplot2::aes(group = 1, color = "Cumulative variance"), + geom_line( + aes(group = 1, color = "Cumulative variance"), data = dplyr::filter(elb_dat, metric == "Cumulative Proportion") ) + labs + - ggplot2::scale_color_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[3])) + - ggplot2::scale_fill_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[1])) + + scale_color_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[3])) + + scale_fill_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[1])) + ggthemes + themes @@ -597,9 +597,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl dev_ggplot2_args <- teal.widgets::ggplot2_args( theme = list( - text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)), + text = substitute(element_text(size = font_size), list(font_size = font_size)), axis.text.x = substitute( - ggplot2::element_text(angle = angle_val, hjust = hjust_val), + element_text(angle = angle_val, hjust = hjust_val), list(angle_val = angle, hjust_val = hjust) ) ) @@ -629,15 +629,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl y = sin(seq(0, 2 * pi, length.out = 100)) ) - g <- ggplot2::ggplot(pca_rot) + - ggplot2::geom_point(ggplot2::aes_string(x = x_axis, y = y_axis)) + - ggplot2::geom_label( - ggplot2::aes_string(x = x_axis, y = y_axis, label = "label"), + g <- ggplot(pca_rot) + + geom_point(aes_string(x = x_axis, y = y_axis)) + + geom_label( + aes_string(x = x_axis, y = y_axis, label = "label"), nudge_x = 0.1, nudge_y = 0.05, fontface = "bold" ) + - ggplot2::geom_path(ggplot2::aes(x, y, group = 1), data = circle_data) + - ggplot2::geom_point(ggplot2::aes(x = x, y = y), data = data.frame(x = 0, y = 0), shape = "x", size = 5) + + geom_path(aes(x, y, group = 1), data = circle_data) + + geom_point(aes(x = x, y = y), data = data.frame(x = 0, y = 0), shape = "x", size = 5) + labs + ggthemes + themes @@ -648,7 +648,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl y_axis = y_axis, variables = variables, ggthemes = parsed_ggplot2_args$ggtheme, - labs = `if`(is.null(parsed_ggplot2_args$labs), quote(ggplot2::labs()), parsed_ggplot2_args$labs), + labs = `if`(is.null(parsed_ggplot2_args$labs), quote(labs()), parsed_ggplot2_args$labs), themes = parsed_ggplot2_args$theme ) ) @@ -694,7 +694,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl rot_vars <- pca$rotation[, c(x_axis, y_axis)] %>% dplyr::as_tibble(rownames = "label") %>% - dplyr::mutate_at(ggplot2::vars(c(x_axis, y_axis)), function(x) r * x / sqrt(max(v_scale))) + dplyr::mutate_at(vars(c(x_axis, y_axis)), function(x) r * x / sqrt(max(v_scale))) }, env = list(x_axis = x_axis, y_axis = y_axis) ) @@ -726,14 +726,14 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ) } - pca_plot_biplot_expr <- list(quote(ggplot2::ggplot())) + pca_plot_biplot_expr <- list(quote(ggplot())) if (length(resp_col) == 0) { pca_plot_biplot_expr <- c( pca_plot_biplot_expr, substitute( - ggplot2::geom_point( - ggplot2::aes_string(x = x_axis, y = y_axis), + geom_point( + aes_string(x = x_axis, y = y_axis), data = pca_rot, alpha = alpha, size = size ), list(x_axis = input$x_axis, y_axis = input$y_axis, alpha = input$alpha, size = input$size) @@ -746,7 +746,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl response <- ANL[[resp_col]] aes_biplot <- substitute( - ggplot2::aes_string(x = x_axis, y = y_axis, color = "response"), + aes_string(x = x_axis, y = y_axis, color = "response"), env = list(x_axis = x_axis, y_axis = y_axis) ) @@ -767,7 +767,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl qenv, quote(pca_rot$response <- as.factor(response)) ) - quote(ggplot2::scale_color_brewer(palette = "Dark2")) + quote(scale_color_brewer(palette = "Dark2")) } else if (inherits(response, "Date")) { qenv <- teal.code::eval_code( qenv, @@ -775,7 +775,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ) quote( - ggplot2::scale_color_gradient( + scale_color_gradient( low = c(getOption("ggplot2.discrete.colour")[2], "darkred")[1], high = c(getOption("ggplot2.discrete.colour"), "lightblue")[1], labels = function(x) as.Date(x, origin = "1970-01-01") @@ -786,7 +786,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl qenv, quote(pca_rot$response <- response) ) - quote(ggplot2::scale_color_gradient( + quote(scale_color_gradient( low = c(getOption("ggplot2.discrete.colour")[2], "darkred")[1], high = c(getOption("ggplot2.discrete.colour"), "lightblue")[1] )) @@ -795,7 +795,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl pca_plot_biplot_expr <- c( pca_plot_biplot_expr, substitute( - ggplot2::geom_point(aes_biplot, data = pca_rot, alpha = alpha, size = size), + geom_point(aes_biplot, data = pca_rot, alpha = alpha, size = size), env = list(aes_biplot = aes_biplot, alpha = alpha, size = size) ), scales_biplot @@ -806,8 +806,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl pca_plot_biplot_expr <- c( pca_plot_biplot_expr, substitute( - ggplot2::geom_segment( - ggplot2::aes_string(x = "xstart", y = "ystart", xend = x_axis, yend = y_axis), + geom_segment( + aes_string(x = "xstart", y = "ystart", xend = x_axis, yend = y_axis), data = rot_vars, lineend = "round", linejoin = "round", arrow = grid::arrow(length = grid::unit(0.5, "cm")) @@ -815,8 +815,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl env = list(x_axis = x_axis, y_axis = y_axis) ), substitute( - ggplot2::geom_label( - ggplot2::aes_string( + geom_label( + aes_string( x = x_axis, y = y_axis, label = "label" @@ -827,7 +827,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ), env = list(x_axis = x_axis, y_axis = y_axis) ), - quote(ggplot2::geom_point(ggplot2::aes(x = xstart, y = ystart), data = rot_vars, shape = "x", size = 5)) + quote(geom_point(aes(x = xstart, y = ystart), data = rot_vars, shape = "x", size = 5)) ) } @@ -837,9 +837,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl dev_ggplot2_args <- teal.widgets::ggplot2_args( labs = dev_labs, theme = list( - text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)), + text = substitute(element_text(size = font_size), list(font_size = font_size)), axis.text.x = substitute( - ggplot2::element_text(angle = angle_val, hjust = hjust_val), + element_text(angle = angle_val, hjust = hjust_val), list(angle_val = angle, hjust_val = hjust) ) ) @@ -888,9 +888,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl dev_ggplot2_args <- teal.widgets::ggplot2_args( theme = list( - text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)), + text = substitute(element_text(size = font_size), list(font_size = font_size)), axis.text.x = substitute( - ggplot2::element_text(angle = angle_val, hjust = hjust_val), + element_text(angle = angle_val, hjust = hjust_val), list(angle_val = angle, hjust_val = hjust) ) ) @@ -909,10 +909,10 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ggplot_exprs <- c( list( - quote(ggplot2::ggplot(pca_rot)), + quote(ggplot(pca_rot)), substitute( - ggplot2::geom_bar( - ggplot2::aes_string(x = "Variable", y = pc), + geom_bar( + aes_string(x = "Variable", y = pc), stat = "identity", color = "black", fill = c(getOption("ggplot2.discrete.colour"), "lightblue")[1] @@ -920,8 +920,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl env = list(pc = pc) ), substitute( - ggplot2::geom_text( - ggplot2::aes( + geom_text( + aes( x = Variable, y = pc_name, label = round(pc_name, 3), From 2abbd29e3c8802071b08f3216dc74ff0b6df839b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:10:49 +0200 Subject: [PATCH 18/25] chore: revert multiline to single line --- R/tm_a_pca.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/R/tm_a_pca.R b/R/tm_a_pca.R index 6fe0bd34f..20e2c1cb9 100644 --- a/R/tm_a_pca.R +++ b/R/tm_a_pca.R @@ -732,10 +732,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl pca_plot_biplot_expr <- c( pca_plot_biplot_expr, substitute( - geom_point( - aes_string(x = x_axis, y = y_axis), - data = pca_rot, alpha = alpha, size = size - ), + geom_point(aes_string(x = x_axis, y = y_axis), data = pca_rot, alpha = alpha, size = size), list(x_axis = input$x_axis, y_axis = input$y_axis, alpha = input$alpha, size = input$size) ) ) From 65eab4e94ecfece2c1a71c3ef6a095e5cb527742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:11:47 +0200 Subject: [PATCH 19/25] chore: revert change in comment --- tests/testthat/helper-TealAppDriver.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/helper-TealAppDriver.R b/tests/testthat/helper-TealAppDriver.R index d2dc7fc70..39e5c28d9 100644 --- a/tests/testthat/helper-TealAppDriver.R +++ b/tests/testthat/helper-TealAppDriver.R @@ -1,7 +1,7 @@ # Import non-exported TealAppDriver from `teal` package TealAppDriver <- getFromNamespace("TealAppDriver", "teal") # nolint: object_name. -# Data helper functions for reusable datasets --------------------------------- +# Helper function simple_teal_data <- function() { data <- within(teal.data::teal_data(), { require(nestcolor) From a51e7450342c70a6297e3a76da52d2275f9a91b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:12:58 +0200 Subject: [PATCH 20/25] Apply suggestions from @m7pr on `set_active_module_input` rename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com> Signed-off-by: André Veríssimo <211358+averissimo@users.noreply.github.com> --- tests/testthat/test-shinytest2-tm_a_pca.R | 50 +++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index 3e932547d..b329ef8af 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -32,7 +32,7 @@ testthat::test_that("e2e - tm_a_pca: Data selection (data_extract) changes eigen app_driver <- app_driver_tm_a_pca() # Data selection (adds rows to tables) - app_driver$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "Assault"), wait = FALSE) + app_driver$set_active_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "Assault"), wait = FALSE) app_driver$expect_no_validation_error() testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "Assault") @@ -47,9 +47,9 @@ testthat::test_that("e2e - tm_a_pca: Original coordinates (data_extract) changes app_driver <- app_driver_tm_a_pca() - app_driver$set_module_input("plot_type", "Circle plot") + app_driver$set_active_module_input("plot_type", "Circle plot") - app_driver$set_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "UrbanPop")) + app_driver$set_active_module_input("dat-dataset_USArrests_singleextract-select", c("Murder", "UrbanPop")) app_driver$expect_no_validation_error() testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "UrbanPop") @@ -60,13 +60,13 @@ testthat::test_that("e2e - tm_a_pca: Color by columns (data_extract) must be fro app_driver <- app_driver_tm_a_pca() - app_driver$set_module_input("plot_type", "Biplot") + app_driver$set_active_module_input("plot_type", "Biplot") # Change colors of data points - app_driver$set_module_input("response-dataset_USArrests_singleextract-select", c("UrbanPop")) + app_driver$set_active_module_input("response-dataset_USArrests_singleextract-select", c("UrbanPop")) app_driver$expect_no_validation_error() - app_driver$set_module_input("response-dataset_USArrests_singleextract-select", c("Murder")) + app_driver$set_active_module_input("response-dataset_USArrests_singleextract-select", c("Murder")) app_driver$expect_validation_error() app_driver$stop() @@ -79,7 +79,7 @@ testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate # Display section (hides tables) - app_driver$set_module_input("tables_display", c()) + app_driver$set_active_module_input("tables_display", c()) app_driver$expect_no_validation_error() testthat::expect_type(app_driver$get_active_module_output("tbl_importance"), "list") @@ -91,31 +91,31 @@ testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate # Plot type (select each) # Changing input will trigger an output change - app_driver$set_module_input("plot_type", "Circle plot") + app_driver$set_active_module_input("plot_type", "Circle plot") app_driver$expect_no_validation_error() - app_driver$set_module_input("plot_type", "Biplot") + app_driver$set_active_module_input("plot_type", "Biplot") app_driver$expect_no_validation_error() - app_driver$set_module_input("plot_type", "Eigenvector plot") + app_driver$set_active_module_input("plot_type", "Eigenvector plot") app_driver$expect_no_validation_error() - app_driver$set_module_input("plot_type", "Elbow plot") # Initial value + app_driver$set_active_module_input("plot_type", "Elbow plot") # Initial value app_driver$expect_no_validation_error() # Pre-processing - app_driver$set_module_input("standardization", "center") + app_driver$set_active_module_input("standardization", "center") app_driver$expect_no_validation_error - app_driver$set_module_input("standardization", "center_scale") + app_driver$set_active_module_input("standardization", "center_scale") app_driver$expect_no_validation_error - app_driver$set_module_input("standardization", "none") # Initial value + app_driver$set_active_module_input("standardization", "none") # Initial value app_driver$expect_no_validation_error # NA Action - app_driver$set_module_input("na_action", "drop") - app_driver$set_module_input("na_action", "none") + app_driver$set_active_module_input("na_action", "drop") + app_driver$set_active_module_input("na_action", "none") # Selected plot's specific settings is not visible no_plot_settings_selector <- sprintf("#%s-%s %s", app_driver$active_module_ns(), "plot_settings", "span.help-block") @@ -126,38 +126,38 @@ testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate "response-dataset_USArrests_singleextract-select_input" ) - app_driver$set_module_input("plot_type", "Elbow plot", wait = FALSE) + app_driver$set_active_module_input("plot_type", "Elbow plot", wait = FALSE) testthat::expect_true(app_driver$is_visible(no_plot_settings_selector)) testthat::expect_false(app_driver$is_visible(x_axis_selector)) testthat::expect_false(app_driver$is_visible(color_by_selector)) - app_driver$set_module_input("plot_type", "Circle plot", wait = FALSE) + app_driver$set_active_module_input("plot_type", "Circle plot", wait = FALSE) testthat::expect_false(app_driver$is_visible(no_plot_settings_selector)) testthat::expect_true(app_driver$is_visible(x_axis_selector)) - app_driver$set_module_input("plot_type", "Biplot", wait = FALSE) + app_driver$set_active_module_input("plot_type", "Biplot", wait = FALSE) testthat::expect_false(app_driver$is_visible(no_plot_settings_selector)) testthat::expect_true(app_driver$is_visible(x_axis_selector)) testthat::expect_true(app_driver$is_visible(color_by_selector)) # Theme - app_driver$set_module_input("ggtheme-selectized", "bw") + app_driver$set_active_module_input("ggtheme-selectized", "bw") app_driver$expect_no_validation_error() - app_driver$set_module_input("ggtheme-selectized", "light") + app_driver$set_active_module_input("ggtheme-selectized", "light") app_driver$expect_no_validation_error() - app_driver$set_module_input("ggtheme-selectized", "dark") + app_driver$set_active_module_input("ggtheme-selectized", "dark") app_driver$expect_no_validation_error() # Font size - app_driver$set_module_input("font_size", "8") + app_driver$set_active_module_input("font_size", "8") app_driver$expect_no_validation_error() - app_driver$set_module_input("font_size", "20") + app_driver$set_active_module_input("font_size", "20") app_driver$expect_no_validation_error() - app_driver$set_module_input("font_size", "15") + app_driver$set_active_module_input("font_size", "15") app_driver$expect_no_validation_error() app_driver$stop() From ce2a06eea1443206800d2b519e370e55efca742d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:29:42 +0200 Subject: [PATCH 21/25] fix: replace TealAppDriver with init_teal_app_driver --- tests/testthat/test-shinytest2-tm_a_pca.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index b329ef8af..e537446b6 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -8,7 +8,7 @@ app_driver_tm_a_pca <- function() { teal.data::datanames(data) <- "USArrests" - TealAppDriver$new( + init_teal_app_driver( data = data, modules = tm_a_pca( dat = teal.transform::data_extract_spec( From 98751d4d7c66e0e3e3817f4f7c6e66d1927b241e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:59:53 +0200 Subject: [PATCH 22/25] Update tests/testthat/test-shinytest2-tm_a_pca.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dawid Kałędkowski <6959016+gogonzo@users.noreply.github.com> Signed-off-by: André Veríssimo <211358+averissimo@users.noreply.github.com> --- tests/testthat/test-shinytest2-tm_a_pca.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index e537446b6..5bc15fee9 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -37,9 +37,7 @@ testthat::test_that("e2e - tm_a_pca: Data selection (data_extract) changes eigen testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "Assault") - testthat::expect_failure( - testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "UrbanPop") - ) + testthat::expect_no_match(app_driver$get_active_module_output("tbl_eigenvector"), "UrbanPop") }) testthat::test_that("e2e - tm_a_pca: Original coordinates (data_extract) changes output of plot", { From 01b4b3b8cdfcce30d2b0e3feaff49595d8a33314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:10:45 +0200 Subject: [PATCH 23/25] chore: split tests into multiple --- tests/testthat/test-shinytest2-tm_a_pca.R | 89 ++++++++++++++++++++++- 1 file changed, 85 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index 5bc15fee9..073e8ae28 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -21,12 +21,45 @@ app_driver_tm_a_pca <- function() { selected = c("Murder", "Assault"), multiple = TRUE ) - ) + ), + size = c(3, 1, 5), + alpha = c(.5, 0, 1), + font_size = c(10, 8, 15), + ggtheme = "light", + rotate_xaxis_labels = TRUE, + pre_output = shiny::tags$div(id = "unique_id_pre", "A pre output"), + post_output = shiny::tags$div(id = "unique_id_post", "A post output") ) ) } -testthat::test_that("e2e - tm_a_pca: Data selection (data_extract) changes eigenvector table", { +testthat::test_that("e2e - tm_a_pca: module is initialised with the specified defaults in function call", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_a_pca() + + app_driver$expect_no_shiny_error() + + testthat::expect_setequal( + app_driver$get_active_module_input("dat-dataset_USArrests_singleextract-select"), + c("Murder", "Assault") + ) + + module_parent_id <- gsub("-module$", "", app_driver$active_module_ns()) + testthat::expect_equal(app_driver$get_text(sprintf("#%s %s", module_parent_id, "#unique_id_pre")), "A pre output") + testthat::expect_equal(app_driver$get_text(sprintf("#%s %s", module_parent_id, "#unique_id_post")), "A post output") + + # Plot options that can be changed in call + testthat::expect_equal(app_driver$get_active_module_input("rotate_xaxis_labels")) + testthat::expect_equal(app_driver$get_active_module_input("ggtheme"), "light") + testthat::expect_equal(app_driver$get_active_module_input("font_size"), 10) + + app_driver$stop() +}) + +# Data extract ---------------------------------------------------------------- + +testthat::test_that("e2e - tm_a_pca: Eigenvector table should have data extract selection Murder/Assault on header", { skip_if_too_deep(5) app_driver <- app_driver_tm_a_pca() @@ -36,11 +69,12 @@ testthat::test_that("e2e - tm_a_pca: Data selection (data_extract) changes eigen app_driver$expect_no_validation_error() testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "Assault") + testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "Murder") testthat::expect_no_match(app_driver$get_active_module_output("tbl_eigenvector"), "UrbanPop") }) -testthat::test_that("e2e - tm_a_pca: Original coordinates (data_extract) changes output of plot", { +testthat::test_that("e2e - tm_a_pca: Eigenvector table should have data extract selection Murder/UrbanPop on header", { skip_if_too_deep(5) app_driver <- app_driver_tm_a_pca() @@ -51,6 +85,8 @@ testthat::test_that("e2e - tm_a_pca: Original coordinates (data_extract) changes app_driver$expect_no_validation_error() testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "UrbanPop") + testthat::expect_match(app_driver$get_active_module_output("tbl_eigenvector"), "Murder") + testthat::expect_no_match(app_driver$get_active_module_output("tbl_eigenvector"), "Assault") }) testthat::test_that("e2e - tm_a_pca: Color by columns (data_extract) must be from non-selected variable set", { @@ -70,21 +106,31 @@ testthat::test_that("e2e - tm_a_pca: Color by columns (data_extract) must be fro app_driver$stop() }) -testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate errors", { +# Encodings ------------------------------------------------------------------- + +testthat::test_that("e2e - tm_a_pca: Changing output encodings of tables_display does not generate errors", { skip_if_too_deep(5) app_driver <- app_driver_tm_a_pca() + app_driver$expect_no_validation_error() # Display section (hides tables) app_driver$set_active_module_input("tables_display", c()) app_driver$expect_no_validation_error() + # Tables are removed from DOM (output should generate a silent error empty message) testthat::expect_type(app_driver$get_active_module_output("tbl_importance"), "list") testthat::expect_setequal(names(app_driver$get_active_module_output("tbl_importance")), c("message", "call", "type")) testthat::expect_type(app_driver$get_active_module_output("tbl_eigenvector"), "list") testthat::expect_setequal(names(app_driver$get_active_module_output("tbl_eigenvector")), c("message", "call", "type")) +}) + +testthat::test_that("e2e - tm_a_pca: Changing output encodings for 'plot type' does not generate errors", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_a_pca() # Plot type (select each) @@ -100,6 +146,13 @@ testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate app_driver$set_active_module_input("plot_type", "Elbow plot") # Initial value app_driver$expect_no_validation_error() +}) + +testthat::test_that("e2e - tm_a_pca: Changing output encodings of 'standardization' does not generate errors", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_a_pca() + app_driver$expect_no_validation_error() # Pre-processing @@ -109,11 +162,25 @@ testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate app_driver$expect_no_validation_error app_driver$set_active_module_input("standardization", "none") # Initial value app_driver$expect_no_validation_error +}) + +testthat::test_that("e2e - tm_a_pca: Changing output encodings of 'NA action' does not generate errors", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_a_pca() + app_driver$expect_no_validation_error() # NA Action app_driver$set_active_module_input("na_action", "drop") app_driver$set_active_module_input("na_action", "none") +}) + +testthat::test_that("e2e - tm_a_pca: Changing output encodings of 'plot_type' hides and shows options", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_a_pca() + app_driver$expect_no_validation_error() # Selected plot's specific settings is not visible no_plot_settings_selector <- sprintf("#%s-%s %s", app_driver$active_module_ns(), "plot_settings", "span.help-block") @@ -137,6 +204,13 @@ testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate testthat::expect_false(app_driver$is_visible(no_plot_settings_selector)) testthat::expect_true(app_driver$is_visible(x_axis_selector)) testthat::expect_true(app_driver$is_visible(color_by_selector)) +}) + +testthat::test_that("e2e - tm_a_pca: Changing output encodings of 'theme' does not generate errors", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_a_pca() + app_driver$expect_no_validation_error() # Theme @@ -146,6 +220,13 @@ testthat::test_that("e2e - tm_a_pca: Changing output encodings does not generate app_driver$expect_no_validation_error() app_driver$set_active_module_input("ggtheme-selectized", "dark") app_driver$expect_no_validation_error() +}) + +testthat::test_that("e2e - tm_a_pca: Changing output encodings of 'font size' does not generate errors", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_a_pca() + app_driver$expect_no_validation_error() # Font size From f25df6e42629bd6ed93f4c023182af2bb402ae51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:12:56 +0200 Subject: [PATCH 24/25] docs: adds a simple comment --- tests/testthat/test-shinytest2-tm_a_pca.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index 073e8ae28..509a137e3 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -33,6 +33,8 @@ app_driver_tm_a_pca <- function() { ) } +# Defaults -------------------------------------------------------------------- + testthat::test_that("e2e - tm_a_pca: module is initialised with the specified defaults in function call", { skip_if_too_deep(5) From 1428f582c5f1a01d0b32dd841c98636801d88842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:50:16 +0200 Subject: [PATCH 25/25] fix: wrong expectation --- tests/testthat/test-shinytest2-tm_a_pca.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-shinytest2-tm_a_pca.R b/tests/testthat/test-shinytest2-tm_a_pca.R index 509a137e3..8752a0ca9 100644 --- a/tests/testthat/test-shinytest2-tm_a_pca.R +++ b/tests/testthat/test-shinytest2-tm_a_pca.R @@ -52,7 +52,7 @@ testthat::test_that("e2e - tm_a_pca: module is initialised with the specified de testthat::expect_equal(app_driver$get_text(sprintf("#%s %s", module_parent_id, "#unique_id_post")), "A post output") # Plot options that can be changed in call - testthat::expect_equal(app_driver$get_active_module_input("rotate_xaxis_labels")) + testthat::expect_true(app_driver$get_active_module_input("rotate_xaxis_labels")) testthat::expect_equal(app_driver$get_active_module_input("ggtheme"), "light") testthat::expect_equal(app_driver$get_active_module_input("font_size"), 10)