Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Oct 7, 2024
1 parent ca0e36f commit 38fa7e5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion R/summarize-expr-block.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ new_summarize_expr_block <- function(new_cols = NULL,
if (inherits(ans, "try-error")) {
return(expression())
}
res
ans
}

parse_cols <- function(new_cols) {
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-admiral-dpc-block.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ test_that("admiral-dpc-block", {
data <- datasets::BOD
data$PARAMCD <- as.character(seq_len(nrow(data)))

block <- admiral_dpc_block(
data,
block <- new_admiral_dpc_block(
by_vars = "Time",
parameters = c("4", "5"),
set_values_to = c(
Expand All @@ -12,6 +11,8 @@ test_that("admiral-dpc-block", {
)
)

block <- initialize_block(block, data)

expect_s3_class(block, "admiral_dpc_block")
expect_type(block, "list")

Expand Down
14 changes: 8 additions & 6 deletions tests/testthat/test-filter-expr-block.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
test_that("filter-expr-block", {
data <- datasets::iris
block <- filter_expr_block(data, value = c("Species == 'virginica'"))
block <- new_filter_expr_block(value = c("Species == 'virginica'"))
block <- initialize_block(block, data)

expect_s3_class(block, "filter_expr_block")
expect_type(block, "list")
Expand All @@ -10,16 +11,16 @@ test_that("filter-expr-block", {
res <- evaluate_block(block, data)
expect_identical(unique(as.character(res$Species)), "virginica")

res_ui <- generate_ui(filter_expr_block(data = datasets::iris), id = "test")
res_ui <- generate_ui(new_filter_expr_block(data = datasets::iris), id = "test")
expect_s3_class(res_ui, "shiny.tag")
})

test_that("filter-expr-block module_server handles input correctly", {

# wrap generate_server
# id as first argument, so we can test via shiny::testSever
module_server_test <- function(id, x, in_dat, ...) {
generate_server(x = x, in_dat = in_dat, id = id)
module_server_test <- function(id, x, in_dat, is_prev_valid, ...) {
generate_server(x = x, in_dat = in_dat, id = id, is_prev_valid = is_prev_valid)
}

shiny::testServer(
Expand All @@ -39,8 +40,9 @@ test_that("filter-expr-block module_server handles input correctly", {
},
args = list(
id = "test",
x = filter_expr_block(data = datasets::iris),
in_dat = reactive(datasets::iris)
x = new_filter_expr_block(data = datasets::iris),
in_dat = reactive(datasets::iris),
is_prev_valid = shiny::reactive(TRUE)
)
)
})
5 changes: 3 additions & 2 deletions tests/testthat/test-summarize-expr-block.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
test_that("summarize-expr-block", {
data <- datasets::iris

block <- summarize_expr_block(
data,
block <- new_summarize_expr_block(
group_by = "Species",
new_cols = c(
Mean.Sepal.Width = "mean(Sepal.Width)"
)
)

block <- initialize_block(block, data)

expect_true(is_initialized(block))
expect_s3_class(block, "summarize_expr_block")
expect_type(block, "list")
Expand Down

0 comments on commit 38fa7e5

Please sign in to comment.