@@ -4,18 +4,23 @@ testthat::describe("teal_card contructor creates", {
44 testthat :: expect_identical(doc , structure(list (), class = " teal_card" ))
55 })
66
7+ testthat :: it(" teal_card appends arguments and sets them random unique names" , {
8+ doc <- teal_card(" a" , " b" , " c" , " d" , " e" , " f" , " g" , " h" )
9+ testthat :: expect_true(all(! duplicated(names(doc ))))
10+ })
11+
712 testthat :: it(" teal_card doesn't ignore NULL" , {
8- doc <- teal_card(NULL )
13+ doc <- unname( teal_card(NULL ) )
914 testthat :: expect_identical(doc , structure(list (NULL ), class = " teal_card" ))
1015 })
1116
1217 testthat :: it(" teal_card keeps conditions" , {
13- doc <- teal_card(simpleCondition(" test" ))
18+ doc <- unname( teal_card(simpleCondition(" test" ) ))
1419 testthat :: expect_identical(doc , structure(list (simpleCondition(" test" )), class = " teal_card" ))
1520 })
1621
1722 testthat :: it(" teal_card appends each element asis (no list unwrapping)" , {
18- doc <- teal_card(" a" , list (1 , list (2 )), code_chunk(" print('hi')" ))
23+ doc <- unname( teal_card(" a" , list (1 , list (2 )), code_chunk(" print('hi')" ) ))
1924 testthat :: expect_identical(
2025 doc ,
2126 structure(
@@ -32,64 +37,87 @@ testthat::describe("c.teal_card combines", {
3237 })
3338
3439 it(" empty teal_card with non-empty" , {
35- testthat :: expect_identical(c(teal_card(), teal_card(TRUE )), teal_card(TRUE ))
40+ doc2 <- teal_card(TRUE )
41+ testthat :: expect_identical(c(teal_card(), doc2 ), doc2 )
3642 })
3743
38- it(" with empty teal_card and remains the same" , {
39- testthat :: expect_identical(c(teal_card(" a" , " b" ), teal_card()), teal_card(" a" , " b" ))
44+ it(" with empty teal_card - remains the same" , {
45+ doc <- teal_card(" a" , " b" )
46+ testthat :: expect_identical(c(doc , teal_card()), doc )
4047 })
4148
42- it(" with character, preserves class and append as a new element" , {
49+ it(" with character - adds as a new element" , {
4350 doc_result <- c(teal_card(" a" , " b" ), " c" )
44- testthat :: expect_identical (doc_result , teal_card(" a" , " b" , " c" ))
51+ testthat :: expect_equal (doc_result , teal_card(" a" , " b" , " c" ), ignore_attr = TRUE )
4552 })
4653
47- it(" with list, preserves the class and adds each element separately (unwraps list)" , {
54+ it(" with list - adds each list element separately (unwraps list)" , {
4855 doc_result <- c(teal_card(" a" , " b" ), list (1 , 2 ))
49- testthat :: expect_identical (doc_result , teal_card(" a" , " b" , 1 , 2 ))
56+ testthat :: expect_equal (doc_result , teal_card(" a" , " b" , 1 , 2 ), ignore_attr = TRUE )
5057 })
5158
52- it(" with teal_card containing a list and doesn't unwrap the list (asis )" , {
59+ it(" with teal_card containing a list - append this list asis ( doesn't unwrap list)" , {
5360 doc_result <- c(teal_card(" a" , " b" ), teal_card(list (1 , 2 )))
54- testthat :: expect_identical (doc_result , teal_card(" a" , " b" , list (1 , 2 )))
61+ testthat :: expect_equal (doc_result , teal_card(" a" , " b" , list (1 , 2 )), ignore_attr = TRUE )
5562 })
5663
57- it(" with NULL and remains the same (ignores NULL)" , {
64+ it(" with NULL - remains the same (ignores NULL)" , {
5865 doc_result <- c(teal_card(" a" , " b" ), NULL )
59- testthat :: expect_identical (doc_result , teal_card(" a" , " b" ))
66+ testthat :: expect_equal (doc_result , teal_card(" a" , " b" ), ignore_attr = TRUE )
6067 })
6168
62- it(" with character(0) and appends as a new element" , {
69+ it(" with character(0) - adds as a new element" , {
6370 doc_result <- c(teal_card(" a" , " b" ), character (0 ))
64- testthat :: expect_identical(doc_result , teal_card(" a" , " b" , character (0 )))
65- })
66-
67- it(" with teal_card and appends new elements asis" , {
68- doc_result <- c(teal_card(" a" , " b" ), teal_card(" c" , " d" ))
69- testthat :: expect_identical(doc_result , teal_card(" a" , " b" , " c" , " d" ))
71+ testthat :: expect_equal(doc_result , teal_card(" a" , " b" , character (0 )), ignore_attr = TRUE )
7072 })
7173
72- it(" with ggplot, preserves the class class and append as a new element" , {
74+ it(" with ggplot - adds as a new element" , {
7375 plot <- ggplot2 :: ggplot(iris )
7476 doc_result <- c(teal_card(" a" , " b" ), plot )
75- testthat :: expect_identical (doc_result , teal_card(" a" , " b" , plot ))
77+ testthat :: expect_equal (doc_result , teal_card(" a" , " b" , plot ), ignore_attr = TRUE )
7678 })
7779
78- it(" with teal_card containing ggplot and appends elements asis" , {
80+ it(" with new teal_card - adds new elements asis" , {
81+ doc_result <- c(teal_card(" a" , " b" ), teal_card(" c" , " d" ))
82+ testthat :: expect_equal(doc_result , teal_card(" a" , " b" , " c" , " d" ), ignore_attr = TRUE )
83+ })
84+
85+ it(" with new teal_card containing ggplot - adds new elements asis" , {
7986 plot <- ggplot2 :: ggplot(iris ) +
8087 ggplot2 :: geom_point(ggplot2 :: aes(x = Sepal.Length , y = Sepal.Width ))
8188 doc_result <- c(teal_card(" a" , " b" ), teal_card(" # Plot" , plot ))
82- testthat :: expect_identical(doc_result , teal_card(" a" , " b" , " # Plot" , plot ))
89+ testthat :: expect_equal(doc_result , teal_card(" a" , " b" , " # Plot" , plot ), ignore_attr = TRUE )
90+ })
91+
92+ it(" with teal_card containing new and old items - adds only new" , {
93+ doc1 <- teal_card(" a" , " b" )
94+ doc2 <- c(doc1 , " c" , " d" )
95+ testthat :: expect_equal(c(doc1 , doc2 ), teal_card(" a" , " b" , " c" , " d" ), ignore_attr = TRUE )
96+ })
97+
98+ it(" with teal_card containing new and old items - adds even if their order is different" , {
99+ doc1 <- teal_card(" a" , " b" )
100+ doc2 <- c(doc1 , " c" , " d" )
101+ doc2 <- doc2 [c(3 , 1 , 4 , 2 )]
102+ testthat :: expect_equal(c(doc1 , doc2 ), teal_card(" c" , " a" , " d" , " b" ), ignore_attr = TRUE )
103+ })
104+
105+ it(" with teal_card with new and missing old items - restores original items, adds new at the end and warn" , {
106+ doc1 <- teal_card(" a" , " b" )
107+ doc2 <- c(doc1 , " c" , " d" )[c(4 , 3 , 2 )]
108+ testthat :: expect_warning(
109+ testthat :: expect_equal(c(doc1 , doc2 ), teal_card(" a" , " b" , " d" , " c" ), ignore_attr = TRUE )
110+ )
83111 })
84112
85- it(" with a `teal_card` and keeps original metadata" , {
113+ it(" with a `teal_card` - keeps original metadata" , {
86114 doc <- teal_card(" a" , " b" )
87115 metadata(doc ) <- list (title = " A Title" , a = " test" )
88116 doc_result <- c(doc , teal_card(" new content" ))
89117 testthat :: expect_identical(metadata(doc_result ), list (title = " A Title" , a = " test" ))
90118 })
91119
92- it(" new `teal_card` and combines metadata and overwrites original" , {
120+ it(" new `teal_card` - combines metadata and overwrites original" , {
93121 doc1 <- teal_card(" a" , " b" )
94122 metadata(doc1 ) <- list (title = " A Title" , a = " test" )
95123 doc2 <- teal_card(" new content" )
@@ -118,22 +146,22 @@ testthat::describe("as.teal_card", {
118146 it(" converts a simple list with each element being converted to a report content" , {
119147 simple_list <- list (" a" , " b" , " c" )
120148 doc <- as.teal_card(simple_list )
121- testthat :: expect_identical (doc , teal_card(" a" , " b" , " c" ))
149+ testthat :: expect_equal (doc , teal_card(" a" , " b" , " c" ), ignore_attr = TRUE )
122150 })
123151
124152 it(" converts a custom list class with many elements into single-element-teal_card" , {
125153 custom_list <- list (" a" , " b" , " c" , " d" )
126154 class(custom_list ) <- " extra class"
127155 doc <- as.teal_card(custom_list )
128- testthat :: expect_identical (doc , teal_card(custom_list ))
156+ testthat :: expect_equal (doc , teal_card(custom_list ), ignore_attr = TRUE )
129157 })
130158
131159 it(" converts a ggplot2 to a teal_card with only 1 report content" , {
132160 testthat :: skip_if_not_installed(" ggplot2" )
133161 plot <- ggplot2 :: ggplot(iris ) +
134162 ggplot2 :: geom_point(ggplot2 :: aes(x = Sepal.Length , y = Sepal.Width ))
135163 doc <- as.teal_card(plot )
136- testthat :: expect_identical (doc , teal_card(plot ))
164+ testthat :: expect_equal (doc , teal_card(plot ), ignore_attr = TRUE )
137165 })
138166})
139167
0 commit comments