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 Feb 4, 2025
1 parent a633ae7 commit bb7b6e8
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def set_wizard
end

def step_path(step)
edit_request_clawback_claims_support_claims_clawback_path(claim: @claim, mentor_training_id:, step:)
edit_request_clawback_claims_support_claims_clawback_path(claim: @claim, mentor_training_id:, state_key:, step:)
end

def mentor_training_id
Expand Down
42 changes: 31 additions & 11 deletions app/views/claims/support/claims/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<% summary_list.with_row do |row| %>
<% row.with_key(text: Claims::Claim.human_attribute_name(:accredited_provider)) %>
<% row.with_value(text: claim.provider.name) %>
<% if policy(claim).edit? %>
<% row.with_action(text: t("change"),
href: create_revision_claims_support_school_claim_path(claim.school, claim),
html_attributes: {
class: "govuk-link--no-visited-state",
}) %>
<% if policy(claim).edit? %>
<% row.with_action(text: t("change"),
href: create_revision_claims_support_school_claim_path(claim.school, claim),
html_attributes: {
class: "govuk-link--no-visited-state",
}) %>
<% end %>
<% end %>
<% else %>
Expand All @@ -27,12 +27,32 @@
<% 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>
<% if claim.clawback_requested? || claim.clawback_in_progress? %>
<% claim.mentor_trainings.not_assured.order_by_mentor_full_name.each do |mentor_training| %>
<%= govuk_summary_list(actions: policy(claim).edit?) do |summary_list| %>
<%= govuk_summary_list do |summary_list| %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: mentor_training.mentor.full_name) %>
<% end %>
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 @@ -54,20 +74,20 @@
html_attributes: {
class: "govuk-link--no-visited-state",
}) %>
<% end %>
<% end %>
<% end %>

<% 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,
mentor_training_id: mentor_training.id,
),
html_attributes: {
class: "govuk-link--no-visited-state",
class: "govuk-link--no-visited-state",
}) %>
<% end %>
<% end %>
Expand Down
6 changes: 3 additions & 3 deletions app/wizards/claims/edit_request_clawback_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def update_clawback
end

def setup_state
state[step_name_for_mentor_training_clawback(mentor_training)] = {
"hours_clawed_back" => mentor_training.hours_clawed_back,
"reason_clawed_back" => mentor_training.reason_clawed_back,
state[step_name_for_mentor_training_clawback(mentor_training).to_s] = {
"number_of_hours" => mentor_training.hours_clawed_back,
"reason_for_clawback" => mentor_training.reason_clawed_back,
}
end
end
Expand Down
8 changes: 4 additions & 4 deletions config/routes/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@
resources :clawbacks, path: "clawbacks/claims", only: %i[index show new create] do
member do
get "edit/:claim_id/:mentor_training_id", to: "edit_request_clawback#new", as: :new_edit_request_clawback
get "edit/:claim_id/:mentor_training_id/:step", to: "edit_request_clawback#edit", as: :edit_request_clawback
put "edit/:claim_id/:mentor_training_id/:step", to: "edit_request_clawback#update"
get "edit/:state_key/:claim_id/:mentor_training_id/:step", to: "edit_request_clawback#edit", as: :edit_request_clawback
put "edit/:state_key/:claim_id/:mentor_training_id/:step", to: "edit_request_clawback#update"
end

collection do
get "new/:claim_id", to: "request_clawback#new", as: :new_request_clawback
get "new/:claim_id/:step", to: "request_clawback#edit", as: :request_clawback
put "new/:claim_id/:step", to: "request_clawback#update"
get "new/:state_key/:claim_id/:step", to: "request_clawback#edit", as: :request_clawback
put "new/:state_key/:claim_id/:step", to: "request_clawback#update"

get "upload_esfa_response/new", to: "clawbacks/upload_esfa_response#new", as: :new_upload_esfa_response
get "upload_esfa_response/new/:state_key/:step", to: "clawbacks/upload_esfa_response#edit", as: :upload_esfa_response
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
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_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: "Ready for clawback", class: "govuk-tag govuk-tag--turquoise")
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 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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def then_i_see_the_show_page_for_the_claim_not_approved_claim
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_not_approved_claim.school_name)
expect(page).to have_element(:strong, text: "Claim not approved", class: "govuk-tag govuk-tag--pink")
expect(page).to have_element(:strong, text: "Rejected by school", class: "govuk-tag govuk-tag--turquoise")
expect(page).to have_link("Request clawback", href: "/support/claims/clawbacks/claims/new/#{@claim_not_approved_claim.id}")
expect(page).to have_summary_list_row("School", @claim_not_approved_claim.school_name)
expect(page).to have_summary_list_row("Academic year", @claim_not_approved_claim.academic_year_name)
Expand Down Expand Up @@ -111,7 +111,7 @@ def then_i_see_the_show_page_for_the_clawback_requested_claim
expect(primary_navigation).to have_current_item("Claims")
expect(page).to have_element(:span, text: "Clawbacks - Claim 22222222", class: "govuk-caption-l")
expect(page).to have_h1(@clawback_requested_claim.school_name)
expect(page).to have_element(:strong, text: "Clawback requested", class: "govuk-tag govuk-tag--orange")
expect(page).to have_element(:strong, text: "Ready for clawback", class: "govuk-tag govuk-tag--turquoise")
expect(page).not_to have_link("Request clawback", href: "/support/claims/clawbacks/claims/new/#{@clawback_requested_claim.id}", class: "govuk-link govuk-button")
expect(page).to have_summary_list_row("School", @clawback_requested_claim.school_name)
expect(page).to have_summary_list_row("Academic year", @clawback_requested_claim.academic_year_name)
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
Loading

0 comments on commit bb7b6e8

Please sign in to comment.