diff --git a/app/assets/stylesheets/application.sass.scss b/app/assets/stylesheets/application.sass.scss index 810f31138..92c8b2651 100644 --- a/app/assets/stylesheets/application.sass.scss +++ b/app/assets/stylesheets/application.sass.scss @@ -19,6 +19,7 @@ $govuk-new-typography-scale: true; @import "summary-lists"; @import "feedback"; @import "button-group-custom"; +@import "early-result-banner"; // NOTE: suggestions input component not yet part of GOV.UK frontend // https://github.com/alphagov/govuk-frontend/pull/2453 diff --git a/app/assets/stylesheets/early-result-banner.scss b/app/assets/stylesheets/early-result-banner.scss new file mode 100644 index 000000000..10bc02344 --- /dev/null +++ b/app/assets/stylesheets/early-result-banner.scss @@ -0,0 +1,9 @@ +.panel-blue { + background: govuk-colour("blue"); + padding: 30px; + border: none; +} + +.white_text { + color: white !important; +} diff --git a/app/assets/stylesheets/results.scss b/app/assets/stylesheets/results.scss index 92e304a9d..e0d0bb4e8 100644 --- a/app/assets/stylesheets/results.scss +++ b/app/assets/stylesheets/results.scss @@ -11,7 +11,7 @@ tr.solid-bottom-border { } // make the confirmation panel a neutral colour -.panel-blue { +.panel-blue-white-text { background: govuk-colour("blue"); // All text on the blue background should be white for accessibility and legibility purposes. diff --git a/app/controllers/change_answers_controller.rb b/app/controllers/change_answers_controller.rb index bb210b1b6..1d8e6a4f8 100644 --- a/app/controllers/change_answers_controller.rb +++ b/app/controllers/change_answers_controller.rb @@ -9,37 +9,22 @@ def update # Note that this merge! has the side effect of altering the session data in the '@check' variable # that was loaded by our base class which looks quite awkward session_data.merge!(@form.attributes_for_export_to_session) - next_step = Steps::Helper.next_step_for(session_data, step) - if @check.consistent? - if Steps::Helper.last_step_in_group?(session_data, step) - # if we have a 'check stops' block, it may have been removed even if we're consistent - # e.g. going from employed to unemployed - # but only check this if we have financial information in the check - if Steps::Logic.check_stops_at_gross_income?(session_data) && !Steps::Logic.non_means_tested?(session_data) - last_step_with_data = Steps::Helper.last_step_with_valid_data(session_data) - completed_steps = Steps::Helper.completed_steps_for(session_data, last_step_with_data) - cfe_result = CfeService.result(session_data, completed_steps) - - if cfe_result.ineligible_gross_income? - # no change - go back to check answers - save_and_redirect_to_check_answers - else - # eligibility changed - remove 'ineligible' block and show notification - session_data.delete IneligibleGrossIncomeForm::SELECTION - flash[:notice] = I18n.t("service.change_eligibility") - redirect_to_next_question - end - else - save_and_redirect_to_check_answers - end + if FeatureFlags.enabled?(:ee_banner, session_data) + next_step = step_with_inconsistent_data + # we need to check for aggregated_means so we know when to show the ":how_to_aggregate" screen when in a change loop + if next_step && step != :aggregated_means + redirect_to helpers.check_step_path_from_step(next_step, assessment_code) + elsif Steps::Helper.last_step_in_group?(session_data, step) + save_and_redirect_to_check_answers else + # this is the mini-loop - it isn't the last step in the section, we have + # valid data from a previous selection but we choose to take the user + # through the whole section again. + next_step = Steps::Helper.next_step_for(session_data, step) redirect_to helpers.check_step_path_from_step(next_step, assessment_code) end - # this branch is neccessary to surface the ":how_to_aggregate" screen when changing answers - elsif step == :aggregated_means - redirect_to helpers.check_step_path_from_step(next_step, assessment_code) else - redirect_to_next_question + legacy_early_eligibility_change_answers end else track_validation_error @@ -63,6 +48,48 @@ def redirect_to_next_question redirect_to helpers.check_step_path_from_step(next_check_answer_step, assessment_code) end + def step_with_inconsistent_data + Steps::Helper.remaining_steps_for(session_data, step) + .drop_while { |thestep| + Flow::Handler.model_from_session(thestep, session_data).valid? + }.first + end + + def legacy_early_eligibility_change_answers + next_step = Steps::Helper.next_step_for(session_data, step) + if @check.consistent? # check will always be consistent at change answers for the new ee_banner flow + if Steps::Helper.last_step_in_group?(session_data, step) + # if we have a 'check stops' block, it may have been removed even if we're consistent + # e.g. going from employed to unemployed + # but only check this if we have financial information in the check + if Steps::Logic.check_stops_at_gross_income?(session_data) && !Steps::Logic.non_means_tested?(session_data) + last_step_with_data = Steps::Helper.last_step_with_valid_data(session_data) + completed_steps = Steps::Helper.completed_steps_for(session_data, last_step_with_data) + cfe_result = CfeService.result(session_data, completed_steps) + + if cfe_result.ineligible_gross_income? + # no change - go back to check answers + save_and_redirect_to_check_answers + else + # eligibility changed - remove 'ineligible' block and show notification + session_data.delete IneligibleGrossIncomeForm::SELECTION + flash[:notice] = I18n.t("service.change_eligibility") + redirect_to_next_question + end + else + save_and_redirect_to_check_answers + end + else + redirect_to helpers.check_step_path_from_step(next_step, assessment_code) + end + # this branch is neccessary to surface the ":how_to_aggregate" screen when changing answers + elsif step == :aggregated_means + redirect_to helpers.check_step_path_from_step(next_step, assessment_code) + else + redirect_to_next_question + end + end + # While we're in a 'change answers loop', we want to be working with a temporary copy of the answers # stored in a section of the session called 'pending'. def session_data diff --git a/app/controllers/checks_controller.rb b/app/controllers/checks_controller.rb index 52fe21f72..dfc4190da 100644 --- a/app/controllers/checks_controller.rb +++ b/app/controllers/checks_controller.rb @@ -1,5 +1,6 @@ class ChecksController < ApplicationController before_action :redirect_to_primary_host, only: :new + before_action :clear_early_result, only: :check_answers def new new_assessment_code = SecureRandom.uuid @@ -32,6 +33,11 @@ def assessment_code params[:assessment_code] end + def clear_early_result + # not all checks have an early result e.g. passported clients, U18 etc + session_data["early_result"]&.clear + end + def specify_feedback_widget @feedback = action_name == "end_of_journey" ? :satisfaction : :freetext end diff --git a/app/controllers/forms_controller.rb b/app/controllers/forms_controller.rb index 8aa914e7b..a30b8628c 100644 --- a/app/controllers/forms_controller.rb +++ b/app/controllers/forms_controller.rb @@ -6,7 +6,12 @@ def update if @form.valid? track_choices(@form) session_data.merge!(@form.attributes_for_export_to_session) - next_step = calculate_next_step(session_data, step) + next_step = if FeatureFlags.enabled?(:ee_banner, session_data) + Steps::Helper.next_step_for(session_data, step) + else + calculate_next_step(session_data, step) + end + calculate_early_result if FeatureFlags.enabled?(:ee_banner, session_data) if next_step redirect_to helpers.step_path_from_step(next_step, assessment_code) else @@ -31,4 +36,13 @@ def calculate_next_step(session_data, step) Steps::Helper.next_step_for(session_data, step) end end + + def calculate_early_result + if last_tag_in_group?(:gross_income) + cfe_result = CfeService.result(session_data, Steps::Helper.completed_steps_for(session_data, step)) + session_data["early_result"] = { "result" => cfe_result.gross_income_result, + "gross_income_excess" => cfe_result.gross_income_excess } + # add analytics tracking here? completed user journeys + end + end end diff --git a/app/controllers/results_controller.rb b/app/controllers/results_controller.rb index 72cbb5e3f..12f0bb7d0 100644 --- a/app/controllers/results_controller.rb +++ b/app/controllers/results_controller.rb @@ -6,9 +6,19 @@ def create redirect_to result_path(assessment_code:) end + def early_result_redirect + @previous_step = params[:step].to_sym + session_data["api_response"] = CfeService.call(session_data, Steps::Helper.completed_steps_for(session_data, @previous_step)) + set_early_result_type + redirect_to result_path(assessment_code:) + end + def show + # ee_banner @early_eligibility_selection can be removed when FF is removed + @early_result_type = session_data.dig("early_result", "type") @early_eligibility_selection = session_data.fetch("early_eligibility_selection", nil) @model = CalculationResult.new(session_data) + # we'll need to move this tracking point or do something with it track_completed_journey(@model) track_page_view(page: :view_results) @journey_continues_on_another_page = @check.controlled? && @model.decision == "eligible" @@ -16,6 +26,8 @@ def show end def download + # ee_banner @early_eligibility_selection can be removed when FF is removed + @early_result_type = session_data.dig("early_result", "type") @early_eligibility_selection = session_data.fetch("early_eligibility_selection", nil) track_page_view(page: :download_results) @model = CalculationResult.new(session_data) @@ -43,6 +55,10 @@ def load_check @check = Check.new(session_data) end + def set_early_result_type + session_data["early_result"]["type"] = "gross_income" + end + def track_completed_journey(calculation_result) if signed_in? && current_provider.present? JourneyLoggerService.call(assessment_id, calculation_result, @check, current_provider.first_office_code, cookies) diff --git a/app/models/cfe_result.rb b/app/models/cfe_result.rb index 53d1cd3d8..95f7edbbf 100644 --- a/app/models/cfe_result.rb +++ b/app/models/cfe_result.rb @@ -5,10 +5,6 @@ def initialize(api_response) @api_response = api_response.deep_symbolize_keys end - def ineligible_gross_income? - api_response.dig(:result_summary, :gross_income, :proceeding_types).first[:result] == "ineligible" - end - def decision @decision ||= begin # In some circumstances CFE can return other results, such as 'partially_eligible'. @@ -22,9 +18,17 @@ def decision end end + def ineligible_gross_income? + gross_income_result == "ineligible" + end + + def gross_income_result + api_response.dig(:result_summary, :gross_income, :proceeding_types, 0, :result) + end + def gross_income_excess total_gross_income = api_response.dig(:result_summary, :gross_income, :total_gross_income) - upper_threshold = api_response.dig(:result_summary, :gross_income, :proceeding_types).first[:upper_threshold] + upper_threshold = api_response.dig(:result_summary, :gross_income, :proceeding_types, 0, :upper_threshold) total_gross_income - upper_threshold end diff --git a/app/models/check.rb b/app/models/check.rb index 4b05abdee..b5037c2c2 100644 --- a/app/models/check.rb +++ b/app/models/check.rb @@ -183,4 +183,12 @@ def owns_property_with_mortgage_or_loan? def owns_property_outright? Steps::Logic.owns_property_outright?(session_data) end + + def early_ineligible_result? + session_data.dig("early_result", "result") == "ineligible" + end + + def gross_income_excess + session_data.dig("early_result", "gross_income_excess") + end end diff --git a/app/views/question_flow/_early_result_banner.html.slim b/app/views/question_flow/_early_result_banner.html.slim new file mode 100644 index 000000000..0ce61f9c1 --- /dev/null +++ b/app/views/question_flow/_early_result_banner.html.slim @@ -0,0 +1,18 @@ +- if FeatureFlags.enabled?(:ee_banner, @check.session_data) && @check.early_ineligible_result? + .govuk-panel.panel-blue.govuk-panel--confirmation class="govuk-!-text-align-left govuk-!-margin-bottom-9" + .govuk-panel__body + h2.govuk-heading-l.white_text + = t("question_flow.early_result.gross_income.title", cfe_result_number: as_money_string(@check.gross_income_excess)) + + p.govuk-body.white_text class="govuk-!-font-weight-bold" + - if @check.controlled? + = t("question_flow.early_result.gross_income.controlled.para_1") + - else + = t("question_flow.early_result.gross_income.certificated.para_1") + + = link_to t("question_flow.early_result.gross_income.go_to_results"), + early_result_redirect_path(assessment_code: params[:assessment_code], step: @previous_step), + method: :post, + class: "govuk-button govuk-button--secondary govuk-!-margin-top-2", + role: "button", + id: "early-result-button" diff --git a/app/views/question_flow/forms/_outgoings.html.slim b/app/views/question_flow/forms/_outgoings.html.slim index 298d23d16..c35843f45 100644 --- a/app/views/question_flow/forms/_outgoings.html.slim +++ b/app/views/question_flow/forms/_outgoings.html.slim @@ -5,6 +5,7 @@ = form_for(@form, url: request.path, method: :put) do |form| = form.govuk_error_summary t("generic.error_summary_title") + = render partial: "question_flow/early_result_banner" = render "shared/heading", header_text: t("question_flow.#{i18n_key}.heading"), post_header_text: t("question_flow.#{i18n_key}.caption"), diff --git a/app/views/question_flow/how_to_aggregate.html.slim b/app/views/question_flow/how_to_aggregate.html.slim index 116b8392f..312c2d330 100644 --- a/app/views/question_flow/how_to_aggregate.html.slim +++ b/app/views/question_flow/how_to_aggregate.html.slim @@ -5,7 +5,7 @@ .govuk-grid-column-full = render "shared/heading" - .govuk-panel.panel-blue.govuk-panel--confirmation class="govuk-!-text-align-left govuk-!-margin-bottom-9" + .govuk-panel.panel-blue-white-text.govuk-panel--confirmation class="govuk-!-text-align-left govuk-!-margin-bottom-9" .govuk-panel__body h1.govuk-heading-l = t(".title") p.govuk-body = t(".panel_text") diff --git a/app/views/results/_capital_table.html.slim b/app/views/results/_capital_table.html.slim index 6a7525078..c414466d5 100644 --- a/app/views/results/_capital_table.html.slim +++ b/app/views/results/_capital_table.html.slim @@ -1,4 +1,5 @@ -- if @early_eligibility_selection == "gross" +/ ee_banner @early_eligibility_selection can be removed when FF is removed +- if @early_eligibility_selection == "gross" || @early_result_type == "gross_income" p class="govuk-body" = t(".not_assessed") - else - if @is_pdf == true diff --git a/app/views/results/_early_summary.html.slim b/app/views/results/_early_summary.html.slim new file mode 100644 index 000000000..1bdaba0ae --- /dev/null +++ b/app/views/results/_early_summary.html.slim @@ -0,0 +1,45 @@ +- data = @model.summary_data(section) +- status = data.status.dasherize + +- if @early_result_type == section.to_s + - total_calc = @model.send("total_calculated_#{section}") + +. class="summary-box summary-box-#{@early_result_type == section.to_s ? status : "not-assessed"}" + p.govuk-body-l.summary-list-subheader class="govuk-!-margin-bottom-0" = t("results.show.section_summaries.heading.#{section}") + h3.govuk-heading-l class="govuk-!-margin-bottom-2 govuk-!-margin-top-0" = total_calc + + - if @early_result_type != section.to_s + .govuk-tag + = t("results.show.section_summaries.not_assessed") + - elsif data.status == "ineligible" + .govuk-tag.govuk-tag--custom-red + = t("results.show.section_summaries.exceeds_upper_limit") + - elsif data.status == "contribution_required_and_overall_contribution_required" + .govuk-tag + = t("results.show.section_summaries.contribution_needed") + + p.govuk-body class="govuk-!-margin-top-3" + - upper_snippet = "_no_upper_threshold" if data.no_upper_threshold + - lower_snippet = "_no_lower_threshold" if data.no_lower_threshold + ruby: + matter_type = if @model.domestic_abuse_applicant + t("results.show.section_summaries.matter_types.domestic_abuse_applicant") + elsif @model.immigration_or_asylum_type_upper_tribunal + t("results.show.section_summaries.matter_types.#{@model.immigration_or_asylum_type_upper_tribunal}") + else + t("results.show.section_summaries.matter_types.none") + end + - if @early_result_type != section.to_s + => t("results.show.section_summaries.texts.not_assessed_desc") + - else + => t("results.show.section_summaries.texts.#{section}.#{data.status}#{upper_snippet}#{lower_snippet}", + upper_threshold: data.upper_threshold, + lower_threshold: data.lower_threshold, + matter_type:, + capital_contribution: @model.capital_contribution, + income_contribution: @model.income_contribution) + - if links + = link_to t("results.show.section_summaries.see_calculation"), + "##{data[:section]}", + class: "summary-box-link", + "aria-label": t("results.show.section_summaries.see_calculation_aria_label.#{data[:section]}") diff --git a/app/views/results/_outgoings_table.html.slim b/app/views/results/_outgoings_table.html.slim index 2edc3e3da..aff07a249 100644 --- a/app/views/results/_outgoings_table.html.slim +++ b/app/views/results/_outgoings_table.html.slim @@ -1,4 +1,5 @@ -- if @early_eligibility_selection == "gross" +/ ee_banner @early_eligibility_selection can be removed when FF is removed +- if @early_eligibility_selection == "gross" || @early_result_type == "gross_income" p class="govuk-body" = t(".not_assessed") - else = pdf_friendly_h2(t("results.show.client_outgoings"), "m", @is_pdf) diff --git a/app/views/results/_summary.html.slim b/app/views/results/_summary.html.slim index d9941e76d..191a8cb6d 100644 --- a/app/views/results/_summary.html.slim +++ b/app/views/results/_summary.html.slim @@ -1,5 +1,6 @@ - data = @model.summary_data(section) - status = data.status.dasherize +/ ee_banner: conditionals and reference to early_result can be removed when FF is removed - early_result = data.ineligible_gross_income == "gross" && section != :gross_income - unless early_result diff --git a/app/views/results/show.html.slim b/app/views/results/show.html.slim index bbd733a68..4523eed8e 100644 --- a/app/views/results/show.html.slim +++ b/app/views/results/show.html.slim @@ -9,15 +9,21 @@ .govuk-grid-column-full = render "shared/heading" - .govuk-panel.panel-blue.govuk-panel--confirmation class="govuk-!-text-align-left govuk-!-margin-bottom-9" + .govuk-panel.panel-blue-white-text.govuk-panel--confirmation class="govuk-!-text-align-left govuk-!-margin-bottom-9" .govuk-panel__body = render "result_panel_content" - if @model.any_calculations_performed? - h2.govuk-heading-m = t(".section_summaries.your_clients_key_eligibility_totals") - .summary-box-holder class="govuk-!-margin-bottom-5" - - %i[gross_income disposable_income capital].each - = render("summary", section: _1, links: true) if @model.calculated?(_1) + - if FeatureFlags.enabled?(:ee_banner, @check.session_data) && @early_result_type + h2.govuk-heading-m = t(".section_summaries.your_clients_key_eligibility_totals") + .summary-box-holder class="govuk-!-margin-bottom-5" + - %i[gross_income disposable_income capital].each + = render("early_summary", section: _1, links: true) if @model.calculated?(_1) + - else + h2.govuk-heading-m = t(".section_summaries.your_clients_key_eligibility_totals") + .summary-box-holder class="govuk-!-margin-bottom-5" + - %i[gross_income disposable_income capital].each + = render("summary", section: _1, links: true) if @model.calculated?(_1) - if @journey_continues_on_another_page h2.govuk-heading-m = t(".save_results") diff --git a/config/locales/en.yml b/config/locales/en.yml index 4c8743130..c6baab3fc 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1027,6 +1027,7 @@ en: para_1: We have enough information to tell you that your client will not qualify for legal aid. certificated: para_1: We have enough information to tell you that your client is not likely to qualify for legal aid. + go_to_results: Go to results page para_2: "You can:" help: Help with next steps details_para_1: "You can:" diff --git a/config/routes.rb b/config/routes.rb index 1bf3029ea..4235edbc0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,6 +72,7 @@ get "check-result/:assessment_code", to: "results#show", as: :result post "check-result/:assessment_code", to: "results#create" + post "check-result/:assessment_code/:step", to: "results#early_result_redirect", as: :early_result_redirect get ":step_url_fragment/:assessment_code", to: "forms#show", as: :step put ":step_url_fragment/:assessment_code", to: "forms#update" diff --git a/spec/end_to_end/result_page_variations_spec.rb b/spec/end_to_end/result_page_variations_spec.rb index f25d159cd..6dfe9b539 100644 --- a/spec/end_to_end/result_page_variations_spec.rb +++ b/spec/end_to_end/result_page_variations_spec.rb @@ -107,4 +107,34 @@ key_lines.each { expect(page).to have_content _1 } end end + + context "when ee_banner is switched on", :ee_banner do + # we need to remove this stubbing once we remove the feature flag + context "when early ineligible on gross_income", :stub_cfe_calls_with_webmock do + before do + allow(CfeService).to receive(:result).and_return(instance_double(CfeResult, ineligible_gross_income?: true, + gross_income_excess: 1000, gross_income_result: "ineligible")) + end + + it "does not show the disposable or capital result" do + start_assessment + fill_in_forms_until(:applicant) + fill_in_applicant_screen(partner: "No", passporting: "No") + fill_in_dependant_details_screen + fill_in_employment_status_screen(choice: "Employed or self-employed") + fill_in_income_screen(gross: "8000", frequency: "Every month") + fill_in_forms_until(:other_income) + fill_in_other_income_screen_with_friends_and_family + confirm_screen(:outgoings) + expect(page).to have_content("Gross monthly income limit exceeded") + click_on "Go to results page" + + key_lines = ["Your client is not likely to qualify financially for civil legal aid based on the information you entered", + "Disposable monthly income\nNot assessed\nThis was not assessed because it would not change the overall result", + "Disposable capital\nNot assessed\nThis was not assessed because it would not change the overall result"] + + key_lines.each { expect(page).to have_content _1 } + end + end + end end diff --git a/spec/flows/early_result_change_answers_flow_spec.rb b/spec/flows/early_result_change_answers_flow_spec.rb index 81edba1fc..91878d5aa 100644 --- a/spec/flows/early_result_change_answers_flow_spec.rb +++ b/spec/flows/early_result_change_answers_flow_spec.rb @@ -1,5 +1,7 @@ require "rails_helper" +# this whole spec file will become redundant with the switch to the ee_banner +# although we can write new specs to check the banner appears/disappears correctly RSpec.describe "Change answers after early result", type: :feature do let(:fixed_arbitrary_date) { Date.new(2023, 2, 15) } let(:eligibility_banner_content) { "Your changes have now put the client within the financial eligibility limits for legal aid. You now need to provide more information." } @@ -26,6 +28,91 @@ def stub_under_18_eligible ) end + context "when the new ee_banner is implemented", :ee_banner do + context "when starting as ineligible on gross income but continuing the check", :stub_cfe_gross_ineligible do + before do + start_assessment + fill_in_forms_until(:employment_status) + fill_in_employment_status_screen(choice: "Employed") + fill_in_income_screen(gross: "2700") + fill_in_benefits_screen + fill_in_other_income_screen + confirm_screen("outgoings") + fill_in_forms_until("check_answers") + end + + it "does not display banner from Change Answers page" do + within "#table-employment_status" do + click_on "Change" + end + expect(page).not_to have_content("Gross monthly income limit exceeded") + fill_in_employment_status_screen(choice: "Unemployed") + confirm_screen("check_answers") + end + + it "takes me on mini loops" do + start_assessment + fill_in_forms_until(:vehicle) + fill_in_vehicle_screen(choice: "Yes") + fill_in_vehicles_details_screen + fill_in_forms_until(:check_answers) + confirm_screen("check_answers") + within "#table-vehicle" do + click_on "Change" + end + fill_in_vehicle_screen(choice: "Yes") + fill_in_vehicles_details_screen + confirm_screen("check_answers") + end + + it "change to passported successfully" do + within "#table-applicant" do + click_on "Change" + end + fill_in_applicant_screen(passporting: "Yes") + confirm_screen("check_answers") + end + + it "change dependants successfully" do + within "#table-dependant_details" do + click_on "Change" + end + fill_in_dependant_details_screen({ child_dependants: "Yes", child_dependants_count: 1 }) + fill_in_dependant_income_screen + confirm_screen("outgoings") + fill_in_outgoings_screen + confirm_screen("check_answers") + click_on "Submit" + expect(page).to have_current_path(/\A\/check-result/) + # check that result isn't 'your answers have been deleted' + expect(page).to have_content "Your client's key eligibility totals" + end + end + + context "when starting as eligible on gross income" do + before do + start_assessment + stub_cfe_gross_eligible + fill_in_forms_until(:employment_status) + fill_in_employment_status_screen(choice: "Employed") + fill_in_income_screen(gross: "1000") + fill_in_benefits_screen + fill_in_other_income_screen + confirm_screen("outgoings") + fill_in_forms_until("check_answers") + end + + it "does not display banner" do + within "#table-income" do + click_on "Change" + end + fill_in_income_screen(gross: "3000", frequency: "Every month") + confirm_screen("check_answers") + expect(page).not_to have_content("Gross monthly income limit exceeded") + end + end + end + context "when starting as ineligible on gross income", :stub_cfe_gross_ineligible do # Default to certificated - it's mostly un-interesting let(:level_of_help) { "Civil certificated or licensed legal work" } diff --git a/spec/flows/early_result_spec.rb b/spec/flows/early_result_spec.rb index 177f39dda..ff03dd989 100644 --- a/spec/flows/early_result_spec.rb +++ b/spec/flows/early_result_spec.rb @@ -1,6 +1,7 @@ require "rails_helper" RSpec.describe "Early result journey", type: :feature do + # expected to fail when ee banner is turned on - tests can be deleted context "when I am ineligible on gross income" do before do allow(CfeService).to receive(:result).and_return(instance_double(CfeResult, ineligible_gross_income?: true, @@ -53,4 +54,92 @@ confirm_screen("ineligible_gross_income") end end + + # new ee banner functionality - tests should all pass and be kept + context "with ee banner switched on", :ee_banner, type: :feature do + context "when I am ineligible on gross income" do + before do + first = instance_double(CfeResult, ineligible_gross_income?: true, + gross_income_excess: 100, + gross_income_result: "ineligible") + second = instance_double(CfeResult, ineligible_gross_income?: false, + gross_income_excess: 0, + gross_income_result: "eligible") + allow(CfeService).to receive(:result).and_return(first, second) + allow(CfeService).to receive(:call).and_return build(:api_result, eligible: "ineligible") + start_assessment + fill_in_forms_until(:applicant) + fill_in_applicant_screen(partner: "No", passporting: "No") + fill_in_dependant_details_screen + fill_in_employment_status_screen(choice: "Employed or self-employed") + fill_in_income_screen(gross: "8000", frequency: "Every month") + fill_in_forms_until(:other_income) + fill_in_other_income_screen_with_friends_and_family + end + + it "when I continue the check" do + confirm_screen("outgoings") + expect(page).to have_content("Gross monthly income limit exceeded") + fill_in_outgoings_screen + expect(page).not_to have_content("Gross monthly income limit exceeded") + fill_in_forms_until(:check_answers) + click_on "Submit" + expect(page).to have_current_path(/\A\/check-result/) + expect(page).to have_content "Your client's key eligibility totals" + end + + it "when I go straight to results the check" do + confirm_screen("outgoings") + expect(page).to have_content("Gross monthly income limit exceeded") + click_on "Go to results page" + expect(page).to have_current_path(/\A\/check-result/) + expect(page).to have_content "Your client's key eligibility totals" + end + + context "when the early eligibility changes" do + it "back links and banner work as expected" do + confirm_screen("outgoings") + expect(page).to have_content("Gross monthly income limit exceeded") + click_on "Back" + confirm_screen("other_income") + expect(page).not_to have_content("Gross monthly income limit exceeded") + click_on "Back" + click_on "Back" + confirm_screen("income") + fill_in_income_screen(gross: "100", frequency: "Every month") + click_on "Save and continue" + fill_in_forms_until(:other_income) + fill_in_other_income_screen_with_friends_and_family + confirm_screen("outgoings") + expect(page).not_to have_content("Gross monthly income limit exceeded") + end + end + end + + context "when I am eligible" do + before do + allow(CfeService).to receive_messages(result: instance_double(CfeResult, ineligible_gross_income?: true, + gross_income_excess: 0, + gross_income_result: "eligible"), call: build(:api_result, eligible: "ineligible")) + start_assessment + fill_in_forms_until(:applicant) + fill_in_applicant_screen(partner: "No", passporting: "No") + fill_in_dependant_details_screen + fill_in_employment_status_screen(choice: "Employed or self-employed") + fill_in_income_screen(gross: "100", frequency: "Every month") + fill_in_forms_until(:other_income) + fill_in_other_income_screen_with_friends_and_family + end + + it "banner does not display and I can submit the check" do + confirm_screen("outgoings") + expect(page).not_to have_content("Gross monthly income limit exceeded") + fill_in_outgoings_screen + fill_in_forms_until(:check_answers) + click_on "Submit" + expect(page).to have_current_path(/\A\/check-result/) + expect(page).to have_content "Your client's key eligibility totals" + end + end + end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 94228c1d4..07b574fae 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -103,7 +103,11 @@ # This allows CFE to be called for early eligibility but return 'keep going' # for those tests that don't care (and typically stop at check answers anyway) config.before(:each, :calls_cfe_early_returns_not_ineligible) do - allow(CfeService).to receive(:result).and_return(instance_double(CfeResult, ineligible_gross_income?: false)) + if FeatureFlags.enabled?(:ee_banner, without_session_data: true) + allow(CfeService).to receive(:result).and_return(instance_double(CfeResult, ineligible_gross_income?: false, gross_income_result: "eligible", gross_income_excess: 0)) + else + allow(CfeService).to receive(:result).and_return(instance_double(CfeResult, ineligible_gross_income?: false)) + end end config.before(:each, :stub_cfe_gross_ineligible) do