Skip to content

Commit

Permalink
tests(card_image): Add snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed Jun 12, 2024
1 parent 8678c94 commit e32a918
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/testthat/_snaps/card.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# card_image()

Code
show_raw_html(card(card_image("https://example.com/image.jpg"), card_body(
"image cap on top of card")))
Output
<div class="card bslib-card bslib-mb-spacing html-fill-item html-fill-container" data-bslib-card-init data-require-bs-caller="card()" data-require-bs-version="5">
<img class="img-fluid card-img-top" src="https://example.com/image.jpg"/>
<div class="card-body bslib-gap-spacing html-fill-item html-fill-container" style="margin-top:auto;margin-bottom:auto;flex:1 1 auto;">image cap on top of card</div>
<script data-bslib-card-init>bslib.Card.initializeAllCards();</script>
</div>

---

Code
show_raw_html(card(card_body("image cap on bottom of card"), card_image(
"https://example.com/image.jpg")))
Output
<div class="card bslib-card bslib-mb-spacing html-fill-item html-fill-container" data-bslib-card-init data-require-bs-caller="card()" data-require-bs-version="5">
<div class="card-body bslib-gap-spacing html-fill-item html-fill-container" style="margin-top:auto;margin-bottom:auto;flex:1 1 auto;">image cap on bottom of card</div>
<img class="img-fluid card-img-bottom" src="https://example.com/image.jpg"/>
<script data-bslib-card-init>bslib.Card.initializeAllCards();</script>
</div>

---

Code
show_raw_html(card(card_header("header"), card_image(
"https://example.com/image.jpg"), card_body("image not a cap")))
Output
<div class="card bslib-card bslib-mb-spacing html-fill-item html-fill-container" data-bslib-card-init data-require-bs-caller="card()" data-require-bs-version="5">
<div class="card-header">header</div>
<img src="https://example.com/image.jpg" class="img-fluid"/>
<div class="card-body bslib-gap-spacing html-fill-item html-fill-container" style="margin-top:auto;margin-bottom:auto;flex:1 1 auto;">image not a cap</div>
<script data-bslib-card-init>bslib.Card.initializeAllCards();</script>
</div>

---

Code
show_raw_html(card(card_image("https://example.com/image.jpg", alt = "card-img")))
Output
<div class="card bslib-card bslib-mb-spacing html-fill-item html-fill-container" data-bslib-card-init data-require-bs-caller="card()" data-require-bs-version="5">
<img alt="card-img" class="img-fluid card-img" src="https://example.com/image.jpg"/>
<script data-bslib-card-init>bslib.Card.initializeAllCards();</script>
</div>

41 changes: 41 additions & 0 deletions tests/testthat/test-card.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
test_that("card_image()", {
show_raw_html <- function(x) {
cat(format(x))
}

expect_snapshot(
show_raw_html(
card(
card_image("https://example.com/image.jpg"),
card_body("image cap on top of card")
)
)
)

expect_snapshot(
show_raw_html(
card(
card_body("image cap on bottom of card"),
card_image("https://example.com/image.jpg")
)
)
)

expect_snapshot(
show_raw_html(
card(
card_header("header"),
card_image("https://example.com/image.jpg"),
card_body("image not a cap")
)
)
)

expect_snapshot(
show_raw_html(
card(
card_image("https://example.com/image.jpg", alt = "card-img")
)
)
)
})

0 comments on commit e32a918

Please sign in to comment.