From 95593c04d1fa0eab2ad878f383b0ccd23bcd59a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:01:34 +0100 Subject: [PATCH] tests: improve tests coverage by adding .raw_data and multiple reserved datanames --- tests/testthat/test-module_teal.R | 47 +++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-module_teal.R b/tests/testthat/test-module_teal.R index 1c8cd82379..c8a530d719 100644 --- a/tests/testthat/test-module_teal.R +++ b/tests/testthat/test-module_teal.R @@ -545,15 +545,54 @@ testthat::describe("srv_teal teal_modules", { ) }) + testthat::describe("reserved dataname is being used:", { + # Shared common code for tests + td <- within(teal.data::teal_data(), { + all <- mtcars + iris <- iris + }) - testthat::describe("warnings on missing datanames", { - testthat::it("warns when dataname is not available", { + testthat::it("multiple datanames with `all` and `.raw_data`", { + testthat::skip_if_not_installed("rvest") + + td_local <- within(td, { + .raw_data <- data.frame( + Species = c("Setosa", "Virginica", "Versicolor"), + New.Column = c("Setosas are cool", "Virginicas are also cool", "Versicolors are cool too") + ) + }) + teal.data::join_keys(td) <- teal.data::join_keys(join_key(".raw_data", "iris", "Species")) + + shiny::testServer( + app = srv_teal, + args = list( + id = "test", + data = td, + modules = modules(module("module_1", server = function(id, data) data)) + ), + expr = { + session$setInputs("teal_modules-active_tab" = "module_1") + testthat::expect_equal( + trimws( + rvest::html_text2( + rvest::read_html( + output[["teal_modules-module_1-validate_datanames-shiny_warnings-message"]]$html + ) + ) + ), + "all and .raw_data are reserved for internal use. Please avoid using them as dataset names." + ) + } + ) + }) + + testthat::it("single dataname with `all`", { testthat::skip_if_not_installed("rvest") shiny::testServer( app = srv_teal, args = list( id = "test", - data = teal_data(iris = iris, all = mtcars), + data = within(td, all$new.column <- 1), modules = modules( module("module_1", server = function(id, data) data) ) @@ -573,7 +612,9 @@ testthat::describe("srv_teal teal_modules", { } ) }) + }) + testthat::describe("warnings on missing datanames", { testthat::it("warns when dataname is not available", { testthat::skip_if_not_installed("rvest") shiny::testServer(