Skip to content

Commit

Permalink
Implemented UI for Unsubscribing Candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
dcyoung-dev committed Jan 9, 2025
1 parent c2c147f commit 26ee4ba
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class SupportInterface::Candidates::BulkUnsubscribesController < SupportInterface::SupportInterfaceController
def new
@bulk_unsubscribe_form = SupportInterface::Candidates::BulkUnsubscribeForm.new
end

def create
@bulk_unsubscribe_form = SupportInterface::Candidates::BulkUnsubscribeForm.new(bulk_unsubscribe_params)

if @bulk_unsubscribe_form.save
flash[:success] = 'Candidates unsubscribed'
redirect_to support_interface_path
else
render :new
end
end

private

def bulk_unsubscribe_params
params.expect(bulk_unsubscribe: [:email_addresses])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{ name: 'Applications', url: support_interface_applications_path, current: local_assigns[:current] == 'Applications' },
{ name: 'Candidate accounts', url: support_interface_candidates_path, current: local_assigns[:current] == 'Candidates' },
{ name: 'Duplicate candidate matches', url: support_interface_duplicate_matches_path, current: local_assigns[:current] == 'Duplicate candidate matches' },
{ name: 'Bulk unsubscribe candidates', url: new_support_interface_bulk_unsubscribe_path, current: local_assigns[:current] == 'Bulk unsubscribe candidates' },
]) %>

<h2 class="govuk-visually-hidden"><%= title %></h2>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<% content_for :browser_title, "Bulk unsubscribe candidates" %>

<%= render 'support_interface/candidates/candidates_navigation', title: 'Bulk unsubscribe candidates' %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @bulk_unsubscribe_form, scope: :bulk_unsubscribe, url: support_interface_bulk_unsubscribe_path do |form| %>
<%= form.govuk_error_summary %>

<h1 class='govuk-heading-l'>Unsubscribe candidates</h1>

<%= form.govuk_text_area :email_addresses,
rows: 5,
label: { text: 'Email addresses', size: 's' },
hint: { text: 'Enter email address to be unsubscribed, use a new line for each email address. You can also copy and paste directly from a spreadsheet.' } %>

<%= form.govuk_submit 'Continue' %>
<% end %>
</div>
</div>
4 changes: 4 additions & 0 deletions config/routes/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@

get '/candidates' => 'candidates#index'

scope path: '/candidates' do
resource :bulk_unsubscribe, only: %i[new create], path: '/bulk-unsubscribe', module: :candidates
end

scope path: '/candidates/:candidate_id' do
get '/' => 'candidates#show', as: :candidate
post '/hide' => 'candidates#hide_in_reporting', as: :hide_candidate
Expand Down
59 changes: 59 additions & 0 deletions spec/system/support_interface/bulk_unsubscribe_candidates_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'rails_helper'

RSpec.describe 'bulk unsubscribe Candidates' do
include DfESignInHelpers

scenario 'bulk unsubscribe candidates', :with_audited do
given_i_am_a_support_user
and_there_are_candidates_in_the_system
and_i_visit_the_bulk_unsubscribe_page

when_i_click_continue
then_i_see_bulk_unsubscribe_form_validation_error

when_i_enter_the_email_addresses
and_i_click_continue
then_i_can_see_candidates_are_unsubscribed
end

private

def given_i_am_a_support_user
sign_in_as_support_user
end

def and_there_are_candidates_in_the_system
@candidate_1 = create(:candidate, email_address: 'candidate_1@email.address')
@candidate_2 = create(:candidate, email_address: 'candidate_2@email.address')
@candidate_3 = create(:candidate, email_address: 'candidate_3@email.address')
end

def and_i_visit_the_bulk_unsubscribe_page
visit support_interface_path
click_on 'Bulk unsubscribe candidates'
end

def when_i_click_continue
click_on 'Continue'
end

alias_method :and_i_click_continue, :when_i_click_continue

def then_i_see_bulk_unsubscribe_form_validation_error
expect(page).to have_content("can't be blank")
end

def when_i_enter_the_email_addresses
fill_in 'Email addresses', with: '
candidate_1@email.address
candidate_3@email.address
'
end

def then_i_can_see_candidates_are_unsubscribed
expect(page).to have_content('Candidates unsubscribed')
expect(@candidate_1.reload).to be_unsubscribed_from_emails
expect(@candidate_2.reload).not_to be_unsubscribed_from_emails
expect(@candidate_3.reload).to be_unsubscribed_from_emails
end
end

0 comments on commit 26ee4ba

Please sign in to comment.