tests/testthat/test-google_map_layer_methods.R

context("map layer methods")


test_that("goejson is validated", {

  ## url is validated
  url <- 'https://storage.googleapis.com/mapsdevsite/json/google.json'
  expect_true(
    googleway:::validateGeojson(url)$geojson ==
      url
    )
  expect_true(
    googleway:::validateGeojson(url)$source == "url"
  )

  ## JSON
  js <- '{ }'
  expect_true(
    googleway:::validateGeojson(js)$geojson == "{ }"
  )

  expect_true(
    googleway:::validateGeojson(js)$source == "local"
  )

  class(js) <- 'json'
  expect_true(
    googleway:::validateGeojson(js)$source == "local"
  )

  expect_error(googleway:::validateGeojson(data.frame()))

  ## invalid json
  expect_error(
    googleway:::validateGeojson('{ "invalid" , json }'),
    "invalid JSON"
    )

})

test_that("update style is validated", {

  ## invalid JSON
  style <- '{ "invalid" , "JSON" }'

  expect_error(
    googleway:::validateStyleUpdate(style),
    "invalid JSON"
  )

  style <- '{ "fillColor" : "color" }'

  expect_true(class(googleway:::validateStyleUpdate(style)) == "json")


  style <- list(fillColor = "color")
  expect_true(class(googleway:::validateStyleUpdate(style)) == "json")

  expect_error(
    googleway:::validateStyleUpdate(data.frame())
  )

})


test_that("style is validated", {

  style <- '{ "invalid" , "JSON"  }'
  expect_error(
    googleway:::validateStyle(style),
    "invalid JSON"
  )

  style <- '{ "fillColor" : "color" }'
  expect_true(class(googleway:::validateStyle(style)) == "list")
  expect_true(googleway:::validateStyle(style)$type == "all")
  expect_true(googleway:::validateStyle(style)$style == style)


  style <- list(fillColor = "color")
  expect_true(googleway:::validateStyle(style)$type == "individual")

  expect_error(
    googleway:::validateStyle(data.frame())
  )

})

Try the googleway package in your browser

Any scripts or data that you put into this service are public.

googleway documentation built on Aug. 22, 2023, 9:13 a.m.