mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Making registration spec click_and_ensure assertions more generic
Assertions can be made about checking checkboxes
This commit is contained in:
@@ -26,7 +26,7 @@ feature "Registration", js: true do
|
||||
|
||||
# Done reading introduction
|
||||
page.has_content?
|
||||
click_and_ensure(:button, "Let's get started!", lambda { page.has_content? 'Woot!' })
|
||||
perform_and_ensure(:click_button, "Let's get started!", lambda { page.has_content? 'Woot!' })
|
||||
|
||||
# Filling in details
|
||||
fill_in 'enterprise_name', with: "My Awesome Enterprise"
|
||||
@@ -37,18 +37,18 @@ feature "Registration", js: true do
|
||||
fill_in 'enterprise_zipcode', with: '3070'
|
||||
select 'Australia', from: 'enterprise_country'
|
||||
select 'VIC', from: 'enterprise_state'
|
||||
click_and_ensure(:button, "Continue", lambda { page.has_content? 'Who is responsible for managing My Awesome Enterprise?' })
|
||||
perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Who is responsible for managing My Awesome Enterprise?' })
|
||||
|
||||
|
||||
# Filling in Contact Details
|
||||
fill_in 'enterprise_contact', with: 'Saskia Munroe'
|
||||
page.should have_field 'enterprise_email_address', with: user.email
|
||||
fill_in 'enterprise_phone', with: '12 3456 7890'
|
||||
click_and_ensure(:button, "Continue", lambda { page.has_content? 'Last step to add My Awesome Enterprise!' })
|
||||
perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Last step to add My Awesome Enterprise!' })
|
||||
|
||||
# Choosing a type
|
||||
click_and_ensure(:link, 'producer-panel', lambda { page.has_content? '#producer-panel.selected' } )
|
||||
click_and_ensure(:button, "Create Profile", lambda { page.has_content? 'Nice one!' })
|
||||
perform_and_ensure(:click_link, 'producer-panel', lambda { page.has_selector? '#producer-panel.selected' } )
|
||||
perform_and_ensure(:click_button, "Create Profile", lambda { page.has_content? 'Nice one!' })
|
||||
|
||||
# Enterprise should be created
|
||||
e = Enterprise.find_by_name('My Awesome Enterprise')
|
||||
@@ -63,7 +63,7 @@ feature "Registration", js: true do
|
||||
fill_in 'enterprise_abn', with: '12345'
|
||||
fill_in 'enterprise_acn', with: '54321'
|
||||
choose 'Yes' # enterprise_charges_sales_tax
|
||||
click_and_ensure(:button, "Continue", lambda { page.has_content? 'Step 1. Select Logo Image' })
|
||||
perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Step 1. Select Logo Image' })
|
||||
|
||||
# Enterprise should be updated
|
||||
e.reload
|
||||
@@ -75,10 +75,10 @@ feature "Registration", js: true do
|
||||
|
||||
# Images
|
||||
# Move from logo page
|
||||
click_and_ensure(:button, "Continue", lambda { page.has_content? 'Step 3. Select Promo Image' })
|
||||
perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Step 3. Select Promo Image' })
|
||||
|
||||
# Move from promo page
|
||||
click_and_ensure(:button, "Continue", lambda { page.has_content? 'How can people find My Awesome Enterprise online?' })
|
||||
perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'How can people find My Awesome Enterprise online?' })
|
||||
|
||||
# Filling in social
|
||||
fill_in 'enterprise_website', with: 'www.shop.com'
|
||||
@@ -86,7 +86,7 @@ feature "Registration", js: true do
|
||||
fill_in 'enterprise_linkedin', with: 'LiNkEdIn'
|
||||
fill_in 'enterprise_twitter', with: '@TwItTeR'
|
||||
fill_in 'enterprise_instagram', with: '@InStAgRaM'
|
||||
click_and_ensure(:button, "Continue", lambda { page.has_content? 'Finished!' })
|
||||
perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Finished!' })
|
||||
|
||||
# Done
|
||||
expect(page).to have_content "We've sent a confirmation email to #{user.email} if it hasn't been activated before."
|
||||
@@ -127,8 +127,7 @@ feature "Registration", js: true do
|
||||
expect(page).to have_content "Terms of Service"
|
||||
expect(page).to have_selector "input.button.primary[disabled]"
|
||||
|
||||
check 'accept_terms'
|
||||
expect(page).to_not have_selector "input.button.primary[disabled]"
|
||||
perform_and_ensure(:check, "accept_terms", lambda { page.has_no_selector? "input.button.primary[disabled]" })
|
||||
|
||||
click_button "Let's get started!"
|
||||
find("div#progress-bar").visible?.should be_true
|
||||
@@ -157,13 +156,16 @@ feature "Registration", js: true do
|
||||
expect(page).to have_content content
|
||||
end
|
||||
|
||||
def click_and_ensure(type, text, check)
|
||||
# Buttons appear to be unresponsive for a while, so keep clicking them until content appears
|
||||
def perform_and_ensure(action, *args, assertion)
|
||||
# Buttons/Links/Checkboxes appear to be unresponsive for a while
|
||||
# so keep clicking them until assertion is satified
|
||||
using_wait_time 0.5 do
|
||||
10.times do
|
||||
send("click_#{type}", text)
|
||||
break if check.call
|
||||
send(action, *args)
|
||||
return if assertion.call
|
||||
end
|
||||
# Only make it here if we have tried 10 times
|
||||
expect(assertion.call).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user