diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index b0818cd79b..0a7756d104 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -33,13 +33,16 @@ feature "Registration", js: true do # Enter Login details fill_in "Email", with: user.email fill_in "Password", with: user.password - click_login_and_ensure_content "Hi there!" + + click_button "Login" + expect(page).to have_content("Hi there!") expect(URI.parse(current_url).path).to eq registration_path # Done reading introduction page.has_content? - perform_and_ensure(:click_button, "Let's get started!", lambda { page.has_content? 'Woot!' }) + click_button "Let's get started!" + expect(page).to have_content 'Woot!' # Filling in details fill_in 'enterprise_name', with: "My Awesome Enterprise" @@ -50,18 +53,24 @@ feature "Registration", js: true do fill_in 'enterprise_zipcode', with: '3070' expect(page).to have_select('enterprise_country', options: %w(Albania Australia), selected: 'Australia') select 'Vic', from: 'enterprise_state' - perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Who is responsible for managing My Awesome Enterprise?' }) + click_button "Continue" + expect(page).to have_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' - perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Last step to add My Awesome Enterprise!' }) + click_button "Continue" + expect(page).to have_content 'Last step to add My Awesome Enterprise!' # Choosing a type - 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!' }) + click_link "producer-panel" + expect(page).to have_selector '#producer-panel.selected' + + # Next (profile is created at this point) + click_button "Create Profile" + expect(page).to have_content 'Nice one!' # Enterprise should be created e = Enterprise.find_by_name('My Awesome Enterprise') @@ -77,7 +86,8 @@ feature "Registration", js: true do fill_in 'enterprise_abn', with: '12345' fill_in 'enterprise_acn', with: '54321' choose 'Yes' # enterprise_charges_sales_tax - perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Step 1. Select Logo Image' }) + click_button "Continue" + expect(page).to have_content 'Step 1. Select Logo Image' # Enterprise should be updated e.reload @@ -89,10 +99,12 @@ feature "Registration", js: true do # Images # Move from logo page - perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Step 3. Select Promo Image' }) + click_button "Continue" + expect(page).to have_content 'Step 3. Select Promo Image' # Move from promo page - perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'How can people find My Awesome Enterprise online?' }) + click_button "Continue" + expect(page).to have_content 'How can people find My Awesome Enterprise online?' # Filling in social fill_in 'enterprise_website', with: 'www.shop.com' @@ -100,7 +112,8 @@ feature "Registration", js: true do fill_in 'enterprise_linkedin', with: 'LiNkEdIn' fill_in 'enterprise_twitter', with: '@TwItTeR' fill_in 'enterprise_instagram', with: '@InStAgRaM' - perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Finished!' }) + click_button "Continue" + expect(page).to have_content 'Finished!' # Done e.reload @@ -125,7 +138,8 @@ feature "Registration", js: true do # Enter Login details fill_in "Email", with: user.email fill_in "Password", with: user.password - click_login_and_ensure_content I18n.t('limit_reached_headline') + click_button 'Login' + expect(page).to have_content I18n.t('limit_reached_headline') end end end @@ -157,7 +171,8 @@ feature "Registration", js: true do expect(page).to have_content "Terms of Service" expect(page).to have_selector "input.button.primary[disabled]" - perform_and_ensure(:check, "accept_terms", lambda { page.has_no_selector? "input.button.primary[disabled]" }) + check "accept_terms" + expect(page).to have_no_selector "input.button.primary[disabled]" click_button "Let's get started!" expect(find("div#progress-bar")).to be_visible @@ -174,15 +189,4 @@ feature "Registration", js: true do end end end - - def click_login_and_ensure_content(content) - # Buttons appear to be unresponsive for a while, so keep clicking them until content appears - using_wait_time 1 do - 3.times do - click_button "Login" - break if page.has_selector? "div#loading", text: "Hold on a moment, we're logging you in" - end - end - expect(page).to have_content content - end end diff --git a/spec/features/consumer/shopping/products_spec.rb b/spec/features/consumer/shopping/products_spec.rb index c53027b12d..f844634a7e 100644 --- a/spec/features/consumer/shopping/products_spec.rb +++ b/spec/features/consumer/shopping/products_spec.rb @@ -32,7 +32,8 @@ feature "As a consumer I want to view products", js: true do visit shop_path select "monday", :from => "order_cycle_id" - perform_and_ensure(:click_link, product.name, lambda{ page.has_selector?('.reveal-modal')}) + click_link product.name + expect(page).to have_selector '.reveal-modal' modal_should_be_open_for product within(".reveal-modal") do @@ -47,7 +48,8 @@ feature "As a consumer I want to view products", js: true do visit shop_path select "monday", :from => "order_cycle_id" - perform_and_ensure(:click_link, product.name, lambda{ page.has_selector?('.reveal-modal')}) + click_link product.name + expect(page).to have_selector '.reveal-modal' modal_should_be_open_for product within(".reveal-modal") do diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb index a6d97d1be1..312389a0d9 100644 --- a/spec/support/request/web_helper.rb +++ b/spec/support/request/web_helper.rb @@ -138,19 +138,6 @@ module WebHelper page.execute_script(%Q{$("div.select2-result-label:contains('#{value}')").mouseup()}) end - def perform_and_ensure(action, *args, assertion) - # Buttons/Links/Checkboxes can be unresponsive for a while - # so keep clicking them until assertion is satified - using_wait_time 0.5 do - 10.times do - 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 - private def wait_for_ajax