diff --git a/app/assets/javascripts/darkswarm/directives/map_search.js.coffee b/app/assets/javascripts/darkswarm/directives/map_search.js.coffee index 0d36b87d2b8..8ac7e5b653f 100644 --- a/app/assets/javascripts/darkswarm/directives/map_search.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/map_search.js.coffee @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 80b5a5e90b3..df0e60f54fb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2784,6 +2784,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" diff --git a/spec/system/consumer/map_spec.rb b/spec/system/consumer/map_spec.rb new file mode 100644 index 00000000000..7cafdbeda6d --- /dev/null +++ b/spec/system/consumer/map_spec.rb @@ -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