From 1297520051be86daf2468f9241cc2748672d2137 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 9 May 2014 14:13:39 +1000 Subject: [PATCH] Authentication steps test --- .../javascripts/templates/login.html.haml | 3 ++ .../javascripts/templates/signup.html.haml | 5 ++- spec/features/consumer/authentication_spec.rb | 40 +++++++++++++++++-- spec/support/request/ui_component_helper.rb | 27 +++++++++++++ 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/templates/login.html.haml b/app/assets/javascripts/templates/login.html.haml index 680edd86d7..992dfd265a 100644 --- a/app/assets/javascripts/templates/login.html.haml +++ b/app/assets/javascripts/templates/login.html.haml @@ -12,6 +12,7 @@ %label{for: "email"} Email %input.title.input-text{name: "email", type: "email", + id: "email", tabindex: 1, "ng-model" => "spree_user.email"} .row @@ -19,6 +20,7 @@ %label{for: "password"} Password %input.title.input-text{name: "password", type: "password", + id: "password", autocomplete: "off", tabindex: 2, "ng-model" => "spree_user.password"} @@ -26,6 +28,7 @@ .large-12.columns %input{name: "remember_me", type: "checkbox", + id: "remember_me", value: "1", "ng-model" => "spree_user.remember_me"} %label{for: "remember_me"} Remember Me diff --git a/app/assets/javascripts/templates/signup.html.haml b/app/assets/javascripts/templates/signup.html.haml index 00040579af..db066685f1 100644 --- a/app/assets/javascripts/templates/signup.html.haml +++ b/app/assets/javascripts/templates/signup.html.haml @@ -8,6 +8,7 @@ %label{for: "email"} Your email %input.title.input-text{name: "email", type: "email", + id: "email", tabindex: 1, "ng-model" => "spree_user.email"} %span.error{"ng-show" => "errors.email != null"} @@ -17,6 +18,7 @@ %label{for: "password"} Choose a password %input.title.input-text{name: "password", type: "password", + id: "password", autocomplete: "off", tabindex: 2, "ng-model" => "spree_user.password"} @@ -24,9 +26,10 @@ {{ errors.password.join(' ') }} .row .large-12.columns - %label{for: "password"} Confirm password + %label{for: "password_confirmation"} Confirm password %input.title.input-text{name: "password_confirmation", type: "password", + id: "password_confirmation", autocomplete: "off", tabindex: 2, "ng-model" => "spree_user.password_confirmation"} diff --git a/spec/features/consumer/authentication_spec.rb b/spec/features/consumer/authentication_spec.rb index 71e9b4c727..7ad5611aef 100644 --- a/spec/features/consumer/authentication_spec.rb +++ b/spec/features/consumer/authentication_spec.rb @@ -12,11 +12,47 @@ feature "Authentication", js: true do describe "as large" do before do browse_as_large + open_login_modal end scenario "showing login" do - open_login_modal page.should have_login_modal end + + scenario "failing to login" do + fill_in "Email", with: user.email + click_login_button + page.should have_content "Invalid email or password" + end + + scenario "logging in successfully" do + fill_in "Email", with: user.email + fill_in "Password", with: user.password + click_login_button + page.should be_logged_in_as user + end + + describe "signing up" do + before do + ActionMailer::Base.deliveries.clear + select_login_tab "Sign up" + end + scenario "Failing to sign up because password is too short" do + fill_in "Email", with: "test@foo.com" + fill_in "Choose a password", with: "short" + click_signup_button + page.should have_content "too short" + end + + scenario "Signing up successfully" do + fill_in "Email", with: "test@foo.com" + fill_in "Choose a password", with: "test12345" + fill_in "Confirm password", with: "test12345" + click_signup_button + page.should have_content "Welcome! You have signed up successfully" + page.should be_logged_in_as "test@foo.com" + ActionMailer::Base.deliveries.last.subject.should =~ /Welcome to/ + end + end end describe "as medium" do before do @@ -24,9 +60,7 @@ feature "Authentication", js: true do end scenario "showing login" do open_off_canvas - binding.pry open_login_modal - save_screenshot "/Users/willmarshall/Desktop/modal.png", :full => true page.should have_login_modal end end diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb index f15723e2ac..294259f36b 100644 --- a/spec/support/request/ui_component_helper.rb +++ b/spec/support/request/ui_component_helper.rb @@ -8,6 +8,20 @@ module UIComponentHelper page.driver.resize(1280, 800) end + def click_login_button + click_button "Log in" + end + + def click_signup_button + click_button "Sign up now" + end + + def select_login_tab(text) + within ".login-modal" do + find("a", text: text).click + end + end + def open_login_modal find("a", text: "LOG IN").click end @@ -19,6 +33,19 @@ module UIComponentHelper def have_login_modal have_selector ".login-modal" end + + def be_logged_in_as(user_or_email) + if user_or_email.is_a? Spree::User + have_content user_or_email.email + else + have_content user_or_email + end + end + + def be_logged_out + have_content "LOG IN" + end + def open_active_table_row find("hub:first-child .active_table_row:first-child").click() end