Skip to content

Commit

Permalink
Minor adjustments for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1beb committed Jan 11, 2021
1 parent f92e821 commit fa320d7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
27 changes: 10 additions & 17 deletions R/trackingReports.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,19 @@ tracking_report <- function(dataset_list, vars, labels = NULL, weight = NULL) {
# - "partial" means it is available in only some datasets
# - "single" means it is available in exactly one dataset

# "all" would follow a typical path
# "partial" would require special treatment to ensure that labeling was
# adjusted appropriately for presentation in the resulting pdf
# "single" should act as a simple passthrough where no additional
# formatting or manipulation takes place on the result.

l1 <- length(results_available)
l2 <- length(labels)

# The "all" case
if(l1 == l2)
rebuilt_results$results[[v]]$availability <- "all"

# The partial case
if(l1 > 1 & l1 < l2)
rebuilt_results$results[[v]]$availability <- "partial"
# Because we use subsetting at the list level, "all" and "partial"
# would follow a typical path that labeling was adjusted appropriately
# for presentation in the resulting pdf "single" should act as a simple
# passthrough where no additional formatting or manipulation takes place
# on the result.

# The single case
if(l1 == 1)
if(length(results_available) == 1) {
rebuilt_results$results[[v]]$availability <- "single"
} else {
rebuilt_results$results[[v]]$availability <- "general"
}

}

# Now that we have an attribute that identifies availability we can use it as
Expand Down
38 changes: 25 additions & 13 deletions tests/testthat/test-banner.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,28 @@ test_that("Single banner with one variable, recodes - categories rename, else",
expect_identical(banner_data[["Results"]][["age5"]][["categories"]], c("Under 25", "Over 54"))
})

# TODO: Figure these out, maybe never.
# with_test_authentication({
# ds <- loadDataset("https://app.crunch.io/api/datasets/868e8b3e01834c45b73e56e80160d3c3/")
# test_that("Error handling - banner", {
# expect_warning(banner(ds, list(c(), "A"="art3")),
# "No variables found in 'Banner1' in `vars`. 'Banner1' will be ignored.")
#
# expect_error(banner(ds, list(Results = c("profile_gender")), recodes = list(profile_gender = list("Male2"="Man"))),
# "Responses in `recodes` must be included in variable responses. This is not true for 'Male2' in 'profile_gender'.")
# expect_error(banner(ds, list(Results = c("profile_gender")), recodes = list(profile_gender = list("Male"="Man", "Female"="Man"))),
# "Combining categories is not currently supported. Please check 'profile_gender' recodes.")
# })
# })
context("getBannerInfo")

test_that("Returns default banner", {
expect_equal(getBannerInfo(NULL), default_banner)
})

context("removeInserts")

test_that("Adjustments for subtotals", {
var <- list()
theme <- list()
theme$format_subtotals <- NULL
theme$format_headers <- NULL
var$inserts_obj <- list()
var$inserts_obj$test <- "Fake Object of class Subtotal"
class(var$inserts_obj$test) <- "Subtotal"
var$inserts_obj$other <- "Fake Object of class Headers"
class(var$inserts_obj$other) <- "Headers"

expect_equal(
removeInserts(var, theme),
list(inserts_obj = structure(list(), .Names = character(0)),
inserts = structure(list(), .Names = character(0)))
)
})

0 comments on commit fa320d7

Please sign in to comment.