mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-25 05:45:15 +00:00
Add tests to make sure the appropriate map is loaded e.g. Open Street Map or Google
This commit is contained in:
27
spec/helpers/map_helper_spec.rb
Normal file
27
spec/helpers/map_helper_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe MapHelper, type: :helper do
|
||||
describe "#using_google_maps?" do
|
||||
it "returns true when a GOOGLE_MAPS_API_KEY is present" do
|
||||
stub_environment_variable("GOOGLE_MAPS_API_KEY", "ABC")
|
||||
|
||||
expect(helper.using_google_maps?).to eq true
|
||||
end
|
||||
|
||||
it "returns false if Open Street Map is enabled, even if a GOOGLE_MAPS_API_KEY is present" do
|
||||
stub_environment_variable("GOOGLE_MAPS_API_KEY", "ABC")
|
||||
ContentConfig.open_street_map_enabled = true
|
||||
|
||||
expect(helper.using_google_maps?).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stub_environment_variable(key, value)
|
||||
allow(ENV).to receive(:[]).and_call_original # Allow non-stubbed calls to ENV to proceed
|
||||
allow(ENV).to receive(:[]).with(key).and_return(value)
|
||||
end
|
||||
end
|
||||
20
spec/views/registration/steps/_details.html.haml_spec.rb
Normal file
20
spec/views/registration/steps/_details.html.haml_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "spec_helper"
|
||||
|
||||
RSpec.describe "registration/steps/_details.html.haml" do
|
||||
subject { render }
|
||||
|
||||
it "uses Google Maps when it is enabled" do
|
||||
allow(view).to receive_messages(using_google_maps?: true)
|
||||
|
||||
is_expected.to match /<ui-gmap-google-map center='map.center' zoom='map.zoom'>/
|
||||
end
|
||||
|
||||
it "uses OpenStreetMap when it is enabled" do
|
||||
ContentConfig.open_street_map_enabled = true
|
||||
allow(view).to receive_messages(using_google_maps?: false)
|
||||
|
||||
is_expected.to match /<div class='map-container--registration' id='open-street-map'>/
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user