Skip to content

Commit

Permalink
Add specs for wizard and system specs for altered views
Browse files Browse the repository at this point in the history
  • Loading branch information
dp-daly committed Feb 4, 2025
1 parent eb88cc8 commit 17e39ee
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
</h2>
<div class="govuk-error-summary__body">
<div class="govuk-list govuk-error-summary__list">
<% if current_step.error_count > 0 %>
<p class="govuk-heading-s">
<%= t(".error_summary.errors_to_fix", count: current_step.error_count) %>
</p>
<% end %>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<span class="govuk-caption-l"><%= t(".caption") %></span>
<h1 class="govuk-heading-l"><%= t(".title") %></h1>

<p class="govuk-body"><%= t(".upload_text") %></p>

<p class="govuk-body"><%= t(".file_must_contain") %></p>

<%= form_for(current_step, url: current_step_path, method: :put, multipart: true) do |f| %>
<%= f.govuk_error_summary(presenter: DetailedErrorSummaryPresenter) %>
<%= f.govuk_file_field :csv_upload, label: { text: t(".upload_csv_file"), size: "s" } %>

<%= govuk_details(summary_text: t(".csv_help")) do %>
<%= render_markdown(t(".csv_help_details")) %>
<% end %>
<%= f.govuk_file_field :csv_upload, label: nil %>

<%= f.govuk_submit(t(".upload_csv_file")) %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Claims::UploadSamplingDataWizard::ConfirmationStep < BaseStep
delegate :file_name, :csv, to: :upload_step
delegate :uploaded_claim_ids, to: :wizard

def csv_headers
@csv_headers ||= csv.headers
Expand Down
8 changes: 3 additions & 5 deletions app/wizards/claims/upload_sampling_data_wizard/upload_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def process_csv
validate_csv_file
return if errors.present?

reset_claim_ids
reset_input_attributes

self.file_name = csv_upload.original_filename

CSV.parse(read_csv, headers: true) do |row|
claim = paid_claims.find_by(reference: row["claim_reference"])
Expand Down Expand Up @@ -93,10 +95,6 @@ def read_csv
@read_csv ||= csv_content || csv_upload.read
end

def reset_claim_ids
self.claim_ids = []
end

def reset_input_attributes
self.invalid_claim_rows = []
self.missing_sample_reason_rows = []
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en/claims/support/claims/samplings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ en:
success_heading: Claim updated
upload_data:
update:
heading: Sampling data uploaded
heading: Auditing data uploaded
body: It may take a moment for the uploaded claims to update
confirm_provider_rejected:
page_title: Are you sure you want to confirm the provider has rejected the claim? - Auditing - Claim %{reference}
Expand Down
18 changes: 6 additions & 12 deletions config/locales/en/wizards/claims/upload_sampling_data_wizard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ en:
page_title: Upload claims to be audited - Auditing - Claims
title: Upload claims to be audited
caption: Auditing
upload_text: Upload the CSV file sent to you by DfE
file_must_contain: The file must contain the headers 'claim_reference' and 'sample_reason'
upload_csv_file: Upload CSV file
csv_help: Help with the CSV file
csv_help_details: |
Use this form to upload the CSV file sent by the data and insights team.
The CSV file must contain the following headers in the first row:
- claim_reference
- sample_reason
already_been_claimed: Test
confirmation_step:
page_title: Are you sure you want to upload the auditing data? - Auditing - Claims
title: Confirm you want to upload claims to be sampled
title: Confirm you want to upload claims to be audited
caption: Auditing
confirm_upload: Confirm upload
only_showing_first_rows: Only showing the first %{row_count} rows
Expand All @@ -36,9 +31,8 @@ en:
claim_reference: claim_reference
sampling_reason: sample_reason
errors:
invalid_claim_reference: Not a valid claim reference
invalid_input: Not a valid input
reason_needed: Reason needed
invalid_claim_reference: Enter a valid claim reference
reason_needed: Enter a valid sample reason
only_showing_rows_with_errors: Only showing rows with errors
upload_your_file_again: Upload your file again
no_claims_step:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
claim_reference,sample_reason
11111111,Valid paid claim
22222222,Invalid claim
88888888,Valid reason
11111111,
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
claim_refrence,sampl_reason
11111111,Random audit
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def then_i_see_the_sampling_claims_index_page
def then_i_see_the_upload_csv_page
expect(page).to have_h1("Upload claims to be audited")
have_element(:span, text: "Auditing", class: "govuk-caption-l")
expect(page).to have_element(:label, text: "Upload CSV file")
end

def and_i_see_no_sampling_claims_have_been_uploaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,16 @@
when_i_click_on_upload_claims_to_be_sampled
then_i_see_the_upload_csv_page

# when_i_upload_a_csv_containing_invalid_headers
# and_i_click_on_upload_csv_file
# then_i_see_validation_errors_regarding_invalid_headers

# when_i_click_on_upload_again
# and_i_upload_a_csv_containing_invalid_sampling_data
# and_i_click_on_upload_csv_file
# then_i_see_validation_errors_regarding_invalid_data
when_i_upload_a_csv_containing_invalid_sampling_data
and_i_click_on_upload_csv_file
then_i_see_validation_errors_regarding_invalid_data
end

private

def given_claims_exist
@current_academic_year = AcademicYear.for_date(Time.current) || create(:academic_year, :current)

current_claim_window = create(:claim_window, academic_year: @current_academic_year,
starts_on: @current_academic_year.starts_on,
ends_on: @current_academic_year.starts_on + 2.days)
@current_claim = create(:claim,
:submitted,
claim_window: current_claim_window,
reference: 11_111_111)
@another_paid_claim = create(:claim,
:submitted,
status: :paid,
claim_window: current_claim_window)
@paid_claim_1 = create(:claim, :submitted, status: :paid, reference: 11_111_111)
@paid_claim_2 = create(:claim, :submitted, status: :paid, reference: 22_222_222)
end

def and_i_am_signed_in
Expand Down Expand Up @@ -74,20 +58,24 @@ def when_i_click_on_upload_claims_to_be_sampled
end

def when_i_upload_a_csv_containing_invalid_sampling_data
attach_file "Upload CSV file", "spec/fixtures/claims/sampling/invalid_example_sampling_upload.csv"
attach_file nil,
"spec/fixtures/claims/sampling/invalid_example_sampling_upload.csv"
end

def and_i_click_on_upload_csv_file
click_on "Upload"
end

def then_i_see_validation_error_regarding_invalid_data
expect(page).to have_validation_error("The selected CSV file contains invalid data")
end

def then_i_see_the_upload_csv_page
expect(page).to have_h1("Upload claims to be audited")
have_element(:span, text: "Auditing", class: "govuk-caption-l")
expect(page).to have_element(:label, text: "Upload CSV file")
end

def then_i_see_validation_errors_regarding_invalid_data
expect(page).to have_h1("Upload claims to be audited")
expect(page).to have_element(:div, text: "You need to fix 2 errors related to specific rows", class: "govuk-error-summary")
expect(page).to have_element(:td, text: "Enter a valid claim reference", class: "govuk-table__cell")
expect(page).to have_element(:td, text: "Enter a valid sample reason", class: "govuk-table__cell")
expect(page).to have_element(:p, text: "Only showing rows with errors", class: "govuk-!-text-align-centre")
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require "rails_helper"

RSpec.describe "Support user uploads a CSV file with the wrong headers",
service: :claims,
type: :system do
scenario do
given_claims_exist
and_i_am_signed_in

when_i_navigate_to_the_sampling_claims_index_page
then_i_see_the_sampling_claims_index_page

when_i_click_on_upload_claims_to_be_audited
then_i_see_the_upload_csv_page

when_i_upload_a_csv_file_not_containing_invalid_headers
and_i_click_on_upload_csv_file
then_i_see_validation_error_regarding_invalid_headers
end

private

def given_claims_exist
@paid_claim_1 = create(:claim, :submitted, status: :paid, reference: 11_111_111)
end

def and_i_am_signed_in
sign_in_claims_support_user
end

def when_i_navigate_to_the_sampling_claims_index_page
within primary_navigation do
click_on "Claims"
end

within secondary_navigation do
click_on "Auditing"
end
end

def then_i_see_the_sampling_claims_index_page
expect(page).to have_title("Claims - Claim funding for mentor training - GOV.UK")
expect(page).to have_h1("Claims")
expect(primary_navigation).to have_current_item("Claims")
expect(secondary_navigation).to have_current_item("Auditing")
expect(page).to have_current_path(claims_support_claims_samplings_path, ignore_query: true)
end

def then_i_see_the_upload_csv_page
expect(page).to have_h1("Upload claims to be audited")
have_element(:span, text: "Auditing", class: "govuk-caption-l")
end

def when_i_click_on_upload_claims_to_be_audited
click_on "Upload claims to be audited"
end

def and_i_click_on_upload_csv_file
click_on "Upload"
end

def when_i_upload_a_csv_file_not_containing_invalid_headers
attach_file nil,
"spec/fixtures/claims/sampling/invalid_headers_sampling_upload.csv"
end

def then_i_see_validation_error_regarding_invalid_headers
expect(page).to have_css(".govuk-error-summary__list", text: "Your file needs a column called ‘claim_reference’ and ‘sample_reason’")
expect(page).to have_css(".govuk-error-summary__list", text: "Right now it has columns called ‘claim_refrence’ and ‘sampl_reason’.")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def when_i_click_on_upload_claims_to_be_sampled
end

def when_i_upload_a_csv_containing_a_valid_sampling_data
attach_file "Upload CSV file", "spec/fixtures/claims/sampling/example_sampling_upload.csv"
attach_file nil, "spec/fixtures/claims/sampling/example_sampling_upload.csv"
end
alias_method :and_i_upload_a_csv_containing_a_valid_sampling_data,
:when_i_upload_a_csv_containing_a_valid_sampling_data
Expand All @@ -110,13 +110,12 @@ def and_i_click_on_upload_csv_file
end

def then_i_see_the_confirmation_page_for_uploading_the_sampling_data
expect(page).to have_h1("Are you sure you want to upload the auditing data?")
expect(page).to have_h1("Confirm you want to upload claims to be audited")
have_element(:span, text: "Auditing", class: "govuk-caption-l")
expect(page).to have_element(:p, text: "There is 1 claim included in this upload.", class: "govuk-body")
expect(page).to have_element(
:strong,
text: "WarningEach accredited provider will receive an email instructing them to assure their partner schools' claim.",
class: "govuk-warning-text__text",
expect(page).to have_table_row(
"1" => "2",
"claim_reference" => "11111111",
"sample_reason" => "Some Reason",
)
end

Expand All @@ -133,11 +132,10 @@ def when_i_click_on_back
def then_i_see_the_upload_csv_page
expect(page).to have_h1("Upload claims to be audited")
have_element(:span, text: "Auditing", class: "govuk-caption-l")
expect(page).to have_element(:label, text: "Upload CSV file")
end

def when_i_click_upload_data
click_on "Upload data"
click_on "Confirm upload"
end

def then_i_see_the_upload_has_been_successful
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ def when_i_click_on_upload_claims_to_be_sampled
def then_i_see_the_upload_csv_page
expect(page).to have_h1("Upload claims to be audited")
have_element(:span, text: "Auditing", class: "govuk-caption-l")
expect(page).to have_element(:label, text: "Upload CSV file")
end

def when_i_upload_an_invalid_file_type
tmp = Tempfile.new("invalid_upload.txt")
attach_file "Upload CSV file", tmp.path
attach_file nil, tmp.path
end

def and_i_click_on_upload_csv_file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def then_i_see_the_errors_page

def and_i_see_the_csv_contained_claims_not_with_the_status_sampling_in_progress
expect(page).to have_h1("Upload provider response")
expect(page).to have_element(:div, text: "You need to fix 1 error related to specific rows", class: "govuk-error-summary")
expect(page).to have_element(:div, text: "You need to fix 1 error related to a specific row", class: "govuk-error-summary")
expect(page).to have_element(:td, text: "Enter a valid mentor name Jane Doe", class: "govuk-table__cell")
expect(page).to have_element(:p, text: "Only showing rows with errors", class: "govuk-!-text-align-centre")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def then_i_see_the_errors_page

def and_i_see_the_csv_contained_claims_not_with_the_status_sampling_in_progress
expect(page).to have_h1("Upload provider response")
expect(page).to have_element(:div, text: "You need to fix 1 error related to specific rows", class: "govuk-error-summary")
expect(page).to have_element(:div, text: "You need to fix 1 error related to a specific row", class: "govuk-error-summary")
expect(page).to have_element(:td, text: "Not a valid claim reference 22222222", class: "govuk-table__cell")
expect(page).to have_element(:p, text: "Only showing rows with errors", class: "govuk-!-text-align-centre")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def then_i_see_the_errors_page

def and_i_see_the_csv_contained_claims_without_a_rejection_reason
expect(page).to have_h1("Upload provider response")
expect(page).to have_element(:div, text: "You need to fix 1 error related to specific rows", class: "govuk-error-summary")
expect(page).to have_element(:div, text: "You need to fix 1 error related to a specific row", class: "govuk-error-summary")
expect(page).to have_element(:td, text: "Enter a reason", class: "govuk-table__cell")
expect(page).to have_element(:p, text: "Only showing rows with errors", class: "govuk-!-text-align-centre")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def then_i_see_the_errors_page

def and_i_see_the_csv_contained_claims_without_a_claim_accepted_input_for_each_mentor
expect(page).to have_h1("Upload provider response")
expect(page).to have_element(:div, text: "You need to fix 1 error related to specific rows", class: "govuk-error-summary")
expect(page).to have_element(:div, text: "You need to fix 1 error related to a specific row", class: "govuk-error-summary")
expect(page).to have_element(:td, text: "Enter a valid input", class: "govuk-table__cell")
expect(page).to have_element(:p, text: "Only showing rows with errors", class: "govuk-!-text-align-centre")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
describe "delegations" do
it { is_expected.to delegate_method(:csv).to(:upload_step) }
it { is_expected.to delegate_method(:file_name).to(:upload_step) }
it { is_expected.to delegate_method(:uploaded_claim_ids).to(:wizard) }
end

describe "#csv_headers" do
Expand Down

0 comments on commit 17e39ee

Please sign in to comment.