Skip to content

Commit

Permalink
Add test for alternate successfull flow
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Oct 1, 2024
1 parent 086c1f1 commit 312a8dc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/applications/_create_alert_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
</div>
<% 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" %>
<div class="flex items-start gap-6 px-8 py-4 mt-8 sm:pr-4 sm:py-2 sm:items-center bg-light-grey">
<%= image_tag "bookmark.svg", alt: "", class: "mt-2 sm:mt-0" %>
<div class="flex flex-col gap-4 sm:flex-row sm:justify-between grow sm:items-center">
Expand Down
32 changes: 32 additions & 0 deletions spec/features/sign_up_for_alerts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]", 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: "[email protected]")
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))

Expand Down
20 changes: 20 additions & 0 deletions spec/support/split_helper.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 312a8dc

Please sign in to comment.