Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SelectedEmailController < ApplicationController
def edit
@identity = identity
@select_email_form = build_select_email_form
@can_add_email = EmailPolicy.new(current_user).can_add_email?
analytics.sp_select_email_visited
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/sign_up/select_email_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def show
@user_emails = user_emails
@last_sign_in_email_address = last_email
@select_email_form = build_select_email_form
@can_add_email = EmailPolicy.new(current_user).can_add_email?
analytics.sp_select_email_visited(needs_completion_screen_reason:)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
<%= f.submit(t('help_text.requested_attributes.select_email_link'), class: 'margin-top-1') %>
<% end %>

<%= render ButtonComponent.new(
url: add_email_path(in_select_email_flow: true),
outline: true,
big: true,
wide: true,
class: 'margin-top-2',
).with_content(t('account.index.email_add')) %>
<% if @can_add_email %>
<%= render ButtonComponent.new(
url: add_email_path(in_select_email_flow: true),
outline: true,
big: true,
wide: true,
class: 'margin-top-2',
).with_content(t('account.index.email_add')) %>
<% end %>

<% c.with_footer { link_to t('forms.buttons.back'), account_connected_accounts_path } %>
<% end %>
16 changes: 9 additions & 7 deletions app/views/sign_up/select_email/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
<%= f.submit t('help_text.requested_attributes.select_email_link'), class: 'margin-top-1' %>
<% end %>

<%= render ButtonComponent.new(
url: add_email_path(in_select_email_flow: true),
outline: true,
big: true,
wide: true,
class: 'margin-top-2',
).with_content(t('account.index.email_add')) %>
<% if @can_add_email %>
<%= render ButtonComponent.new(
url: add_email_path(in_select_email_flow: true),
outline: true,
big: true,
wide: true,
class: 'margin-top-2',
).with_content(t('account.index.email_add')) %>
<% end %>

<%= render PageFooterComponent.new do %>
<%= link_to t('forms.buttons.back'), sign_up_completed_path %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

expect(assigns(:identity)).to be_kind_of(ServiceProviderIdentity)
expect(assigns(:select_email_form)).to be_kind_of(SelectEmailForm)
expect(assigns(:can_add_email)).to eq(true)
end

context 'with an identity parameter not associated with the user' do
Expand Down Expand Up @@ -59,6 +60,18 @@
expect(response).to be_not_found
end
end

context 'when users has max number of emails' do
before do
allow(user).to receive(:email_address_count).and_return(2)
allow(IdentityConfig.store).to receive(:max_emails_per_account).and_return(2)
end

it 'can add email variable set to false' do
response
expect(assigns(:can_add_email)).to eq(false)
end
end
end

describe '#update' do
Expand Down
13 changes: 13 additions & 0 deletions spec/controllers/sign_up/select_email_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
expect(assigns(:user_emails)).to all be_kind_of(EmailAddress)
expect(assigns(:last_sign_in_email_address)).to be_kind_of(String)
expect(assigns(:select_email_form)).to be_kind_of(SelectEmailForm)
expect(assigns(:can_add_email)).to eq(true)
end

context 'with selected email to share feature disabled' do
Expand All @@ -69,6 +70,18 @@
expect(response).to redirect_to(sign_up_completed_path)
end
end

context 'when users has max number of emails' do
before do
allow(user).to receive(:email_address_count).and_return(2)
allow(IdentityConfig.store).to receive(:max_emails_per_account).and_return(2)
end

it 'can add email variable set to false' do
response
expect(assigns(:can_add_email)).to eq(false)
end
end
end

describe '#create' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
allow(view).to receive(:current_user).and_return(user)
@identity = identity
@select_email_form = SelectEmailForm.new(user:, identity:)
@can_add_email = true
end

it 'renders introduction text' do
Expand All @@ -35,4 +36,24 @@
expect(inputs).to be_logically_grouped(t('titles.select_email'))
expect(rendered).to have_content(identity.display_name)
end

it 'renders a button to allow users to add email' do
expect(rendered).to have_link(
t('account.index.email_add'),
href: add_email_path(in_select_email_flow: true),
)
end

context 'if user has reached max number of emails' do
before do
@can_add_email = false
end

it 'does not render add email button' do
expect(rendered).not_to have_link(
t('account.index.email_add'),
href: add_email_path(in_select_email_flow: true),
)
end
end
end
21 changes: 21 additions & 0 deletions spec/views/sign_up/select_email/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@user_emails = user.confirmed_email_addresses
@select_email_form = SelectEmailForm.new(user:)
@sp_name = 'Test Service Provider'
@can_add_email = true
end

it 'renders introduction text' do
Expand All @@ -24,4 +25,24 @@
expect(rendered).to include('michael.motorist@email.com')
expect(rendered).to include('michael.motorist2@email.com')
end

it 'renders a button to allow users to add email' do
expect(rendered).to have_link(
t('account.index.email_add'),
href: add_email_path(in_select_email_flow: true),
)
end

context 'if user has reached max number of emails' do
before do
@can_add_email = false
end

it 'does not render add email button' do
expect(rendered).not_to have_link(
t('account.index.email_add'),
href: add_email_path(in_select_email_flow: true),
)
end
end
end