Skip to content

Commit 665c5cf

Browse files
committed
Improvements and testing
1 parent 5c14da2 commit 665c5cf

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

app/view_objects/assessor_interface/assessment_section_view_object.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def notes_placeholder_key_for(failure_reason:)
4747
build_key(failure_reason, "placeholder")
4848
end
4949

50+
def selected_work_histories_for(failure_reason:)
51+
selected_failure_reasons.find_by(key: failure_reason)&.work_histories
52+
end
53+
5054
def show_form?
5155
return true if preliminary?
5256

app/views/assessor_interface/assessment_sections/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
hint: { text: t(view_object.notes_hint_key_for(failure_reason:)) },
8383
placeholder: t(view_object.notes_placeholder_key_for(failure_reason:)),
8484
disabled: view_object.disable_form? %>
85-
<% if FailureReasons.chooses_work_history?(failure_reason) || view_object.selected_failure_reasons.find_by(key: failure_reason)&.work_histories.present? %>
85+
<% if FailureReasons.chooses_work_history?(failure_reason) || view_object.selected_work_histories_for(failure_reason:).present? %>
8686
<%= f.govuk_check_boxes_fieldset :"#{failure_reason}_work_history_checked", legend: { size: "s" } do %>
8787
<% view_object.work_histories.each do |work_history| %>
8888
<%= f.govuk_check_box :"#{failure_reason}_work_history_checked", work_history.id, label: { text: work_history.school_name }, disabled: view_object.disable_form? %>

app/views/assessor_interface/further_information_requests/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<h1 class="govuk-heading-xl">Check the information you’re asking the applicant for</h1>
55

66
<% @further_information_request.items.group_by(&:failure_reason_key).each do |failure_reason_key, items| %>
7-
<% if failure_reason_key == FailureReasons::UNRECOGNISED_REFERENCES %>
7+
<% if FailureReasons.chooses_work_history?(failure_reason_key) %>
88
<section class="app-further-information-request-item">
99
<h2 class="govuk-heading-m">Reason for request</h2>
1010
<% if items.size == 1 %>

spec/system/assessor_interface/checking_submitted_details_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def application_form
551551
:work_history,
552552
assessment: application_form.assessment,
553553
failure_reasons: %w[
554-
school_details_cannot_be_verified
554+
unrecognised_references
555555
identification_document_expired
556556
],
557557
)

spec/view_objects/assessor_interface/assessment_section_view_object_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,52 @@
199199
end
200200
end
201201

202+
describe "#selected_work_histories_for" do
203+
subject(:selected_work_histories_for) do
204+
view_object.selected_work_histories_for(failure_reason:)
205+
end
206+
207+
let(:application_form) do
208+
create(:application_form, :with_work_history, region:)
209+
end
210+
let(:failure_reason) { FailureReasons::UNRECOGNISED_REFERENCES }
211+
let(:work_histories) { application_form.work_histories }
212+
let(:selected_failure_reason) do
213+
create :selected_failure_reason,
214+
key: failure_reason,
215+
assessment_section:,
216+
work_histories:
217+
end
218+
219+
before do
220+
selected_failure_reason
221+
end
222+
223+
it "returns the work histories attached to the selected failure reason" do
224+
expect(selected_work_histories_for).to eq(application_form.work_histories)
225+
end
226+
227+
context "when there is no work history attached" do
228+
let(:work_histories) { [] }
229+
230+
it "returns the empty" do
231+
expect(selected_work_histories_for).to be_empty
232+
end
233+
end
234+
235+
context "when the selected failure reason is not on assessment section" do
236+
let(:selected_failure_reason) do
237+
create :selected_failure_reason,
238+
key: FailureReasons::SCHOOL_DETAILS_CANNOT_BE_VERIFIED,
239+
assessment_section:
240+
end
241+
242+
it "returns nil" do
243+
expect(selected_work_histories_for).to be_nil
244+
end
245+
end
246+
end
247+
202248
describe "#show_form?" do
203249
subject(:show_form?) { view_object.show_form? }
204250

0 commit comments

Comments
 (0)