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_missing_data #727

Merged
merged 39 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
010885f
adding prefix
kartikeyakirar Apr 12, 2024
560f72e
adding app_driver fun
kartikeyakirar Apr 12, 2024
9818f5a
adding shinytest2
kartikeyakirar Apr 12, 2024
95e2dbb
adding tests
kartikeyakirar Apr 12, 2024
90357fd
adding driver to shinytest2 file.
kartikeyakirar Apr 15, 2024
5e9ead6
fixing selector
kartikeyakirar Apr 15, 2024
d60eebb
[skip style] [skip vbump] Restyle files
github-actions[bot] Apr 15, 2024
af97be0
fixing styling
kartikeyakirar Apr 15, 2024
f2adb4f
Update tests/testthat/test-shinytest2-tm_misssing_data.R
kartikeyakirar Apr 16, 2024
7a3ed09
Update tests/testthat/test-shinytest2-tm_misssing_data.R
kartikeyakirar Apr 16, 2024
3b02f1e
Update tests/testthat/test-shinytest2-tm_misssing_data.R
kartikeyakirar Apr 16, 2024
4b6e65c
Update tests/testthat/test-shinytest2-tm_misssing_data.R
kartikeyakirar Apr 16, 2024
df51d9a
Update tests/testthat/test-shinytest2-tm_misssing_data.R
kartikeyakirar Apr 16, 2024
ab710b9
Merge branch 'main' into 712-tm_missing-data@main
kartikeyakirar Apr 17, 2024
54aa417
chore: revert prefix of ggplot2
averissimo Apr 17, 2024
a218c0a
fix: replace TealAppDriver with init_teal_app_driver
averissimo Apr 17, 2024
5d667af
updating descripiton and added new test
kartikeyakirar Apr 17, 2024
57df1fb
Merge branch '712-tm_missing-data@main' of https://github.com/insight…
kartikeyakirar Apr 17, 2024
3ba71b9
styler fix
kartikeyakirar Apr 17, 2024
e4705de
Update tests/testthat/test-shinytest2-tm_misssing_data.R
kartikeyakirar Apr 18, 2024
8bc4332
Update tests/testthat/test-shinytest2-tm_misssing_data.R
kartikeyakirar Apr 18, 2024
49edc1b
Update tests/testthat/test-shinytest2-tm_misssing_data.R
kartikeyakirar Apr 18, 2024
3b3660f
Update tests/testthat/test-shinytest2-tm_misssing_data.R
kartikeyakirar Apr 18, 2024
8adbf29
Update tests/testthat/test-shinytest2-tm_misssing_data.R
kartikeyakirar Apr 18, 2024
f074403
Update tests/testthat/test-shinytest2-tm_misssing_data.R
kartikeyakirar Apr 18, 2024
71df4aa
[skip style] [skip vbump] Restyle files
github-actions[bot] Apr 18, 2024
7910a25
removing wait_for_idle
kartikeyakirar Apr 18, 2024
326c445
Merge branch '712-tm_missing-data@main' of https://github.com/insight…
kartikeyakirar Apr 18, 2024
eef811c
removing plot_with_setting checks
kartikeyakirar Apr 18, 2024
456e33f
Merge branch 'main' into 712-tm_missing-data@main
kartikeyakirar Apr 18, 2024
d56de15
Merge branch 'main' into 712-tm_missing-data@main
m7pr Apr 19, 2024
63b4788
add a test for combination-encoding
m7pr Apr 19, 2024
cdc4039
add test for table display
m7pr Apr 19, 2024
7db8d3d
fix combination_cutoff value
m7pr Apr 19, 2024
4193e0d
fix values for table content test
m7pr Apr 19, 2024
d7fd600
Merge branch 'main' into 712-tm_missing-data@main
kartikeyakirar Apr 19, 2024
73dfc0c
fxing tests
kartikeyakirar Apr 19, 2024
8f781aa
Merge branch '712-tm_missing-data@main' of https://github.com/insight…
kartikeyakirar Apr 19, 2024
6b7b203
Merge branch 'main' into 712-tm_missing-data@main
kartikeyakirar 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
18 changes: 15 additions & 3 deletions R/tm_missing_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,11 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
values = c("grey90", c(getOption("ggplot2.discrete.colour")[2], "#ff2951ff")[1]),
labels = c("Present", "Missing")
) +
scale_y_continuous(labels = scales::percent_format(), breaks = seq(0, 1, by = 0.1), expand = c(0, 0)) +
scale_y_continuous(
labels = scales::percent_format(),
breaks = seq(0, 1, by = 0.1),
expand = c(0, 0)
) +
geom_text(
aes(label = ifelse(isna == TRUE, sprintf("%d [%.02f%%]", n, n_pct), ""), y = 1),
hjust = 1,
Expand Down Expand Up @@ -803,7 +807,11 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
fill = ~isna
) +
geom_bar(alpha = 1, stat = "identity", position = "fill") +
scale_y_continuous(labels = scales::percent_format(), breaks = seq(0, 1, by = 0.1), expand = c(0, 0)) +
scale_y_continuous(
labels = scales::percent_format(),
breaks = seq(0, 1, by = 0.1),
expand = c(0, 0)
) +
scale_fill_manual(
name = "",
values = c("grey90", c(getOption("ggplot2.discrete.colour")[2], "#ff2951ff")[1]),
Expand Down Expand Up @@ -972,7 +980,11 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
dplyr::distinct() %>%
ggplot(aes(x = id, y = n)) +
geom_bar(stat = "identity", fill = c(getOption("ggplot2.discrete.colour")[2], "#ff2951ff")[1]) +
geom_text(aes(label = n), position = position_dodge(width = 0.9), vjust = -0.25) +
geom_text(
aes(label = n),
position = position_dodge(width = 0.9),
vjust = -0.25
) +
ylim(c(0, max(data_combination_plot_cutoff$n) * 1.5)) +
labs1 +
ggthemes1 +
Expand Down
165 changes: 165 additions & 0 deletions tests/testthat/test-shinytest2-tm_misssing_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
app_driver_tm_missing_data <- function() {
data <- within(simple_teal_data(), {
require(nestcolor)

add_nas <- function(x) {
x[sample(seq_along(x), floor(length(x) * runif(1, .05, .17)))] <- NA
x
}

iris[] <- lapply(iris, add_nas)
mtcars[] <- lapply(mtcars, add_nas)
mtcars[["cyl"]] <- as.factor(mtcars[["cyl"]])
mtcars[["gear"]] <- as.factor(mtcars[["gear"]])
})

init_teal_app_driver(
data = data,
modules = tm_missing_data(
label = "Missing data",
plot_height = c(600, 400, 5000),
plot_width = NULL,
parent_dataname = "",
ggtheme = "gray",
ggplot2_args = list(
"Combinations Hist" = teal.widgets::ggplot2_args(
labs = list(subtitle = "Plot produced by Missing Data Module", caption = NULL)
),
"Combinations Main" = teal.widgets::ggplot2_args(labs = list(title = NULL))
),
pre_output = NULL,
post_output = NULL
),
timeout = 3000,
seed = 1
)
}

test_that("e2e - tm_missing_data: Initializes without errors", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_missing_data()

app_driver$expect_no_shiny_error()

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

encoding_dataset <- app_driver$get_text(
app_driver$active_module_element("dataset_encodings .help-block")
)

testthat::expect_match(encoding_dataset, "Datasets.*iris.*mtcars", all = FALSE)


app_driver$stop()
})

test_that("e2e - tm_missing_data: Default settings and visibility of the summary graph", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_missing_data()
# default summary tab
testthat::expect_equal(
app_driver$get_active_module_input("iris-summary_type"),
"Summary"
)

testthat::expect_setequal(
app_driver$get_active_module_input("iris-variables_select"),
c("Petal.Length", "Sepal.Length", "Petal.Width", "Species", "Sepal.Width")
)

app_driver$click(selector = app_driver$active_module_element("iris-filter_na"))
app_driver$expect_no_validation_error()

app_driver$click(selector = app_driver$active_module_element("iris-any_na"))
app_driver$expect_no_validation_error()

testthat::expect_true(
app_driver$is_visible(
app_driver$active_module_element("iris-summary_plot-plot_out_main")
)
)

app_driver$stop()
})

test_that("e2e - tm_missing_data: Check default settings and visibility of the combinations graph and encodings", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_missing_data()

app_driver$expect_no_shiny_error()

# combination graph

app_driver$set_active_module_input("iris-summary_type", "Combinations")
app_driver$expect_no_validation_error()
testthat::expect_true(
app_driver$is_visible(
app_driver$active_module_element("iris-combination_plot-plot_out_main")
)
)

# combination encoding

testthat::expect_true(
app_driver$is_visible(
app_driver$active_module_element("iris-cutoff")
)
)

testthat::expect_equal(app_driver$get_active_module_input("iris-combination_cutoff"), 2L)
app_driver$set_active_module_input("iris-combination_cutoff", 10L)
app_driver$expect_no_validation_error()

app_driver$stop()
})

test_that("e2e - tm_missing_data: Validate functionality and UI response for 'By Variable Levels'", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_missing_data()
# By variable levels
app_driver$set_active_module_input("iris-summary_type", "By Variable Levels")
app_driver$expect_no_validation_error()


testthat::expect_equal(
app_driver$get_active_module_input("iris-group_by_var"),
"Species"
)
testthat::expect_setequal(
app_driver$get_active_module_input("iris-group_by_vals"),
c("NA", "setosa", "versicolor", "virginica")
)

app_driver$set_active_module_input("iris-group_by_vals", c("versicolor", "virginica"))
app_driver$expect_no_validation_error()

testthat::expect_equal(
app_driver$get_active_module_input("iris-count_type"),
"counts"
)
app_driver$set_active_module_input("iris-count_type", "proportions")
testthat::expect_true(app_driver$is_visible(app_driver$active_module_element("iris-levels_table")))

app_driver$stop()
})

test_that("e2e - tm_missing_data: Validate 'By Variable Levels' table values", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_missing_data()

app_driver$set_active_module_input("iris-summary_type", "By Variable Levels")
levels_table <- app_driver$active_module_element("iris-levels_table") %>%
app_driver$get_html_rvest() %>%
rvest::html_table(fill = TRUE) %>%
.[[1]]

testthat::expect_setequal(
levels_table$Variable,
c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
)

app_driver$stop()
})
Loading