Skip to content

Commit

Permalink
Use snapshots for leaflet maps
Browse files Browse the repository at this point in the history
  • Loading branch information
steffilazerte committed Jun 28, 2024
1 parent 206a840 commit be42613
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 7 deletions.
8 changes: 8 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(feedr)

Expand Down
48 changes: 48 additions & 0 deletions tests/testthat/_snaps/c05_map_leaflet.md

Large diffs are not rendered by default.

Binary file removed tests/testthat/ggmap_args1_map.png
Binary file not shown.
Binary file removed tests/testthat/ggmap_args2_map.png
Binary file not shown.
Binary file removed tests/testthat/ggmap_args3_map.png
Binary file not shown.
Binary file removed tests/testthat/ggmap_indiv1_map.png
Binary file not shown.
Binary file removed tests/testthat/ggmap_indiv2_map.png
Binary file not shown.
Binary file removed tests/testthat/ggmap_none_map.png
Binary file not shown.
Binary file removed tests/testthat/ggmap_sum_indiv_map.png
Binary file not shown.
Binary file removed tests/testthat/ggmap_sum_map.png
Binary file not shown.
14 changes: 7 additions & 7 deletions tests/testthat/test_c05_map_leaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ test_that("maps_leaflet_base return maps", {

expect_silent(map <- map_leaflet_base(locs = unique(finches[, c("logger_id", "lat", "lon")])))
expect_s3_class(map, c("leaflet", "htmlwidget"))
expect_true(all(attr(map$x, "leafletData") == unique(finches[, c("logger_id", "lat", "lon")])))
#expect_equal_to_leaflet_reference(map, "leaflet_base_map.rds")
expect_equal(attr(map$x, "leafletData"), unique(finches[, c("logger_id", "lat", "lon")]))
expect_snapshot_value(deparse(map$x), style = "json2")
})

test_that("map_leaflet() returns summary map", {
Expand All @@ -15,13 +15,13 @@ test_that("map_leaflet() returns summary map", {
m = move(visits(finches)),
summary = "sum"), NA)
expect_s3_class(map, c("leaflet", "htmlwidget"))
#expect_equal_to_leaflet_reference(map, "leaflet_sum_map.rds")
expect_snapshot_value(deparse(map$x), style = "json2")

expect_error(map <- map_leaflet(p = presence(visits(finches)),
m = move(visits(finches)),
summary = "sum_indiv"), NA)
expect_s3_class(map, c("leaflet", "htmlwidget"))
#expect_equal_to_leaflet_reference(map, "leaflet_sum_indiv_map.rds")
expect_snapshot_value(deparse(map$x), style = "json2")

p2 <- presence(visits(finches)) %>%
dplyr::group_by(logger_id, lat, lon) %>%
Expand All @@ -33,7 +33,7 @@ test_that("map_leaflet() returns summary map", {

expect_error(map <- map_leaflet(p = p2, m = m2), NA)
expect_s3_class(map, c("leaflet", "htmlwidget"))
#expect_equal_to_leaflet_reference(map, "leaflet_none_map.rds")
expect_snapshot_value(deparse(map$x), style = "json2")
})

test_that("map_leaflet() returns summary map of individuals", {
Expand All @@ -48,7 +48,7 @@ test_that("map_leaflet() returns summary map of individuals", {

expect_error(map <- map_leaflet(p = p_indiv, m = m_indiv), NA)
expect_s3_class(map, c("leaflet", "htmlwidget"))
#expect_equal_to_leaflet_reference(map, "leaflet_indiv_map.rds")
expect_snapshot_value(deparse(map$x), style = "json2")
})

test_that("map_leaflet() scale, pal, title", {
Expand All @@ -62,5 +62,5 @@ test_that("map_leaflet() scale, pal, title", {
m_title = "PATH", p_title = "TIME",
m_pal = c("blue", "white"), p_pal = c("green", "yellow")), NA)
expect_s3_class(map, c("leaflet", "htmlwidget"))
# expect_equal_to_leaflet_reference(map, "leaflet_args_map.rds")
expect_snapshot_value(deparse(map$x), style = "json2")
})

0 comments on commit be42613

Please sign in to comment.