Skip to content

Commit

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

---------

Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
  • Loading branch information
kartikeyakirar and averissimo authored Apr 19, 2024
1 parent d8eaa97 commit ff4dfbc
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions tests/testthat/test-shinytest2-tm_file_viewer.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
app_driver_tm_file_viewer <- function() {
init_teal_app_driver(
data = simple_teal_data(),
modules = tm_file_viewer(
label = "File Viewer Module",
input_path = list(
folder = system.file("sample_files", package = "teal.modules.general"),
png = system.file("sample_files/sample_file.png", package = "teal.modules.general"),
txt = system.file("sample_files/sample_file.txt", package = "teal.modules.general"),
url = "https://fda.gov/files/drugs/published/Portable-Document-Format-Specifications.pdf"
)
),
timeout = 3000
)
}

test_that("e2e - tm_file_viewer: Initializes without errors and shows files tree specified in input_path argument", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_file_viewer()

app_driver$expect_no_shiny_error()
# check valid path as no file is selected
app_driver$expect_validation_error()
# encoding are visible
testthat::expect_true(app_driver$is_visible(selector = app_driver$active_module_element("tree")))
list_files <- app_driver$get_html_rvest(selector = app_driver$active_module_element("tree")) %>%
rvest::html_nodes("a") %>%
rvest::html_text()
testthat::expect_setequal(
list_files,
c("folder", "png", "txt", "url")
)

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

app_driver$stop()
})

test_that("e2e - tm_file_viewer: Shows selected image file", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_file_viewer()

app_driver$click(selector = "[id= '4_anchor']")
testthat::expect_true(app_driver$is_visible(selector = app_driver$active_module_element("output")))

img_src <- app_driver$get_html_rvest(app_driver$active_module_element("output")) %>%
rvest::html_element("img") %>%
rvest::html_attr("src")

testthat::expect_match(img_src, "png$")

app_driver$stop()
})

test_that("e2e - tm_file_viewer: Shows selected text file", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_file_viewer()

app_driver$click(selector = "[id= '5_anchor']")
testthat::expect_true(app_driver$is_visible(selector = app_driver$active_module_element("output")))

pre_text <- app_driver$get_html_rvest(app_driver$active_module_element("output")) %>%
rvest::html_element("pre") %>%
rvest::html_text()

testthat::expect_true(!is.na(pre_text))
testthat::expect_true(length(pre_text) > 0)

testthat::expect_match(
attr(app_driver$get_active_module_input("tree")$txt, "ancestry"),
"txt$"
)

app_driver$stop()
})

test_that("e2e - tm_file_viewer: Shows selected url", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_file_viewer()

app_driver$click(selector = "[id= '6_anchor']")
testthat::expect_true(app_driver$is_visible(selector = app_driver$active_module_element("output")))

testthat::expect_match(
attr(app_driver$get_active_module_input("tree")$url, "ancestry"),
"pdf$"
)

app_driver$stop()
})

0 comments on commit ff4dfbc

Please sign in to comment.