Skip to content

Commit

Permalink
shiny::testServer tests for srv_teal_transform
Browse files Browse the repository at this point in the history
  • Loading branch information
m7pr committed Nov 18, 2024
1 parent 5d09fcf commit afbe5be
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions tests/testthat/test-module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -1948,34 +1948,39 @@ testthat::describe("srv_teal teal_module(s) transformator", {
})

testthat::it("changes module output for a module with a static decorator", {
testthat::skip("TODO")
label <- "output_decorator"
output_decorator <- teal_transform_module(
label = label,
server = make_teal_transform_server(
expression(
object <- rev(object)
data1 <- rev(data1)
)
)
)

shiny::testServer(
app = srv_teal,
app = srv_teal_transform_data,
args = list(
id = "test",
data = teal.data::teal_data(iris = iris, mtcars = mtcars),
modules = modules(example_module("module 1", decorators = output_decorator))
data = reactive(teal.data::teal_data(data1 = iris, data2 = mtcars)),
transformators = output_decorator
),
expr = {
# session$setInputs(`teal_modules-active_tab` = "module 1")
# testthat::expect_identical(modules_output$module_1()()[["object"]], TODO)
data_out <- transformators[[label]]$server(label, data = data)
testthat::expect_identical(
data_out()[['data1']],

Check warning on line 1971 in tests/testthat/test-module_teal.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-module_teal.R,line=1971,col=23,[quotes_linter] Only use double-quotes.
rev(iris)
)
}
)
})


testthat::it("changes module output for a module with a decorator that is a function of object name", {
testthat::skip("TODO")
output_decorator <- function(output_name) {
testthat::it("changes module output for a module with a decorator that is a function of an object name", {
label <- "output_decorator_name"
output_decorator_name <- function(output_name, label) {
teal_transform_module(
label = label,
ui = function(id) {
ns <- NS(id)
div(
Expand All @@ -2000,21 +2005,27 @@ testthat::describe("srv_teal teal_module(s) transformator", {
}

shiny::testServer(
app = srv_teal,
app = srv_teal_transform_data,
args = list(
id = "test",
data = teal.data::teal_data(iris = iris, mtcars = mtcars),
modules = modules(example_module("module 1", decorators = output_decorator[["object"]]))
data = reactive(teal.data::teal_data(x1 = "ABC")),
transformators = output_decorator_name(output_name = "x1", label = label)
),
expr = {
# TODO
data_out <- transformators[[label]]$server(label, data = data)
testthat::expect_identical(
data_out()[['x1']],

Check warning on line 2017 in tests/testthat/test-module_teal.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-module_teal.R,line=2017,col=23,[quotes_linter] Only use double-quotes.
paste0("ABC", "random text") # "random text" is not appended
)
}
)
})

testthat::it("changes module output for a module with a interactive decorator", {
testthat::skip("TODO")
output_decorator <- teal_transform_module(
testthat::it("changes module output for a module with an interactive decorator", {

label = "output_decorator_int"

Check warning on line 2026 in tests/testthat/test-module_teal.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-module_teal.R,line=2026,col=11,[assignment_linter] Use <-, not =, for assignment.
output_decorator_int <- teal_transform_module(
label = label,
ui = function(id) {
ns <- NS(id)
div(
Expand All @@ -2027,7 +2038,7 @@ testthat::describe("srv_teal teal_module(s) transformator", {
req(data())
within(data(),
{
object <- paste0(object, append_text)
x1 <- paste0(x1, append_text)
},
append_text = input$append_text
)
Expand All @@ -2037,14 +2048,18 @@ testthat::describe("srv_teal teal_module(s) transformator", {
)

shiny::testServer(
app = srv_teal,
app = srv_teal_transform_data,
args = list(
id = "test",
data = teal.data::teal_data(iris = iris, mtcars = mtcars),
modules = modules(example_module("module 1", decorators = output_decorator))
data = reactive(teal.data::teal_data(x1 = "ABC")),
transformators = output_decorator_int
),
expr = {
# TODO
data_out <- transformators[[label]]$server(label, data = data)
testthat::expect_identical(
data_out()[['x1']],

Check warning on line 2060 in tests/testthat/test-module_teal.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-module_teal.R,line=2060,col=23,[quotes_linter] Only use double-quotes.
paste0("ABC", "random text") # "random text" is not appended
)
}
)
})
Expand Down

0 comments on commit afbe5be

Please sign in to comment.