Skip to content

Commit

Permalink
Refactored to move logic from view helper
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehook committed Oct 17, 2023
1 parent 9e5b383 commit 651217c
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,7 @@ def status_row(application_choice)
if @show_status
{
key: 'Status',
value: render(
ApplicationStatusTagComponent.new(
application_choice:,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
),
value: render(ApplicationStatusTagComponent.new(application_choice:)),
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module CandidateInterface
class ApplicationStatusTagComponent < ViewComponent::Base
delegate :status, to: :application_choice

def initialize(application_choice:, display_info_text: true, supplementary_statuses: [])
def initialize(application_choice:, display_info_text: true)
@application_choice = application_choice
@display_info_text = display_info_text
@supplementary_statuses = supplementary_statuses
@supplementary_statuses = application_choice.respond_to?(:supplementary_statuses) ? application_choice.supplementary_statuses : []
end

def text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ def status_row
{
key: 'Status',
value: render(
ApplicationStatusTagComponent.new(
application_choice:,
display_info_text: false,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
ApplicationStatusTagComponent.new(application_choice:, display_info_text: false),
),
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ def course_details
def application_choice_status_row
{
key: 'Status',
value: render(
ContinuousApplications::ApplicationStatusTagComponent.new(
application_choice:,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
),
value: render(ContinuousApplications::ApplicationStatusTagComponent.new(application_choice:)),
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,7 @@ def status_row(application_choice)
if @show_status
{
key: 'Status',
value: render(
ApplicationStatusTagComponent.new(
application_choice:,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
),
value: render(ApplicationStatusTagComponent.new(application_choice:)),
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
<% end %>
</td>
<td class="govuk-table__cell">
<%=
render CandidateInterface::ApplicationStatusTagComponent.new(
application_choice: application_choice,
supplementary_statuses: supplementary_statuses_for(application_choice:),
)
%>
<%= render CandidateInterface::ApplicationStatusTagComponent.new(application_choice:) %>
</td>
</tr>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ def course_details_row_value(application_choice)
def status_row(application_choice)
{
key: 'Status',
value: render(
ApplicationStatusTagComponent.new(
application_choice:,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
),
value: render(ApplicationStatusTagComponent.new(application_choice:)),
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
</span>
</h3>
<span>
<%= render(
ProviderInterface::ApplicationStatusTagComponent.new(
application_choice: application_choice,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
) %>
<%= render(ProviderInterface::ApplicationStatusTagComponent.new(application_choice:)) %>
</span>
</header>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<h1 class="govuk-heading-xl govuk-!-margin-bottom-6">
<%= application_choice.application_form.full_name %>
<span>
<%= render(
ProviderInterface::ApplicationStatusTagComponent.new(
application_choice: application_choice,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
) %>
<%= render(ProviderInterface::ApplicationStatusTagComponent.new(application_choice:)) %>
</span>
</h1>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module ProviderInterface
class ApplicationStatusTagComponent < ViewComponent::Base
delegate :status, to: :application_choice

def initialize(application_choice:, supplementary_statuses: [])
def initialize(application_choice:)
@application_choice = application_choice
@supplementary_statuses = supplementary_statuses
@supplementary_statuses = application_choice.respond_to?(:supplementary_statuses) ? application_choice.supplementary_statuses : []
end

def text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@
<ul class="app-application-card__list govuk-list govuk-list--bullet">
<% application_choices.each do |application_choice| %>
<li class="govuk-list__item govuk-body-s">
<%=
render(
SupportInterface::ApplicationStatusTagComponent.new(
status: application_choice.status,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
)
%>
<%= render(SupportInterface::ApplicationStatusTagComponent.new(application_choice:)) %>
<%= application_choice.current_course_option.course.name_and_code %> at <%= application_choice.current_course_option.provider.name %>
</li>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ def application_number_row
def status_row
{
key: 'Status',
value: render(
SupportInterface::ApplicationStatusTagComponent.new(
status: application_choice.status,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
),
value: render(SupportInterface::ApplicationStatusTagComponent.new(application_choice:)),
}.merge(status_action_link)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module SupportInterface
class ApplicationStatusTagComponent < ViewComponent::Base
def initialize(status:, supplementary_statuses: [])
@status = status
@supplementary_statuses = supplementary_statuses
def initialize(application_choice:)
@status = application_choice.status
@supplementary_statuses =
application_choice.respond_to?(:supplementary_statuses) ? application_choice.supplementary_statuses : []
end

def text
Expand Down
9 changes: 0 additions & 9 deletions app/helpers/view_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,6 @@ def application_form_path
BackLinks.application_form_path
end

def supplementary_statuses_for(application_choice:)
[].tap do |supplementary_statuses|
if application_choice.recruited? &&
RecruitedWithPendingConditions.new(application_choice:).call
supplementary_statuses << :ske_pending_conditions
end
end
end

private

def back_link_url
Expand Down
8 changes: 8 additions & 0 deletions app/models/application_choice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ def science_gcse_needed?
course.primary_course?
end

def supplementary_statuses
[].tap do |supplementary_statuses|
if recruited? && RecruitedWithPendingConditions.new(application_choice: self).call
supplementary_statuses << :ske_pending_conditions
end
end
end

private

def set_initial_status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<%= render(
ProviderInterface::ApplicationStatusTagComponent.new(
application_choice: @application_choice,
supplementary_statuses: supplementary_statuses_for(application_choice: @application_choice),
),
) %>
</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@
end

it 'renders with `ske_pending_condition` supplementary status for `recruited` applications' do
result = render_inline described_class.new(
application_choice: build_stubbed(:application_choice, status: :recruited),
supplementary_statuses: [:ske_pending_conditions],
)
application_choice = build_stubbed(:application_choice, status: :recruited)
allow(application_choice).to receive(:supplementary_statuses).and_return([:ske_pending_conditions])

result = render_inline described_class.new(application_choice:)
expect(result.text).to include('Offer confirmed')
expect(result.text).to include('SKE conditions pending')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
end

it 'renders with `ske_pending_condition` supplementary status for `recruited` applications' do
result = render_inline described_class.new(
application_choice: build_stubbed(:application_choice, status: :recruited),
supplementary_statuses: [:ske_pending_conditions],
application_choice = build_stubbed(
:application_choice,
status: :recruited,
)
allow(application_choice).to receive(:supplementary_statuses).and_return([:ske_pending_conditions])

result = render_inline described_class.new(application_choice:)
expect(result.text).to include('Recruited')
expect(result.text).to include('SKE conditions pending')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
RSpec.describe SupportInterface::ApplicationStatusTagComponent do
ApplicationStateChange.valid_states.each do |state_name|
it "renders with a #{state_name} application choice" do
render_inline described_class.new(status: state_name.to_s)
application_choice = instance_double(ApplicationChoice, status: state_name)

render_inline described_class.new(application_choice:)
end
end

it 'renders with `ske_pending_condition` supplementary status for `recruited` applications' do
result = render_inline described_class.new(
application_choice = instance_double(
ApplicationChoice,
status: :recruited,
supplementary_statuses: [:ske_pending_conditions],
)

result = render_inline described_class.new(application_choice:)
expect(result.text).to include('Recruited')
expect(result.text).to include('SKE conditions pending')
end
Expand Down
14 changes: 0 additions & 14 deletions spec/helpers/view_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,4 @@
expect(helper.formatted_percentage(1, 0)).to eq '-'
end
end

describe '#supplementary_statuses_for' do
let(:service) { instance_double(CanRecruitWithPendingConditions, call: true) }

before { allow(RecruitedWithPendingConditions).to receive(:new).and_return(service) }

it 'returns an empty array if the status is not `recruited`' do
expect(helper.supplementary_statuses_for(application_choice: build(:application_choice, :offer))).to eq([])
end

it 'returns `ske_pending_conditions` if the status is `recruited`' do
expect(helper.supplementary_statuses_for(application_choice: build(:application_choice, :recruited))).to eq([:ske_pending_conditions])
end
end
end
16 changes: 16 additions & 0 deletions spec/models/application_choice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,20 @@
end
end
end

describe '#supplementary_statuses' do
let(:service) { instance_double(RecruitedWithPendingConditions, call: true) }

before { allow(RecruitedWithPendingConditions).to receive(:new).and_return(service) }

it 'returns an empty array if the status is not `recruited`' do
application_choice = build(:application_choice, :offer)
expect(application_choice.supplementary_statuses).to eq([])
end

it 'returns `ske_pending_conditions` if the status is `recruited`' do
application_choice = build(:application_choice, :recruited)
expect(application_choice.supplementary_statuses).to eq([:ske_pending_conditions])
end
end
end

0 comments on commit 651217c

Please sign in to comment.