Simplify email confirmation directive

Making better use of Angular features.
Adding a spec for this functionality.
This commit is contained in:
Maikel Linke
2018-06-20 14:40:48 +10:00
parent fbe2f7ab4c
commit 43883d1ab4
4 changed files with 25 additions and 13 deletions

View File

@@ -1,19 +1,17 @@
angular.module("admin.users").directive "resendUserEmailConfirmation", ($http) ->
template: "{{ 'js.admin.resend_user_email_confirmation.' + status | t }}"
scope:
email: "@resendUserEmailConfirmation"
link: (scope, element, attrs) ->
sent = false
text = element.text()
sending = " " + t "js.admin.resend_user_email_confirmation.sending"
done = " " + t "js.admin.resend_user_email_confirmation.done"
failed = " " + t "js.admin.resend_user_email_confirmation.failed"
scope.status = "resend"
element.bind "click", ->
return if sent
element.text(text + sending)
scope.status = "sending"
$http.post("/user/spree_user/confirmation", {spree_user: {email: scope.email}}).success (data) ->
sent = true
element.addClass "action--disabled"
element.text text + done
scope.status = "done"
.error (data) ->
element.text text + failed
scope.status = "failed"

View File

@@ -1,4 +1,3 @@
%p.alert-box{"ng-app" => "admin.users"}
= t(".confirmation_pending", address: @user.email)
%a{"resend-user-email-confirmation" => @user.email}
= t(".resend")
%a{"resend-user-email-confirmation" => @user.email}

View File

@@ -2436,9 +2436,10 @@ See the %{link} to find out more about %{sitename}'s features and to start using
new_tag_rule_dialog:
select_rule_type: "Select a rule type:"
resend_user_email_confirmation:
sending: "..."
done: "done ✓"
failed: "failed ✗"
resend: "Resend"
sending: "Resend..."
done: "Resend done ✓"
failed: "Resend failed ✗"
out_of_stock:
reduced_stock_available: Reduced stock available
out_of_stock_text: >
@@ -2592,7 +2593,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using
users:
email_confirmation:
confirmation_pending: "Email confirmation is pending. We've sent a confirmation email to %{address}."
resend: "Resend"
variants:
autocomplete:
producer_name: Producer

View File

@@ -24,5 +24,20 @@ feature "Managing users" do
expect(page).to have_text "Email confirmation is pending"
end
end
describe "resending confirmation email", js: true do
let(:user) { create :user, confirmed_at: nil }
it "displays success" do
visit spree.edit_admin_user_path user
# The `a` element doesn't have an href, so we can't use click_link.
find("a", text: "Resend").click
expect(page).to have_text "Resend done"
# And it's successful. (testing it here for reduced test time)
expect(Delayed::Job.last.payload_object.method_name).to eq :send_confirmation_instructions_without_delay
end
end
end
end