Browse Source

Add pending email change banner

pull/2642/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
83f152320f
  1. 19
      app/helpers/user_helper.rb
  2. 9
      app/views/users/show.html.erb
  3. 61
      spec/helpers/user_helper_spec.rb

19
app/helpers/user_helper.rb

@ -56,4 +56,23 @@ module UserHelper
user.errors.add(attribute, message) user.errors.add(attribute, message)
end end
end end
def display_pending_email_change_banner?(user)
user.unconfirmed_email.present? && user.email != user.unconfirmed_email
end
def pending_email_change_title_text(current_user, user)
if current_user == user
"You have requested to change your email address to #{user.unconfirmed_email}."
else
"There has been a request to change this user’s email address to #{user.unconfirmed_email}."
end
end
def pending_email_change_banner_text(current_user)
text = "A confirmation link has been sent to the new email address. The current email will continue to work until the change is confirmed."
text += " Deactivating this user will cancel the email change request." if current_user.support?
text
end
end end

9
app/views/users/show.html.erb

@ -11,6 +11,15 @@
<% end %> <% end %>
<% end %> <% end %>
<% if display_pending_email_change_banner?(@user) %>
<%= govuk_notification_banner(title_text: "Important") do %>
<p class="govuk-notification-banner__heading govuk-!-width-full" style="max-width: fit-content">
<%= pending_email_change_title_text(current_user, @user) %>
<p>
<%= pending_email_change_banner_text(current_user) %>
<% end %>
<% end %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l"> <h1 class="govuk-heading-l">

61
spec/helpers/user_helper_spec.rb

@ -105,6 +105,32 @@ RSpec.describe UserHelper do
end end
end end
describe "display_pending_email_change_banner?" do
context "when the user doesn't have an unconfirmed email" do
let(:user) { FactoryBot.create(:user, :data_provider, unconfirmed_email: nil) }
it "does not display pending email change banner" do
expect(display_pending_email_change_banner?(user)).to be false
end
end
context "when the user doesn't has the same unconfirmed email as current email" do
let(:user) { FactoryBot.create(:user, :data_provider, unconfirmed_email: "updated_email@example.com", email: "updated_email@example.com") }
it "does not display pending email change banner" do
expect(display_pending_email_change_banner?(user)).to be false
end
end
context "when the user doesn't has a different unconfirmed email" do
let(:user) { FactoryBot.create(:user, :data_provider, unconfirmed_email: "updated_email@example.com", email: "old_email@example.com") }
it "displays pending email change banner" do
expect(display_pending_email_change_banner?(user)).to be true
end
end
end
describe "organisation_change_confirmation_warning" do describe "organisation_change_confirmation_warning" do
context "when user owns logs" do context "when user owns logs" do
before do before do
@ -147,4 +173,39 @@ RSpec.describe UserHelper do
end end
end end
end end
describe "pending_email_change_title_text" do
let(:user) { FactoryBot.create(:user, :data_provider, unconfirmed_email: "updated_email@example.com", email: "old_email@example.com") }
let(:current_user) { FactoryBot.create(:user, :support) }
context "when viewing own profile" do
it "returns the correct text" do
expect(pending_email_change_title_text(user, user)).to eq("You have requested to change your email address to updated_email@example.com.")
end
end
context "when viewing another user's profile" do
it "returns the correct text" do
expect(pending_email_change_title_text(current_user, user)).to eq("There has been a request to change this user’s email address to updated_email@example.com.")
end
end
end
describe "pending_email_change_banner_text" do
context "with non support user" do
let(:user) { FactoryBot.create(:user, :data_provider) }
it "returns the correct text" do
expect(pending_email_change_banner_text(user)).to eq("A confirmation link has been sent to the new email address. The current email will continue to work until the change is confirmed.")
end
end
context "with support user" do
let(:user) { FactoryBot.create(:user, :support) }
it "returns the correct text" do
expect(pending_email_change_banner_text(user)).to eq("A confirmation link has been sent to the new email address. The current email will continue to work until the change is confirmed. Deactivating this user will cancel the email change request.")
end
end
end
end end

Loading…
Cancel
Save