Skip to content

Commit

Permalink
Add tests for listing export bug (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua authored Oct 11, 2024
1 parent a9c6889 commit f36fe12
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/testthat/_snaps/export.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,45 @@
foot

# export_as_txt works with empty listings

Code
cat(res)
Output
—————————————————————————————————————————————————————————————————————————————————————
Null Report: No observations met the reporting criteria for inclusion in this output.

# export_as_txt works with listings with all key cols

Code
cat(res)
Output
Categorical Level Biomarker 2 Medication Class Standardized Medication Name
———————————————————————————————————————————————————————————————————————————————
LOW medcl A medname A_1/3
medname A_2/3
medname A_3/3
medcl B medname B_1/4
medname B_2/4
medname B_3/4
medname B_4/4
medcl C medname C_1/2
medname C_2/2
MEDIUM medcl A medname A_2/3
medname A_3/3
medcl B medname B_1/4
medname B_2/4
medname B_3/4
medname B_4/4
medcl C medname C_1/2
medname C_2/2
HIGH medcl A medname A_1/3
medname A_2/3
medname A_3/3
medcl B medname B_1/4
medname B_2/4
medname B_3/4
medname B_4/4
medcl C medname C_2/2

22 changes: 22 additions & 0 deletions tests/testthat/test-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,25 @@ testthat::test_that("export_as_txt works with split_into_pages_by_var", {
pages_listings <- export_as_txt(lsting, file = NULL, paginate = TRUE, lpp = 30, cpp = 65)
testthat::expect_snapshot(cat(pages_listings))
})

testthat::test_that("export_as_txt works with empty listings", {
df <- data.frame(
x = with_label("Null Report: No observations met the reporting criteria for inclusion in this output.", "")
)
lsting <- as_listing(df)

res <- export_as_txt(lsting)
testthat::expect_snapshot(cat(res))
})

testthat::test_that("export_as_txt works with listings with all key cols", {
lsting <- as_listing(
df = ex_adcm[1:50, ],
key_cols = c("BMRKR2", "CMCLAS", "CMDECOD"),
disp_cols = c("BMRKR2", "CMCLAS", "CMDECOD"),
unique_rows = TRUE
)

res <- export_as_txt(lsting)
testthat::expect_snapshot(cat(res))
})

0 comments on commit f36fe12

Please sign in to comment.