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_g_response #725

Merged
merged 21 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
73dd132
feat: add shinytest2 tests for `tm_g_response`
vedhav Apr 12, 2024
2664945
chore: add pkg prefix
vedhav Apr 12, 2024
a3a290e
chore: move `facet_ggplot_call` to utils
vedhav Apr 15, 2024
f2338df
feat: add a test to check encoding inputs
vedhav Apr 15, 2024
f3c104c
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Apr 15, 2024
a536a81
fix: remove debug browser statement
vedhav Apr 15, 2024
06f15e0
docs: remove unused doc
vedhav Apr 15, 2024
20b08c0
fix: linter errors
averissimo Apr 15, 2024
cdbc5f9
Merge branch 'main' into 712-tm_g_response@main
averissimo Apr 17, 2024
991507e
Apply suggestions from @m7pr on `set_active_module_input` rename
averissimo Apr 17, 2024
3a92d00
chore: revert prefix of ggplot2
averissimo Apr 17, 2024
81f1ed5
fix: replace TealAppDriver with init_teal_app_driver
averissimo Apr 17, 2024
7bdfb93
Merge branch 'main' into 712-tm_g_response@main
averissimo Apr 19, 2024
d8ad990
feat: adds tests where deselected variables produce errors
averissimo Apr 19, 2024
db7834f
fix: revert response choices selected change
averissimo Apr 19, 2024
3cee41e
Merge branch 'main' into 712-tm_g_response@main
averissimo Apr 19, 2024
2e9ab61
Merge branch 'main' into 712-tm_g_response@main
averissimo Apr 19, 2024
0f0927c
Merge branch 'main' into 712-tm_g_response@main
m7pr Apr 19, 2024
b59c6d0
trigger ci
vedhav Apr 22, 2024
714c1fb
Merge branch 'main' into 712-tm_g_response@main
vedhav Apr 22, 2024
834ab45
Merge branch 'main' into 712-tm_g_response@main
vedhav Apr 22, 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
9 changes: 7 additions & 2 deletions R/tm_g_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,12 @@ srv_g_response <- function(id,
)
)

if (!freq) plot_call <- substitute(plot_call + expand_limits(y = c(0, 1.1)), env = list(plot_call = plot_call))
if (!freq) {
plot_call <- substitute(
plot_call + expand_limits(y = c(0, 1.1)),
env = list(plot_call = plot_call)
)
}

if (counts) {
plot_call <- substitute(
Expand All @@ -479,7 +484,7 @@ srv_g_response <- function(id,
resp_cl = resp_cl,
hjust_value = if (swap_axes) "left" else "middle",
vjust_value = if (swap_axes) "middle" else -1,
position_anl2_value = if (!freq) quote(position_fill(0.5)) else quote(position_stack(0.5)),
position_anl2_value = if (!freq) quote(position_fill(0.5)) else quote(position_stack(0.5)), # nolint: line_length.
anl3_y = if (!freq) 1.1 else as.name("ns"),
position_anl3_value = if (!freq) "fill" else "stack"
)
Expand Down
110 changes: 110 additions & 0 deletions tests/testthat/test-shinytest2-tm_g_response.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
app_driver_tm_g_response <- function() {
data <- teal.data::teal_data()
data <- within(data, {
require(nestcolor)
ADSL <- rADSL
})
teal.data::datanames(data) <- c("ADSL")
teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[teal.data::datanames(data)]

init_teal_app_driver(
data = data,
modules = teal::modules(
tm_g_response(
label = "Response Plots",
response = teal.transform::data_extract_spec(
dataname = "ADSL",
select = teal.transform::select_spec(
label = "Select variable:",
choices = teal.transform::variable_choices(data[["ADSL"]], c("BMRKR2", "COUNTRY")),
selected = "BMRKR2",
multiple = FALSE,
fixed = FALSE
)
),
x = teal.transform::data_extract_spec(
dataname = "ADSL",
select = teal.transform::select_spec(
label = "Select variable:",
choices = teal.transform::variable_choices(data[["ADSL"]], c("SEX", "RACE")),
selected = "RACE",
multiple = FALSE,
fixed = FALSE
)
),
ggplot2_args = teal.widgets::ggplot2_args(
labs = list(subtitle = "Plot generated by Response Module")
)
)
)
)
}

testthat::test_that("e2e - tm_g_response: module is initialised with the specified defaults", {
skip_if_too_deep(5)

app_driver <- app_driver_tm_g_response()

app_driver$expect_no_shiny_error()

testthat::expect_equal(app_driver$get_active_module_input("response-dataset_ADSL_singleextract-select"), "BMRKR2")
testthat::expect_equal(app_driver$get_active_module_input("x-dataset_ADSL_singleextract-select"), "RACE")
testthat::expect_equal(app_driver$get_active_module_input("freq"), "density")
testthat::expect_true(app_driver$get_active_module_input("count_labels"))
testthat::expect_false(app_driver$get_active_module_input("coord_flip"))
testthat::expect_false(app_driver$get_active_module_input("rotate_xaxis_labels"))
testthat::expect_equal(app_driver$get_active_module_input("ggtheme"), "gray")

app_driver$stop()
})
testthat::test_that("e2e - tm_g_response: encoding inputs produce output without validation errors", {
skip_if_too_deep(5)

app_driver <- app_driver_tm_g_response()

app_driver$set_active_module_input("response-dataset_ADSL_singleextract-select", "COUNTRY")
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("x-dataset_ADSL_singleextract-select", "SEX")
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("freq", "frequency")
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("count_labels", FALSE)
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("coord_flip", TRUE)
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("rotate_xaxis_labels", TRUE)
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("ggtheme", "light")

app_driver$expect_no_validation_error()

app_driver$stop()
})

testthat::test_that("e2e - tm_g_response: deselecting response produces validation error", {
skip_if_too_deep(5)

app_driver <- app_driver_tm_g_response()

app_driver$set_active_module_input("response-dataset_ADSL_singleextract-select", c())
app_driver$expect_validation_error()

app_driver$stop()
})

testthat::test_that("e2e - tm_g_response: deselecting x produces validation error", {
skip_if_too_deep(5)

app_driver <- app_driver_tm_g_response()

app_driver$set_active_module_input("x-dataset_ADSL_singleextract-select", c())
app_driver$expect_validation_error()

app_driver$stop()
})
vedhav marked this conversation as resolved.
Show resolved Hide resolved
Loading