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

Refactor edit claim to wizard pattern #1212

Open
wants to merge 12 commits into
base: jc/refactor_claims_to_wizard_pattern
Choose a base branch
from

Conversation

JamieCleare2525
Copy link
Contributor

Context

  • To improve the efficiency of Editing a Claim. Refactor the Edit Claim journey to use the Wizard pattern.

Changes proposed in this pull request

  • Introduce EditClaimWizard and related steps
  • Remove code with is no longer necessary
  • Add test coverage to ensure all code changes have been tested.
  • ... success?

Guidance to review

Sign in as Anne (School user)

  • Visit the show page for an existing DRAFT claim

  • Edit an existing claim (provider, mentors, mentor training hours)
  • Submit the claim -> The existing claim should be updated and submitted.

  • Click "Submit claim"
  • You should be redirected to the Declaration page.
  • Click "Submit claim" -> The existing clam should be submitted

Sign in as Colin (Support user)

  • Visit the show page for an existing DRAFT claim
  • Edit an existing claim (provider, mentors, mentor training hours)
  • Submit the claim -> The existing claim should be updated and submitted.

Link to Trello card

https://trello.com/c/dzMquW8D/934-refactor-the-edit-claim-form-to-use-the-wizard-pattern

@JamieCleare2525 JamieCleare2525 added the deploy A Review App will be created for PRs with this label label Nov 28, 2024
@JamieCleare2525 JamieCleare2525 self-assigned this Nov 28, 2024
@JamieCleare2525 JamieCleare2525 requested review from a team as code owners November 28, 2024 16:32
@JamieCleare2525 JamieCleare2525 changed the base branch from main to jc/refactor_claims_to_wizard_pattern November 28, 2024 16:32
Copy link

@@ -22,7 +22,7 @@ def remaining_claimable_hours_condition(scope)
end

def training_allowance_for(mentor)
Claims::TrainingAllowance.new(mentor:, provider:, academic_year:)
Claims::TrainingAllowance.new(mentor:, provider:, academic_year:, claim_to_exclude: claim)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What changed to require the addition of claim_to_exclude here?

@@ -15,7 +15,8 @@
<% 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),
href: edit_attribute_path(:provider),
visually_hidden_text: Claims::Claim.human_attribute_name(:accredited_provider),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice spot on the visually_hidden_text arguments you've added ⭐

<% unless current_user.support_user? %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: Claims::Claim.human_attribute_name(:school)) %>
<% row.with_value(text: @wizard.school.name) %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we consider delegation here to guard against nil values? Granted this shouldn't happen but we've seen a lot of cases that shouldn't happen 😂

Likewise for the other chained methods in this file if you agree!

end

def academic_year
claim.claim_window.academic_year
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make use of the has_one :academic_year, through: :claim_window association here?

Suggested change
claim.claim_window.academic_year
claim.academic_year

Is this worth memoizing?

max_hours = Claims::TrainingAllowance.new(
mentor: mentor_training.mentor,
provider: mentor_training.provider,
academic_year: claim.claim_window.academic_year,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this make use of the academic_year method above?

@@ -70,7 +130,7 @@ def given_i_sign_in
end

def given_there_is_a_current_claim_window
Claims::ClaimWindow::Build.call(claim_window_params: { starts_on: 2.days.ago, ends_on: 2.days.from_now }).save!(validate: false)
claim_window
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we use let! to declare the claim_window is this step necessary?

@@ -216,21 +197,25 @@ def when_i_add_training_hours(hours)
end

def then_i_expect_the_training_hours_to_be_selected(hours)
find("#claims-support-claim-mentor-training-form-hours-completed-#{hours}-field").checked?
if hours.to_i == 20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to convert this to an integer here or could we use string comparison?

expect(page).to have_content("Check your answers")

within("dl.govuk-summary-list:nth(1)") do
within(".govuk-summary-list__row:nth(1)") do
expect(page).to have_content("Academic year")
expect(page).to have_content(claim.academic_year_name)
expect(page).to have_content(@claim_window.academic_year.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to a previous comment 😁

Suggested change
expect(page).to have_content(@claim_window.academic_year.name)
expect(page).to have_content(@claim_window.academic_year_name)

given_i_sign_in
when_i_select_a_school
when_i_click_on_claims
scenario "A support user I can edit a draft claim" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
scenario "A support user I can edit a draft claim" do
scenario "As a support user I can edit a draft claim" do

Comment on lines +10 to +13
let(:school) { create(:claims_school) }
let(:created_by) { create(:claims_user, schools: [school]) }
let(:provider) { create(:claims_provider, :niot) }
let(:mentor_1) { create(:claims_mentor, schools: [school], first_name: "Alan", last_name: "Anderson") }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let(:school) { create(:claims_school) }
let(:created_by) { create(:claims_user, schools: [school]) }
let(:provider) { create(:claims_provider, :niot) }
let(:mentor_1) { create(:claims_mentor, schools: [school], first_name: "Alan", last_name: "Anderson") }
let(:school) { build(:claims_school) }
let(:created_by) { build(:claims_user, schools: [school]) }
let(:provider) { build(:claims_provider, :niot) }
let(:mentor_1) { build(:claims_mentor, schools: [school], first_name: "Alan", last_name: "Anderson") }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy A Review App will be created for PRs with this label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants