Add tests to make sure the appropriate map is loaded e.g. Open Street Map or Google

This commit is contained in:
Cillian O'Ruanaidh
2024-05-24 11:14:43 +01:00
parent 826d9eb36d
commit 850385a8d3
2 changed files with 47 additions and 0 deletions

View 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

View 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