diff --git a/app/views/applications/_create_alert_form.html.erb b/app/views/applications/_create_alert_form.html.erb
index dafc91d8e..f223dd419 100644
--- a/app/views/applications/_create_alert_form.html.erb
+++ b/app/views/applications/_create_alert_form.html.erb
@@ -11,7 +11,7 @@
<% else %>
- <% if ab_test("logged_out_alert_flow_order", "sign_in_create_alert", "create_alert_sign_in") == "create_alert_sign_in" %>
+ <% if ab_test(:logged_out_alert_flow_order, "sign_in_create_alert", "create_alert_sign_in") == "create_alert_sign_in" %>
<%= image_tag "bookmark.svg", alt: "", class: "mt-2 sm:mt-0" %>
diff --git a/spec/features/sign_up_for_alerts_spec.rb b/spec/features/sign_up_for_alerts_spec.rb
index f16eeaa71..eb1b24946 100644
--- a/spec/features/sign_up_for_alerts_spec.rb
+++ b/spec/features/sign_up_for_alerts_spec.rb
@@ -119,6 +119,38 @@
expect(page).to have_content("You succesfully added a new alert for 24 Bruce Rd, Glenbrook NSW 2773")
end
+ it "when via the homepage with a pre-existing user but not logged in in the alternate flow" do
+ use_ab_test logged_out_alert_flow_order: "create_alert_sign_in"
+
+ create(:geocoded_application, address: "26 Bruce Rd, Glenbrook NSW 2773", lat: -33.772812, lng: 150.624252, lonlat: RGeo::Geographic.spherical_factory(srid: 4326).point(150.624252, -33.772812))
+ user = create(:confirmed_user, email: "example@example.com", password: "mypassword")
+ sign_in user
+ visit root_path
+ sign_out user
+
+ visit root_path
+ fill_in("Street address", with: "24 Bruce Rd, Glenbrook")
+ within("form") do
+ click_on("Search")
+ end
+
+ expect(page).to have_content("Search results")
+ expect(page).to have_content("Save this search as an email alert")
+ click_on("Save", match: :first)
+
+ expect(page).to have_content("You'll receive email alerts when new applications match this search")
+ click_on("Sign in")
+
+ expect(page).to have_content("Sign in to save this search")
+ expect(page).to have_content("Applications within 2 km of 24 Bruce Rd, Glenbrook")
+
+ fill_in("Your email", with: "example@example.com")
+ fill_in("Password", with: "mypassword")
+ click_on("Sign in")
+
+ expect(page).to have_content("You succesfully signed in and added a new alert for 24 Bruce Rd, Glenbrook NSW 2773")
+ end
+
it "when via the homepage but not yet have an account" do
create(:geocoded_application, address: "26 Bruce Rd, Glenbrook NSW 2773", lat: -33.772812, lng: 150.624252, lonlat: RGeo::Geographic.spherical_factory(srid: 4326).point(150.624252, -33.772812))
diff --git a/spec/support/split_helper.rb b/spec/support/split_helper.rb
new file mode 100644
index 000000000..11ff3d928
--- /dev/null
+++ b/spec/support/split_helper.rb
@@ -0,0 +1,20 @@
+module SplitHelper
+ # Force a specific experiment alternative to always be returned:
+ # use_ab_test(signup_form: "single_page")
+ #
+ # Force alternatives for multiple experiments:
+ # use_ab_test(signup_form: "single_page", pricing: "show_enterprise_prices")
+ #
+ def use_ab_test(alternatives_by_experiment)
+ allow_any_instance_of(Split::Helper).to receive(:ab_test) do |_receiver, experiment, &block|
+ variant = alternatives_by_experiment.fetch(experiment) { |key| raise "Unknown experiment '#{key}'" }
+ block.call(variant) unless block.nil?
+ variant
+ end
+ end
+end
+
+# Make the `use_ab_test` method available to all specs:
+RSpec.configure do |config|
+ config.include SplitHelper
+end