Skip to content

Commit f36fe12

Browse files
authored
Add tests for listing export bug (#227)
See insightsengineering/formatters#323
1 parent a9c6889 commit f36fe12

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

tests/testthat/_snaps/export.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,45 @@
258258
259259
foot
260260

261+
# export_as_txt works with empty listings
262+
263+
Code
264+
cat(res)
265+
Output
266+
267+
—————————————————————————————————————————————————————————————————————————————————————
268+
Null Report: No observations met the reporting criteria for inclusion in this output.
269+
270+
# export_as_txt works with listings with all key cols
271+
272+
Code
273+
cat(res)
274+
Output
275+
Categorical Level Biomarker 2 Medication Class Standardized Medication Name
276+
———————————————————————————————————————————————————————————————————————————————
277+
LOW medcl A medname A_1/3
278+
medname A_2/3
279+
medname A_3/3
280+
medcl B medname B_1/4
281+
medname B_2/4
282+
medname B_3/4
283+
medname B_4/4
284+
medcl C medname C_1/2
285+
medname C_2/2
286+
MEDIUM medcl A medname A_2/3
287+
medname A_3/3
288+
medcl B medname B_1/4
289+
medname B_2/4
290+
medname B_3/4
291+
medname B_4/4
292+
medcl C medname C_1/2
293+
medname C_2/2
294+
HIGH medcl A medname A_1/3
295+
medname A_2/3
296+
medname A_3/3
297+
medcl B medname B_1/4
298+
medname B_2/4
299+
medname B_3/4
300+
medname B_4/4
301+
medcl C medname C_2/2
302+

tests/testthat/test-export.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,25 @@ testthat::test_that("export_as_txt works with split_into_pages_by_var", {
9191
pages_listings <- export_as_txt(lsting, file = NULL, paginate = TRUE, lpp = 30, cpp = 65)
9292
testthat::expect_snapshot(cat(pages_listings))
9393
})
94+
95+
testthat::test_that("export_as_txt works with empty listings", {
96+
df <- data.frame(
97+
x = with_label("Null Report: No observations met the reporting criteria for inclusion in this output.", "")
98+
)
99+
lsting <- as_listing(df)
100+
101+
res <- export_as_txt(lsting)
102+
testthat::expect_snapshot(cat(res))
103+
})
104+
105+
testthat::test_that("export_as_txt works with listings with all key cols", {
106+
lsting <- as_listing(
107+
df = ex_adcm[1:50, ],
108+
key_cols = c("BMRKR2", "CMCLAS", "CMDECOD"),
109+
disp_cols = c("BMRKR2", "CMCLAS", "CMDECOD"),
110+
unique_rows = TRUE
111+
)
112+
113+
res <- export_as_txt(lsting)
114+
testthat::expect_snapshot(cat(res))
115+
})

0 commit comments

Comments
 (0)