Skip to content

Commit fa320d7

Browse files
committed
Minor adjustments for tests
1 parent f92e821 commit fa320d7

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

R/trackingReports.R

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,19 @@ tracking_report <- function(dataset_list, vars, labels = NULL, weight = NULL) {
5353
# - "partial" means it is available in only some datasets
5454
# - "single" means it is available in exactly one dataset
5555

56-
# "all" would follow a typical path
57-
# "partial" would require special treatment to ensure that labeling was
58-
# adjusted appropriately for presentation in the resulting pdf
59-
# "single" should act as a simple passthrough where no additional
60-
# formatting or manipulation takes place on the result.
61-
62-
l1 <- length(results_available)
63-
l2 <- length(labels)
64-
65-
# The "all" case
66-
if(l1 == l2)
67-
rebuilt_results$results[[v]]$availability <- "all"
68-
69-
# The partial case
70-
if(l1 > 1 & l1 < l2)
71-
rebuilt_results$results[[v]]$availability <- "partial"
56+
# Because we use subsetting at the list level, "all" and "partial"
57+
# would follow a typical path that labeling was adjusted appropriately
58+
# for presentation in the resulting pdf "single" should act as a simple
59+
# passthrough where no additional formatting or manipulation takes place
60+
# on the result.
7261

7362
# The single case
74-
if(l1 == 1)
63+
if(length(results_available) == 1) {
7564
rebuilt_results$results[[v]]$availability <- "single"
65+
} else {
66+
rebuilt_results$results[[v]]$availability <- "general"
67+
}
68+
7669
}
7770

7871
# Now that we have an attribute that identifies availability we can use it as

tests/testthat/test-banner.R

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,28 @@ test_that("Single banner with one variable, recodes - categories rename, else",
151151
expect_identical(banner_data[["Results"]][["age5"]][["categories"]], c("Under 25", "Over 54"))
152152
})
153153

154-
# TODO: Figure these out, maybe never.
155-
# with_test_authentication({
156-
# ds <- loadDataset("https://app.crunch.io/api/datasets/868e8b3e01834c45b73e56e80160d3c3/")
157-
# test_that("Error handling - banner", {
158-
# expect_warning(banner(ds, list(c(), "A"="art3")),
159-
# "No variables found in 'Banner1' in `vars`. 'Banner1' will be ignored.")
160-
#
161-
# expect_error(banner(ds, list(Results = c("profile_gender")), recodes = list(profile_gender = list("Male2"="Man"))),
162-
# "Responses in `recodes` must be included in variable responses. This is not true for 'Male2' in 'profile_gender'.")
163-
# expect_error(banner(ds, list(Results = c("profile_gender")), recodes = list(profile_gender = list("Male"="Man", "Female"="Man"))),
164-
# "Combining categories is not currently supported. Please check 'profile_gender' recodes.")
165-
# })
166-
# })
154+
context("getBannerInfo")
155+
156+
test_that("Returns default banner", {
157+
expect_equal(getBannerInfo(NULL), default_banner)
158+
})
159+
160+
context("removeInserts")
161+
162+
test_that("Adjustments for subtotals", {
163+
var <- list()
164+
theme <- list()
165+
theme$format_subtotals <- NULL
166+
theme$format_headers <- NULL
167+
var$inserts_obj <- list()
168+
var$inserts_obj$test <- "Fake Object of class Subtotal"
169+
class(var$inserts_obj$test) <- "Subtotal"
170+
var$inserts_obj$other <- "Fake Object of class Headers"
171+
class(var$inserts_obj$other) <- "Headers"
172+
173+
expect_equal(
174+
removeInserts(var, theme),
175+
list(inserts_obj = structure(list(), .Names = character(0)),
176+
inserts = structure(list(), .Names = character(0)))
177+
)
178+
})

0 commit comments

Comments
 (0)