Browse Source

Merge branch 'main' into CLDC-3618-Support-user-view-bulk-uploads

pull/2653/head
Manny Dinssa 2 years ago committed by GitHub
parent
commit
d4621e4eb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  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)
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? || current_user.data_coordinator?
text
end
end

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

@ -11,6 +11,15 @@
<% 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-column-two-thirds">
<h1 class="govuk-heading-l">

61
spec/helpers/user_helper_spec.rb

@ -105,6 +105,32 @@ RSpec.describe UserHelper do
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 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 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
context "when user owns logs" do
before do
@ -147,4 +173,39 @@ RSpec.describe UserHelper do
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 provider 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

Loading…
Cancel
Save