From 850385a8d377b63ea9b7cf981c9d69003c9249e9 Mon Sep 17 00:00:00 2001 From: Cillian O'Ruanaidh Date: Fri, 24 May 2024 11:14:43 +0100 Subject: [PATCH] Add tests to make sure the appropriate map is loaded e.g. Open Street Map or Google --- spec/helpers/map_helper_spec.rb | 27 +++++++++++++++++++ .../steps/_details.html.haml_spec.rb | 20 ++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 spec/helpers/map_helper_spec.rb create mode 100644 spec/views/registration/steps/_details.html.haml_spec.rb diff --git a/spec/helpers/map_helper_spec.rb b/spec/helpers/map_helper_spec.rb new file mode 100644 index 0000000000..950fbeef6c --- /dev/null +++ b/spec/helpers/map_helper_spec.rb @@ -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 diff --git a/spec/views/registration/steps/_details.html.haml_spec.rb b/spec/views/registration/steps/_details.html.haml_spec.rb new file mode 100644 index 0000000000..b903b5d748 --- /dev/null +++ b/spec/views/registration/steps/_details.html.haml_spec.rb @@ -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 // + 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 /
/ + end +end