-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of #712 --------- Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
- Loading branch information
1 parent
d8eaa97
commit ff4dfbc
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) |