Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

712 - {shinytest2} for tm_a_regression #718

Merged
merged 43 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8b008e7
setup skeleton for the test
m7pr Apr 11, 2024
b85a959
missing prefixes
m7pr Apr 11, 2024
1c63108
few tests for encoding panel
m7pr Apr 11, 2024
15b3d81
few tests for buttons above the plot
m7pr Apr 11, 2024
6bcb4d8
play with regressor-dataset_CO2_singleextract-select
m7pr Apr 11, 2024
7e01ecc
[skip style] [skip vbump] Restyle files
github-actions[bot] Apr 11, 2024
fff0bc6
remove things tests in teal.widgets
m7pr Apr 12, 2024
7507b4f
create app_driver_tm_a_regression function
m7pr Apr 12, 2024
f92142c
move teal_data creation to app_driver_tm_a_regression
m7pr Apr 12, 2024
aaede01
[skip style] [skip vbump] Restyle files
github-actions[bot] Apr 12, 2024
906cc6c
cleanup test
m7pr Apr 12, 2024
8606261
Update tests/testthat/helper-TealAppDriver.R
m7pr Apr 12, 2024
b8dc52d
Update tests/testthat/test-shinytest2-tm_a_regression.R
m7pr Apr 12, 2024
443194d
Merge branch '712-tm_a_regression@main' of https://github.com/insight…
m7pr Apr 12, 2024
0755b8a
remove require shinytest2
m7pr Apr 12, 2024
333f746
prefix ggplot
m7pr Apr 12, 2024
b1bfa61
prefix aes
m7pr Apr 12, 2024
f3fe358
prefix stat_qq
m7pr Apr 12, 2024
65c97f7
put name of the test
m7pr Apr 12, 2024
6ed591b
Update tests/testthat/test-shinytest2-tm_a_regression.R
m7pr Apr 12, 2024
c420f7e
gogonzo suggestions - divide tests into smaller tests
m7pr Apr 15, 2024
41ce6b0
[skip style] [skip vbump] Restyle files
github-actions[bot] Apr 15, 2024
f6f01db
extend tests by more default values checking
m7pr Apr 15, 2024
3f07bfe
check if values can be set
m7pr Apr 15, 2024
5b5bd20
Merge branch '712-tm_a_regression@main' of https://github.com/insight…
m7pr Apr 15, 2024
f6712f9
move out ggplot2_args test to teal.widgets
m7pr Apr 16, 2024
0ac7488
rename active_module_input to set_active_module_input
m7pr Apr 16, 2024
ecd37a5
9 -> 9L
m7pr Apr 16, 2024
9d6c425
divide initial test
m7pr Apr 16, 2024
17f0f00
rename app to app_driver
m7pr Apr 16, 2024
855673b
Merge branch 'main' into 712-tm_a_regression@main
averissimo Apr 17, 2024
2bb17e7
chore: revert ggplot2 prefixes
averissimo Apr 17, 2024
25a0ec9
fix: replace TealAppDriver with init_teal_app_driver
averissimo Apr 17, 2024
70cc24d
@kartikeyakirar suggestions from tm_g_asscioation PR
m7pr Apr 18, 2024
21ca5d8
Update tests/testthat/test-shinytest2-tm_a_regression.R
m7pr Apr 18, 2024
90e8cce
Merge branch 'main' into 712-tm_a_regression@main
m7pr Apr 18, 2024
1f818e2
typos lol
m7pr Apr 18, 2024
da785b9
Merge branch '712-tm_a_regression@main' of https://github.com/insight…
m7pr Apr 18, 2024
024ef4f
Merge branch 'main' into 712-tm_a_regression@main
m7pr Apr 18, 2024
7d73139
remove duplicated argument
m7pr Apr 18, 2024
608fb71
Merge branch '712-tm_a_regression@main' of https://github.com/insight…
m7pr Apr 18, 2024
1abd428
Merge branch 'main' into 712-tm_a_regression@main
m7pr Apr 19, 2024
76558fd
Merge branch 'main' into 712-tm_a_regression@main
m7pr Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/tm_a_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ srv_a_regression <- function(id,
selected = restoreInput(ns("label_var"), selected)
)

data <- fortify(stats::lm(form, data = ANL))
data <- ggplot2::fortify(stats::lm(form, data = ANL))
cooksd <- data$.cooksd[!is.nan(data$.cooksd)]
max_outlier <- max(ceiling(max(cooksd) / mean(cooksd)), 2)
cur_outlier <- isolate(input$outlier)
Expand Down Expand Up @@ -615,7 +615,7 @@ srv_a_regression <- function(id,
substitute(
expr = {
class(fit$residuals) <- NULL
data <- fortify(fit)
data <- ggplot2::fortify(fit)
g <- plot
print(g)
},
Expand Down
136 changes: 136 additions & 0 deletions tests/testthat/test-shinytest2-tm_a_regression.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
testthat::test_that("e2e - tm_a_regerssion: ", {
m7pr marked this conversation as resolved.
Show resolved Hide resolved
skip_if_too_deep(5)

# needed untill this is merged https://github.com/insightsengineering/teal/pull/1198
require(shinytest2)

m7pr marked this conversation as resolved.
Show resolved Hide resolved
data <- within(teal.data::teal_data(), {
require(nestcolor)
require(ggplot2)
CO2 <- CO2 # nolint: object_name.
})
datanames(data) <- c("CO2")

app <- TealAppDriver$new(
data = data,
modules = tm_a_regression(
label = "Regression",
default_plot_type = 3,
response = teal.transform::data_extract_spec(
dataname = "CO2",
select = teal.transform::select_spec(
label = "Select variable:",
choices = "uptake",
selected = "uptake",
multiple = FALSE,
fixed = TRUE
)
),
regressor = teal.transform::data_extract_spec(
dataname = "CO2",
select = teal.transform::select_spec(
label = "Select variables:",
choices = teal.transform::variable_choices(data[["CO2"]], c("conc", "Treatment")),
selected = "conc",
multiple = TRUE,
fixed = FALSE
)
),
ggplot2_args = teal.widgets::ggplot2_args(
labs = list(subtitle = "Plot generated by Regression Module")
)
)
)

app$expect_no_shiny_error()
#app$open_url()

testthat::expect_equal(
app$get_text("#teal-main_ui-root-active_tab > li.active > a"),
"Regression"
)

# Check MAIN encoding panel
# DO WE NEED any function for checking top of the encoding panel part?
encoding_dataset <- app$get_text("#teal-main_ui-root-regression > div > div.col-md-3 > div.well > div > span")
testthat::expect_match(encoding_dataset, 'Dataset', fixed = TRUE)
testthat::expect_match(encoding_dataset, 'CO2', fixed = TRUE)

# Check plot settings
testthat::expect_identical(
app$get_active_module_input("plot_type"),
"Normal Q-Q"
)

plot_types <- app$active_module_element_text("plot_type > div")
testthat::expect_match(plot_types, 'Response vs Regressor', fixed = TRUE)
testthat::expect_match(plot_types, 'Scale-Location', fixed = TRUE)
testthat::expect_match(plot_types, 'Residuals vs Leverage', fixed = TRUE)

app$set_module_input("plot_type", "Residuals vs Fitted")
app$expect_no_validation_error()
app$set_module_input("plot_type", "Normal Q-Q")
app$expect_no_validation_error()

# NO OUTLIER DEFINITION
app$set_module_input("show_outlier", FALSE)
testthat::expect_false(app$is_visible(app$active_module_element("outlier-label")))

# BRING BACK OUTLIER DEFINITION
app$set_module_input("show_outlier", TRUE)
testthat::expect_true(app$is_visible(app$active_module_element("outlier-label")))


# Plot settings are not visible
testthat::expect_false(app$is_visible(app$active_module_element("size-label")))
# After click they are visible
app$click("#_div > div.panel-heading.collapsed")
m7pr marked this conversation as resolved.
Show resolved Hide resolved
testthat::expect_true(app$is_visible(app$active_module_element("outlier-label")))
m7pr marked this conversation as resolved.
Show resolved Hide resolved
app$set_module_input("size-label", 3)
app$expect_no_validation_error()


# QUESTION - SHOULD BELOW THIS BE CHECKED HERE OR IN teal.widgets::plot_with_settings ? ? ?
# Module buttons

# Check if there are three buttons above the table.

plot_buttons_selector <- app$active_module_element("myplot-plot-with-settings > div.plot-settings-buttons")
plot_buttons <-
app$get_html_rvest(plot_buttons_selector) %>%
rvest::html_elements("button")
testthat::expect_length(plot_buttons, 3)
# Check is the first one is a toggle button.
testthat::expect_equal(
plot_buttons[[1]] %>%
rvest::html_attr("data-toggle"),
"dropdown"
)

# First button has specific font-awesome icon.
dwnl_button <- app$active_module_element("myplot-downbutton-downl")
testthat::expect_equal(
app$get_html_rvest(dwnl_button) %>%
rvest::html_element("i") %>%
rvest::html_attr("class"),
"fas fa-download"
)
# Click the first button.
app$click(selector = dwnl_button)

# Review the content of the toggle.
testthat::expect_equal(
#app$get_text(
app$active_module_element_text("myplot-downbutton-file_format-label"),
"File type"
)

file_format_text <- app$active_module_element_text("myplot-downbutton-file_format > div")
testthat::expect_match(file_format_text, "png\n", fixed = TRUE)
testthat::expect_match(file_format_text, "svg\n", fixed = TRUE)
testthat::expect_match(file_format_text, "pdf\n", fixed = TRUE)
m7pr marked this conversation as resolved.
Show resolved Hide resolved


app$stop()

})