Skip to content

Commit

Permalink
Merge pull request #12963 from murjax/map-network-check-8230
Browse files Browse the repository at this point in the history
Show alert if map cannot load
  • Loading branch information
filipefurtad0 authored Nov 28, 2024
2 parents 58d174f + 32ab821 commit 355c968
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/assets/javascripts/darkswarm/directives/map_search.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ angular.module('Darkswarm').directive 'mapSearch', ($timeout, Search) ->
$timeout =>
map = ctrl.getMap()

searchBox = scope.createSearchBox map
scope.bindSearchResponse map, searchBox
scope.biasResults map, searchBox
scope.performUrlSearch map
if !map
alert(t('gmap_load_failure'))
else
searchBox = scope.createSearchBox map
scope.bindSearchResponse map, searchBox
scope.biasResults map, searchBox
scope.performUrlSearch map

scope.createSearchBox = (map) ->
map.controls[google.maps.ControlPosition.TOP_LEFT].push scope.input
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2788,6 +2788,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
confirm_hub_change: "Are you sure? This will change your selected hub and remove any items in your shopping cart."
confirm_oc_change: "Are you sure? This will change your selected order cycle and remove any items in your shopping cart."
location_placeholder: "Type in a location..."
gmap_load_failure: "Unable to load map. Please check your browser settings and allow 3rd party cookies for this website."
error_required: "can't be blank"
error_number: "must be number"
error_email: "must be email address"
Expand Down
28 changes: 28 additions & 0 deletions spec/system/consumer/map_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require 'system_helper'

RSpec.describe 'Map' do
context 'map can load' do
it 'does not show alert' do
url_whitelist = page.driver.browser.url_whitelist
page.driver.browser.url_whitelist = nil

assert_raises(Capybara::ModalNotFound) do
accept_alert { visit '/map' }
end

page.driver.browser.url_whitelist = url_whitelist
end
end

context 'map cannot load' do
it 'shows alert' do
message = accept_alert { visit '/map' }
expect(message).to eq(
"Unable to load map. Please check your browser " \
"settings and allow 3rd party cookies for this website."
)
end
end
end

0 comments on commit 355c968

Please sign in to comment.