Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recruit with pending conditions status tags #8665

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
@@ -1,4 +1,7 @@
<%= govuk_tag(text: text, colour: colour) %>
<% supplementary_tags do |supplementary_tag_text, supplementary_tag_colour| %>
<%= govuk_tag(text: supplementary_tag_text, colour: supplementary_tag_colour) %>
<% end %>

<% if @display_info_text %>
<% if @application_choice.application_not_sent? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ApplicationStatusTagComponent < ViewComponent::Base
def initialize(application_choice:, display_info_text: true)
@application_choice = application_choice
@display_info_text = display_info_text
@supplementary_statuses = application_choice.respond_to?(:supplementary_statuses) ? application_choice.supplementary_statuses : []
end

def text
Expand Down Expand Up @@ -36,8 +37,27 @@ def colour
end
end

def supplementary_tags
@supplementary_statuses.each do |supplementary_status|
yield supplementary_tag_text(supplementary_status), supplementary_tag_colour(supplementary_status)
end
end

private

def supplementary_tag_text(supplementary_status)
I18n.t!("supplementary_application_states.#{supplementary_status}.name")
end

def supplementary_tag_colour(supplementary_status)
case supplementary_status.to_s
when 'ske_pending_conditions'
'blue'
else
raise "You need to define a colour for the #{supplementary_status} supplementary state"
end
end

attr_reader :application_choice
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def status_row

{
key: 'Status',
value: render(ApplicationStatusTagComponent.new(application_choice:, display_info_text: false)),
value: render(
ApplicationStatusTagComponent.new(application_choice:, display_info_text: false),
),
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<% end %>
</td>
<td class="govuk-table__cell">
<%= render CandidateInterface::ApplicationStatusTagComponent.new(application_choice: 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 @@ -6,7 +6,9 @@
<%= application_choice.id %>
</span>
</h3>
<%= render ProviderInterface::ApplicationStatusTagComponent.new(application_choice: application_choice) %>
<span>
<%= render(ProviderInterface::ApplicationStatusTagComponent.new(application_choice:)) %>
</span>
</header>

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

<% if show_inset_text? -%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<%= govuk_tag(text: text, colour: colour) %>
<% supplementary_tags do |supplementary_tag_text, supplementary_tag_colour| %>
<%= govuk_tag(text: supplementary_tag_text, colour: supplementary_tag_colour) %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ApplicationStatusTagComponent < ViewComponent::Base

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

def text
Expand Down Expand Up @@ -33,8 +34,27 @@ def colour
end
end

def supplementary_tags
@supplementary_statuses.each do |supplementary_status|
yield supplementary_tag_text(supplementary_status), supplementary_tag_colour(supplementary_status)
end
end

private

def supplementary_tag_text(supplementary_status)
I18n.t!("supplementary_application_states.#{supplementary_status}.name")
end

def supplementary_tag_colour(supplementary_status)
case supplementary_status.to_s
when 'ske_pending_conditions'
'blue'
else
raise "You need to define a colour for the #{supplementary_status} supplementary state"
end
end

attr_reader :application_choice
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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) %>
<%= 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,7 +41,7 @@ def application_number_row
def status_row
{
key: 'Status',
value: render(SupportInterface::ApplicationStatusTagComponent.new(status: application_choice.status)),
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 +1,4 @@
<%= govuk_tag(text: text, colour: colour) %>
<% supplementary_tags do |supplementary_tag_text, supplementary_tag_colour| %>
<%= govuk_tag(text: supplementary_tag_text, colour: supplementary_tag_colour) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module SupportInterface
class ApplicationStatusTagComponent < ViewComponent::Base
def initialize(status:)
@status = status
def initialize(application_choice:)
@status = application_choice.status
@supplementary_statuses =
application_choice.respond_to?(:supplementary_statuses) ? application_choice.supplementary_statuses : []
end

def text
Expand All @@ -26,5 +28,26 @@ def colour
raise "You need to define a colour for the #{@status} state"
end
end

def supplementary_tags
@supplementary_statuses.each do |supplementary_status|
yield supplementary_tag_text(supplementary_status), supplementary_tag_colour(supplementary_status)
end
end

private

def supplementary_tag_text(supplementary_status)
I18n.t!("supplementary_application_states.#{supplementary_status}.name")
end

def supplementary_tag_colour(supplementary_status)
case supplementary_status.to_s
when 'ske_pending_conditions'
'blue'
else
raise "You need to define a colour for the #{supplementary_status} supplementary state"
end
end
end
end
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
31 changes: 3 additions & 28 deletions app/services/can_recruit_with_pending_conditions.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
class CanRecruitWithPendingConditions
attr_accessor :application_choice

def initialize(application_choice:)
self.application_choice = application_choice
end

class CanRecruitWithPendingConditions < HasPendingSkeConditionsOnly
def call
feature_flag_enabled? &&
application_has_offer? &&
offer_has_pending_ske_conditions? &&
all_non_ske_conditions_met? &&
application_choice.pending_conditions? &&
pending_ske_conditions_only? &&
provider_is_scitt? &&
course_is_within_time_limit?
end

private

def feature_flag_enabled?
FeatureFlag.active?(:recruit_with_pending_conditions)
end

def application_has_offer?
application_choice.offer.present?
end

def offer_has_pending_ske_conditions?
application_choice.offer.ske_conditions.any?(&:pending?)
end

def all_non_ske_conditions_met?
non_ske_conditions = application_choice.offer.conditions - application_choice.offer.ske_conditions
non_ske_conditions.all?(&:met?)
end

def provider_is_scitt?
application_choice.provider&.scitt?
end
Expand Down
35 changes: 35 additions & 0 deletions app/services/has_pending_ske_conditions_only.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class HasPendingSkeConditionsOnly
attr_accessor :application_choice

def initialize(application_choice:)
self.application_choice = application_choice
end

def pending_ske_conditions_only?
feature_flag_enabled? &&
application_has_offer? &&
offer_has_pending_ske_conditions? &&
all_non_ske_conditions_met?
end

private

def feature_flag_enabled?
FeatureFlag.active?(:recruit_with_pending_conditions)
end

def application_has_offer?
application_choice.offer.present?
end

def offer_has_pending_ske_conditions?
application_choice.offer.conditions.any? do |condition|
condition.is_a?(SkeCondition) && condition.pending?
end
end

def all_non_ske_conditions_met?
non_ske_conditions = application_choice.offer.conditions - application_choice.offer.ske_conditions
non_ske_conditions.all?(&:met?)
end
end
5 changes: 5 additions & 0 deletions app/services/recruited_with_pending_conditions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RecruitedWithPendingConditions < HasPendingSkeConditionsOnly
def call
application_choice.recruited? && pending_ske_conditions_only?
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

<h1 class="govuk-heading-xl govuk-!-margin-bottom-6">
<%= @application_choice.application_form.full_name %>
<%= render(ProviderInterface::ApplicationStatusTagComponent.new(application_choice: @application_choice)) %>
<%= render(
ProviderInterface::ApplicationStatusTagComponent.new(
application_choice: @application_choice,
),
) %>
</h1>

<%= form_with(
Expand Down
5 changes: 5 additions & 0 deletions config/locales/application_states.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ en:
emails:
- candidate_mailer-deferred_offer_reminder

supplementary_application_states:
ske_pending_conditions:
name: SKE conditions pending
description: Provider is waiting for the candidate to meet one or more SKE conditions.

events:
unsubmitted-send_to_provider:
name: Candidate submits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,13 @@
end
end
end

it 'renders with `ske_pending_condition` supplementary status for `recruited` applications' do
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
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,16 @@
render_inline described_class.new(application_choice: build_stubbed(:application_choice, status: state_name))
end
end

it 'renders with `ske_pending_condition` supplementary status for `recruited` applications' do
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
end
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def row_link_selector(row_number)
end
end

context 'when application is in condititions_pending state but only SKE conditions are pending' do
context 'when application is in conditions_pending state but only SKE conditions are pending' do
let(:application_choice) { build_stubbed(:application_choice, :accepted) }

before { allow(CanRecruitWithPendingConditions).to receive(:new).and_return(instance_double(CanRecruitWithPendingConditions, call: true)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@
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
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
end
2 changes: 2 additions & 0 deletions spec/factories/offer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
end

trait :with_ske_conditions do
application_choice { association(:application_choice, :pending_conditions, offer: instance) }

conditions {
[
build(:text_condition),
Expand Down
Loading