Skip to content

Commit

Permalink
tests: improve tests coverage by adding .raw_data and multiple reserv…
Browse files Browse the repository at this point in the history
…ed datanames
  • Loading branch information
averissimo committed Nov 15, 2024
1 parent 60c2bad commit 95593c0
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions tests/testthat/test-module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -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(
Expand Down

0 comments on commit 95593c0

Please sign in to comment.