|
| 1 | +testthat::describe("modify_last_chunk_outputs_attributes", { |
| 2 | + card <- teal.reporter::teal_card( |
| 3 | + "# Header", |
| 4 | + "Some text", |
| 5 | + structure(list(2), class = "chunk_output"), |
| 6 | + structure(list("1"), class = "chunk_output") |
| 7 | + ) |
| 8 | + |
| 9 | + it("changes last chunk output with default parameters", { |
| 10 | + new_card <- modify_last_chunk_outputs_attributes(teal_card, list(dev.height = 200)) |
| 11 | + testthat::expect_equal(attributes(new_card[[4]]), list(class = "chunk_output", dev.height = 200)) |
| 12 | + testthat::expect_equal(attributes(new_card[[3]]), list(class = "chunk_output")) |
| 13 | + }) |
| 14 | + |
| 15 | + it("changes last 2 chunks", { |
| 16 | + new_card <- modify_last_chunk_outputs_attributes(card, list(dev.height = 200), n = 2) |
| 17 | + testthat::expect_equal(attributes(new_card[[4]]), list(class = "chunk_output", dev.height = 200)) |
| 18 | + testthat::expect_equal(attributes(new_card[[3]]), list(class = "chunk_output", dev.height = 200)) |
| 19 | + }) |
| 20 | + |
| 21 | + it("only changes the numeric chunk_outputs", { |
| 22 | + new_card <- modify_last_chunk_outputs_attributes(card, list(dev.height = 200), n = 2, inner_classes = "numeric") |
| 23 | + testthat::expect_equal(attributes(new_card[[3]]), list(class = "chunk_output", dev.height = 200)) |
| 24 | + testthat::expect_equal(attributes(new_card[[4]]), list(class = "chunk_output")) |
| 25 | + }) |
| 26 | + |
| 27 | + it("throws warning when last chunk is not chunk_output", { |
| 28 | + testthat::expect_warning( |
| 29 | + modify_last_chunk_outputs_attributes(c(card, "yada"), list(new_attr = TRUE)), |
| 30 | + "The last element of the `teal_card` is not a `chunk_output` object. No attributes were modified." |
| 31 | + ) |
| 32 | + }) |
| 33 | + |
| 34 | + it("throws warning when second to last chunk is not chunk_output", { |
| 35 | + card_modified <- c(card[c(1, 2, 3)], "bla", card[[4]]) |
| 36 | + testthat::expect_warning( |
| 37 | + modify_last_chunk_outputs_attributes(card_modified, n = 3, list(new_attr = TRUE)), |
| 38 | + "The 2 to last element of the `teal_card` is not a `chunk_output` object. Skipping any further modifications." |
| 39 | + ) |
| 40 | + }) |
| 41 | + |
| 42 | + it("modifies all elements up until the first non-chunk output", { |
| 43 | + card_modified <- c(card[c(1, 2, 3)], "bla", card[[4]]) |
| 44 | + new_card <- modify_last_chunk_outputs_attributes(card_modified, n = 3, list(new_attr = TRUE), quiet = TRUE) |
| 45 | + testthat::expect_equal(attributes(new_card[[5]]), list(class = "chunk_output", new_attr = TRUE)) |
| 46 | + testthat::expect_null(attributes(new_card[[4]])) |
| 47 | + testthat::expect_equal(attributes(new_card[[3]]), list(class = "chunk_output")) |
| 48 | + }) |
| 49 | +}) |
0 commit comments