Skip to content

Commit

Permalink
Merge pull request #2116 from DFE-Digital/fix-timeline-events
Browse files Browse the repository at this point in the history
Fix timeline events not showing failure reasons
  • Loading branch information
thomasleese authored Apr 4, 2024
2 parents ac8ee5c + 473ac2d commit 57f2c81
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 72 deletions.
76 changes: 29 additions & 47 deletions app/components/timeline_entry/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,9 @@ def description_vars
def status_changed_vars
{
old_status:
render(
StatusTag::Component.new(
timeline_event.old_value,
class_context: "timeline-event",
),
).strip,
render(StatusTag::Component.new(timeline_event.old_value)).strip,
new_status:
render(
StatusTag::Component.new(
timeline_event.new_value,
class_context: "timeline-event",
),
).strip,
render(StatusTag::Component.new(timeline_event.new_value)).strip,
}
end

Expand All @@ -71,51 +61,53 @@ def assessor_assigned_vars
alias_method :reviewer_assigned_vars, :assessor_assigned_vars

def assessment_section_recorded_vars
section = timeline_event.assessment_section

# to handle old timeline events
assessment_section = timeline_event.assessment_section

is_most_recent =
timeline_event
.application_form
.timeline_events
.assessment_section_recorded
.order(created_at: :desc)
.find_by(assessment_section:) == timeline_event

# We need to transform the previous status values that aren't
# suitable for presenting to the user.
status =
if timeline_event.new_value == "action_required"
"rejected"
elsif timeline_event.new_value == "completed" &&
timeline_event.is_latest_of_type?
section.status
elsif timeline_event.new_value == "completed" && is_most_recent
assessment_section.status
else
timeline_event.new_value
end

# We can only show failure reasons for the most recent timeline
# event as we pull them direct from the assessment section.
selected_failure_reasons =
(
if timeline_event.is_latest_of_type?
section.selected_failure_reasons.to_a
if is_most_recent
assessment_section.selected_failure_reasons.to_a
else
[]
end
)

visible_failure_reasons =
(
{
section_name: assessment_section.key.titleize,
status:,
visible_failure_reasons:
if selected_failure_reasons.count <= 2
selected_failure_reasons
else
selected_failure_reasons.take(1)
end
)

hidden_failure_reasons =
(
end,
hidden_failure_reasons:
if selected_failure_reasons.count <= 2
[]
else
selected_failure_reasons.drop(1)
end
)

{
section_name: section.key.titleize,
status:,
visible_failure_reasons:,
hidden_failure_reasons:,
end,
}
end

Expand Down Expand Up @@ -203,19 +195,9 @@ def action_required_by_changed_vars
def stage_changed_vars
{
old_stage:
render(
StatusTag::Component.new(
timeline_event.old_value,
class_context: "timeline-event",
),
).strip,
render(StatusTag::Component.new(timeline_event.old_value)).strip,
new_stage:
render(
StatusTag::Component.new(
timeline_event.new_value,
class_context: "timeline-event",
),
).strip,
render(StatusTag::Component.new(timeline_event.new_value)).strip,
}
end

Expand Down
25 changes: 0 additions & 25 deletions spec/models/timeline_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,29 +453,4 @@
it { is_expected.to validate_absence_of(:note_text) }
end
end

describe "#is_latest_of_type?" do
let(:application_form) { create(:application_form) }
let!(:timeline_event_1) do
create(
:timeline_event,
:assessment_section_recorded,
application_form:,
created_at: Date.new(2020, 1, 1),
)
end
let!(:timeline_event_2) do
create(
:timeline_event,
:assessment_section_recorded,
application_form:,
created_at: Date.new(2020, 1, 2),
)
end

it "returns the correct value" do
expect(timeline_event_1.is_latest_of_type?).to be false
expect(timeline_event_2.is_latest_of_type?).to be true
end
end
end

0 comments on commit 57f2c81

Please sign in to comment.