tests/testthat/test_eq_leaflet.R

context("leaflet")

test_that('eq_map creates leaflet map', {
  leaflet_map <-
    eq_clean_data(earthquakes) %>%
    eq_location_clean() %>%
    dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>%
    eq_map(annot_col = "DATE")

  expect_s3_class(leaflet_map, 'leaflet')
  expect_s3_class(leaflet_map, 'htmlwidget')
})

test_that('eq_create_label handles NA', {
  df <- data.frame(
    LOCATION_NAME = c(1:2, NA),
    EQ_PRIMARY = c(5, NA, 8),
    TOTAL_DEATHS = c(NA, NA, 1)
  )

  label_col <- eq_create_label(df, label_col = "popup_text")[["popup_text"]]

  expect_equal(which(grepl("Location", label_col)), c(1, 2))
  expect_equal(which(grepl("Magnitude", label_col)), c(1, 3))
  expect_equal(which(grepl("Total death", label_col)), 3)
})
avidclam/msdr5 documentation built on May 29, 2019, 11:02 p.m.