Skip to content

Commit

Permalink
712 - {shinytest2} for tm_data_table (#719)
Browse files Browse the repository at this point in the history
Part of
#712

~~- [ ]  testing table caption (DT functionality)~~
- [x] testing table
- [x] variable selected

---------

Signed-off-by: kartikeya kirar <kirar.kartikeya1@gmail.com>
Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com>
Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Co-authored-by: m7pr <marcin.kosinski.mk1@roche.com>
  • Loading branch information
6 people authored Apr 19, 2024
1 parent c904c4a commit 7857ad6
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/tm_data_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#' variables_selected = list(
#' iris = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species")
#' ),
#' dt_args = list(caption = "ADSL Table Caption")
#' dt_args = list(caption = "IRIS Table Caption")
#' )
#' )
#' )
Expand Down
2 changes: 1 addition & 1 deletion man/tm_data_table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 101 additions & 0 deletions tests/testthat/test-shinytest2-tm_data_table.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
app_driver_tm_data_table <- function() {
init_teal_app_driver(
data = simple_teal_data(),
modules = tm_data_table(
label = "Data Table",
variables_selected = list(
iris = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species")
),
datasets_selected = c("iris", "mtcars"),
dt_args = list(caption = "Table Caption"),
dt_options = list(
searching = FALSE, pageLength = 30, lengthMenu = c(5, 15, 30, 100),
scrollX = TRUE
),
server_rendering = FALSE,
pre_output = NULL,
post_output = NULL
),
timeout = 3000
)
}

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

app_driver$expect_no_shiny_error()

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

app_driver$stop()
})

test_that("e2e - tm_data_table: Verify checkbox displayed over data table", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_data_table()

testthat::expect_false(app_driver$get_active_module_input("if_distinct"))

app_driver$stop()
})

test_that("e2e - tm_data_table: Verify module displays data table", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_data_table()

# table
testthat::expect_match(app_driver$get_active_module_output("iris-data_table"), "Table Caption")
testthat::expect_true(app_driver$is_visible(selector = app_driver$active_module_element("iris-data_table")))

extract_iris_table <- function() {
app_driver$active_module_element("iris-data_table") %>%
app_driver$get_html_rvest() %>%
rvest::html_table(fill = TRUE) %>%
.[[2]] %>%
dplyr::select(-1) %>%
data.frame()
}
# Non-distinct version.
iris_extracted <- extract_iris_table()
iris_subset <- iris %>%
dplyr::mutate(Species = as.character(Species)) %>%
dplyr::slice(1:30)
testthat::expect_equal(iris_extracted, iris_subset)

# Distinct version.
app_driver$set_active_module_input("if_distinct", TRUE)
iris_extracted_distinct <- extract_iris_table()
iris_subset_distinct <- iris %>%
dplyr::mutate(n = 1) %>%
dplyr::arrange(dplyr::across(dplyr::everything())) %>%
dplyr::mutate(Species = as.character(Species)) %>%
dplyr::slice(1:30)
testthat::expect_equal(iris_extracted_distinct, iris_subset_distinct)

app_driver$stop()
})

test_that("e2e - tm_data_table: Verify default variable selection and set new selection", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_data_table()

# default variable selection
testthat::expect_equal(
app_driver$get_active_module_input("iris-variables"),
c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species")
)

# new variable selection
app_driver$set_active_module_input("iris-variables", c("Petal.Width", "Species"))
app_driver$expect_no_validation_error()
testthat::expect_equal(
app_driver$get_active_module_input("iris-variables"),
c("Petal.Width", "Species")
)

app_driver$stop()
})

0 comments on commit 7857ad6

Please sign in to comment.