Skip to content

Commit

Permalink
Test that monthly count plot reacts to daterange filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmlft committed Aug 22, 2024
1 parent 11b41fc commit 185a2da
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tests/testthat/test-mod_monthly_count.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ mock_monthly_counts <- data.frame(
# Application-logic tests ---------------------------------------------------------------------

mock_concept_row <- reactiveVal()
mock_date_range <- reactiveVal(c("2000-01-01", "2200-12-31"))

test_that("mod_monthly_count_server reacts to changes in the selected concept", {
testServer(
mod_monthly_count_server,
# Add here your module params
args = list(data = mock_monthly_counts, selected_concept = mock_concept_row),
args = list(data = mock_monthly_counts, selected_concept = mock_concept_row, selected_dates = mock_date_range),
{
ns <- session$ns
expect_true(inherits(ns, "function"))
Expand All @@ -34,10 +35,37 @@ test_that("mod_monthly_count_server reacts to changes in the selected concept",
)
})

test_that("mod_monthly_count_server reacts to changes in the selected date range", {
testServer(
mod_monthly_count_server,
# Add here your module params
args = list(data = mock_monthly_counts, selected_concept = mock_concept_row, selected_dates = mock_date_range),
{
ns <- session$ns
expect_true(inherits(ns, "function"))
expect_true(grepl(id, ns("")))
expect_true(grepl("test", ns("test")))

mock_concept_row(list(concept_id = 40213251, concept_name = "test")) # update reactive value

selected_dates <- c("2019-01-01", "2019-12-31")
mock_date_range(selected_dates)
session$flushReact()
expect_true(all(filtered_monthly_counts()$date_year == 2019))

## Case when no data for given range
selected_dates2 <- c("3019-01-01", "3019-12-31")
mock_date_range(selected_dates2)
session$flushReact()
expect_equal(nrow(filtered_monthly_counts()), 0)
}
)
})

test_that("mod_monthly_count_server generates an empty plot when no row is selected", {
testServer(
mod_monthly_count_server,
args = list(data = mock_monthly_counts, selected_concept = reactiveVal(NULL)),
args = list(data = mock_monthly_counts, selected_concept = reactiveVal(NULL), selected_dates = mock_date_range),
{
# When no concept_id is selected, no plot should be rendered
expect_length(output$monthly_count_plot$coordmap$panels[[1]]$mapping, 0)
Expand Down

0 comments on commit 185a2da

Please sign in to comment.