Skip to content

Commit

Permalink
Change links only appear for clawback hours and reason when clawback …
Browse files Browse the repository at this point in the history
…is requested
  • Loading branch information
dp-daly committed Jan 16, 2025
1 parent 6890bff commit 5da5070
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 2 deletions.
24 changes: 22 additions & 2 deletions app/views/claims/support/claims/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@
<% row.with_value(text: t("none")) %>
<% end %>
<% end %>

<% unless claim.clawback_requested? || claim.clawback_in_progress? %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t(".mentors")) %>
<% row.with_value do %>
<ul class="govuk-list">
<% claim.mentors.each do |mentor| %>
<li><%= mentor.full_name %></li>
<% end %>
</ul>
<% end %>
<% if policy(claim).edit? %>
<% row.with_action(text: t("change"),
href: create_revision_claims_support_school_claim_mentors_path(claim.school, claim),
html_attributes: {
class: "govuk-link--no-visited-state",
}) %>
<% end %>
<% end %>
<% end %>
<% end %>

<h2 class="govuk-heading-m"><%= t(".hours_of_training") %></h2>
Expand All @@ -45,7 +65,7 @@
<% summary_list.with_row do |row| %>
<% row.with_key(text: t(".clawed_back")) %>
<% row.with_value(text: pluralize(mentor_training.hours_clawed_back, t(".hour"))) %>
<% if policy(claim).edit? %>
<% if policy(claim).edit? && claim.clawback_requested? %>
<% row.with_action(text: t("change"),
href: new_edit_request_clawback_claims_support_claims_clawback_path(
claim_id: claim.id,
Expand All @@ -60,7 +80,7 @@
<% summary_list.with_row do |row| %>
<% row.with_key(text: t(".reason_clawed_back")) %>
<% row.with_value(text: mentor_training.reason_clawed_back) %>
<% if policy(claim).edit? %>
<% if policy(claim).edit? && claim.clawback_requested? %>
<% row.with_action(text: t("change"),
href: new_edit_request_clawback_claims_support_claims_clawback_path(
claim_id: claim.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
require "rails_helper"

RSpec.describe "Support user edits a clawback request on a claim", service: :claims, type: :system do
include ActionView::Helpers::TextHelper

scenario do
given_claims_exist
and_i_am_signed_in

when_i_navigate_to_the_clawbacks_index_page
and_i_click_on_claim_one
then_i_see_the_show_page_for_claim_one

when_i_click_on_the_change_link_for_clawback_reason
then_i_see_the_clawback_step_for_claim_one

when_i_click_on_back
then_i_see_the_show_page_for_claim_one

when_i_click_on_the_change_link_for_clawback_reason
then_i_see_the_clawback_step_for_claim_one

when_i_enter_more_hours_than_the_mentor_has_hours_completed
and_i_click_on_continue
then_i_see_a_validation_error_for_entering_too_many_hours

when_i_enter_a_valid_number_of_hours
and_i_click_on_continue
then_i_see_a_validation_error_for_not_entering_a_clawback_reason

when_i_enter_valid_data
and_i_click_on_continue
then_i_see_a_success_message
and_i_see_the_updated_show_page_for_claim_one
end

private

def given_claims_exist
@claim_one = create(:claim,
:submitted,
status: :clawback_requested,
reference: 11_111_111)

@john_doe = create(:claims_mentor, first_name: "John", last_name: "Doe")

@john_doe_training = create(:mentor_training, claim: @claim_one, mentor: @john_doe,
hours_completed: 20, not_assured: true,
hours_clawed_back: 7,
reason_not_assured: "Mismatch in hours recorded compared with hours claimed.",
reason_clawed_back: "Mismatch in hours recorded compared with hours claimed.")
end

def and_i_am_signed_in
sign_in_claims_support_user
end

def when_i_navigate_to_the_clawbacks_index_page
within primary_navigation do
click_on "Claims"
end

within secondary_navigation do
click_on "Clawbacks"
end
end

def and_i_click_on_claim_one
click_on "11111111 - #{@claim_one.school_name}"
end

def then_i_see_the_show_page_for_claim_one
expect(page).to have_title("Clawbacks - #{@claim_one.school_name} - Claim 11111111 - Claim funding for mentor training - GOV.UK")
expect(primary_navigation).to have_current_item("Claims")
expect(page).to have_element(:span, text: "Clawbacks - Claim 11111111", class: "govuk-caption-l")
expect(page).to have_h1(@claim_one.school_name)
expect(page).to have_element(:strong, text: "Clawback requested", class: "govuk-tag govuk-tag--orange")
expect(page).not_to have_link("Request clawback", href: "/support/claims/clawbacks/claims/new/#{@claim_one.id}", class: "govuk-link govuk-button")
expect(page).to have_summary_list_row("School", @claim_one.school_name)
expect(page).to have_summary_list_row("Academic year", @claim_one.academic_year_name)
expect(page).to have_summary_list_row("Accredited provider", @claim_one.provider.name)
expect(page).to have_h2("Hours of training")
@claim_one.mentor_trainings.not_assured.order_by_mentor_full_name.each do |mentor_training|
expect(page).to have_element(:dt, text: mentor_training.mentor.full_name, class: "govuk-summary-list__key")
expect(page).to have_summary_list_row("Original hours claimed", pluralize(mentor_training.hours_completed, "hour"))
expect(page).to have_summary_list_row("Amount clawed back", pluralize(mentor_training.hours_clawed_back, "hour"))
expect(page).to have_summary_list_row("Reason for clawback", mentor_training.reason_clawed_back)
end
expect(page).to have_h2("Grant funding")
expect(page).to have_summary_list_row("Original claim amount", @claim_one.amount.format(symbol: true, decimal_mark: ".", no_cents: true))
expect(page).to have_summary_list_row("Hours clawed back", pluralize(@claim_one.mentor_trainings.sum(:hours_clawed_back), "hour"))
end
alias_method :and_i_see_the_show_page_for_claim_one, :then_i_see_the_show_page_for_claim_one

def when_i_click_on_the_change_link_for_clawback_reason
all("a", text: "Change").last.click
end

def then_i_see_the_clawback_step_for_claim_one
expect(page).to have_title("Clawback details for #{@john_doe.full_name} - #{@claim_one.school_name} - Claim 11111111 - Claim funding for mentor training - GOV.UK")
expect(primary_navigation).to have_current_item("Claims")

expect(page).to have_element(:span, text: "Clawbacks - Claim 11111111", class: "govuk-caption-l")
expect(page).to have_h1("Clawback details")
expect(page).to have_element(:label, text: "Number of hours to clawback", class: "govuk-label")
expect(page).to have_element(:div, text: "Enter whole numbers up to a maximum of #{@john_doe_training.hours_completed} hours", class: "govuk-hint")
expect(page).to have_element(:label, text: "Notes on your decision", class: "govuk-label")
expect(page).to have_element(:div, text: "Only include details related to #{@john_doe.full_name}", class: "govuk-hint")
expect(page).to have_button("Continue")
expect(page).to have_link("Cancel", href: "/support/claims/clawbacks/claims/#{@claim_one.id}")
end

def when_i_click_on_back
click_on "Back"
end

def when_i_enter_more_hours_than_the_mentor_has_hours_completed
fill_in "claims_request_clawback_wizard_mentor_training_clawback_step[number_of_hours]", with: 30
end

def and_i_click_on_continue
click_on "Continue"
end

def then_i_see_a_validation_error_for_entering_too_many_hours
expect(page).to have_validation_error("must be less than or equal to #{@john_doe_training.hours_completed}")
end

def when_i_enter_a_valid_number_of_hours
fill_in "claims_request_clawback_wizard_mentor_training_clawback_step[number_of_hours]", with: 20
end

def then_i_see_a_validation_error_for_not_entering_a_clawback_reason
expect(page).to have_validation_error("Enter the details about your decision.")
end

def when_i_enter_valid_data
fill_in "claims_request_clawback_wizard_mentor_training_clawback_step[number_of_hours]", with: 2
fill_in "claims_request_clawback_wizard_mentor_training_clawback_step[reason_for_clawback]", with: "Insufficient evidence."
end

def then_i_see_a_success_message
expect(page).to have_success_banner("Clawback updated")
end

def and_i_see_the_updated_show_page_for_claim_one
expect(page).to have_h2("Hours of training")
@claim_one.mentor_trainings.not_assured.order_by_mentor_full_name.each do |mentor_training|
expect(page).to have_element(:dt, text: mentor_training.mentor.full_name, class: "govuk-summary-list__key")
expect(page).to have_summary_list_row("Original hours claimed", pluralize(mentor_training.hours_completed, "hour"))
expect(page).to have_summary_list_row("Amount clawed back", pluralize(mentor_training.hours_clawed_back, "hour"))
expect(page).to have_summary_list_row("Reason for clawback", mentor_training.reason_clawed_back)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def then_i_see_the_show_page_for_claim_one
expect(page).to have_summary_list_row("School", @claim_one.school_name)
expect(page).to have_summary_list_row("Academic year", @claim_one.academic_year_name)
expect(page).to have_summary_list_row("Accredited provider", @claim_one.provider.name)
expect(page).to have_summary_list_row("Mentors") do |row|
@claim_one.mentors.each do |mentor|
expect(row).to have_css("ul.govuk-list li", text: mentor.full_name)
end
end
expect(page).to have_h2("Hours of training")
@claim_one.mentor_trainings.order_by_mentor_full_name.each do |mentor_training|
expect(page).to have_summary_list_row(mentor_training.mentor.full_name, "#{mentor_training.hours_completed} hours")
Expand Down
1 change: 1 addition & 0 deletions spec/system/claims/support/claims/view_a_claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def then_i_can_see_the_details_of_a_submitted_claim
expect(page).to have_content("Submitted")
expect(page).to have_content("Submitted by #{user.full_name} on 5 March 2024.")
expect(page).to have_content("Accredited provider#{provider.name}")
expect(page).to have_content("Mentors\n#{mentor.full_name}")
expect(page).to have_content("Hours of training")
expect(page).to have_content("#{mentor.full_name}#{mentor_training.hours_completed} hours")
expect(page).to have_content("Total hours6 hours")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def then_i_can_then_see_the_claim_details
expect(page).to have_content("Submitted")
expect(page).to have_content("Submitted by #{colin.full_name} on 5 March 2024.")
expect(page).to have_content("Accredited providerBest Practice Network")
expect(page).to have_content("Mentors\nBarry Garlow")
expect(page).to have_content("Hours of training")
expect(page).to have_content("Barry Garlow#{mentor_training.hours_completed} hours")
expect(page).to have_content("Total hours6 hours")
Expand Down

0 comments on commit 5da5070

Please sign in to comment.