From bbb3074b85fc39fef83463ec16bc06d6a91cf69c Mon Sep 17 00:00:00 2001 From: Abigail McPhillips Date: Mon, 11 Sep 2023 13:19:34 +0300 Subject: [PATCH] Add 'No teachers found' content and link back to search page --- app/views/check_records/search/show.html.erb | 58 ++++++++++--------- spec/support/fake_qualifications_api.rb | 2 + .../user_searches_with_no_matches_spec.rb | 29 ++++++++++ 3 files changed, 63 insertions(+), 26 deletions(-) create mode 100644 spec/system/check_records/user_searches_with_no_matches_spec.rb diff --git a/app/views/check_records/search/show.html.erb b/app/views/check_records/search/show.html.erb index 3539c314..31977338 100644 --- a/app/views/check_records/search/show.html.erb +++ b/app/views/check_records/search/show.html.erb @@ -4,32 +4,38 @@

Search results (<%= @total %>)

+ <% if @total.zero? %> +

+ No teachers found. + <%= govuk_link_to("Try another search", check_records_search_path) %>. +

+ <% else %> +
+ <% @teachers.each do |teacher| %> +
+

+ <%= link_to teacher.name, check_records_teacher_path(teacher.trn), class: "govuk-link--no-visited-state" %> +

+ "%> + <%= teacher.sanctions.any? ? "Restrictions" : "No restrictions" %> + -
- <% @teachers.each do |teacher| %> -
-

- <%= link_to teacher.name, check_records_teacher_path(teacher.trn), class: "govuk-link--no-visited-state" %> -

- "%> - <%= teacher.sanctions.any? ? "Restrictions" : "No restrictions" %> - - - <% - rows = [ - { - key: { text: "TRN" }, - value: { text: teacher.trn } - }, - { - key: { text: "Date of birth" }, - value: { text: Date.parse(teacher.date_of_birth).to_fs(:long_uk) } - } - ] - %> - <%= render GovukComponent::SummaryListComponent.new(rows:, borders: false, classes: ['app-summary-list--compact']) %> -
- <% end %> -
+ <% + rows = [ + { + key: { text: "TRN" }, + value: { text: teacher.trn } + }, + { + key: { text: "Date of birth" }, + value: { text: Date.parse(teacher.date_of_birth).to_fs(:long_uk) } + } + ] + %> + <%= render GovukComponent::SummaryListComponent.new(rows:, borders: false, classes: ['app-summary-list--compact']) %> +
+ <% end %> +
+ <% end %>
diff --git a/spec/support/fake_qualifications_api.rb b/spec/support/fake_qualifications_api.rb index 8cf1742d..7f66f60a 100644 --- a/spec/support/fake_qualifications_api.rb +++ b/spec/support/fake_qualifications_api.rb @@ -17,6 +17,8 @@ class FakeQualificationsApi < Sinatra::Base case bearer_token when "token" + return { total: 0, results: [] }.to_json if params["lastName"] == "No match" + { total: 1, results: [teacher_data(sanctions: params["lastName"] == "Restricted")] diff --git a/spec/system/check_records/user_searches_with_no_matches_spec.rb b/spec/system/check_records/user_searches_with_no_matches_spec.rb new file mode 100644 index 00000000..4c4de045 --- /dev/null +++ b/spec/system/check_records/user_searches_with_no_matches_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +RSpec.describe "No matches", host: :check_records, type: :system do + include ActivateFeaturesSteps + include CheckRecords::AuthenticationSteps + + scenario "User searches with a last name and date of birth and finds no matches", + test: %i[with_stubbed_auth with_fake_quals_api] do + given_the_service_is_open + when_i_sign_in_via_dsi + and_search_returns_no_records + then_i_see_no_records + end + + private + + def and_search_returns_no_records + fill_in "Last name", with: "No match" + fill_in "Day", with: "1" + fill_in "Month", with: "1" + fill_in "Year", with: "1990" + click_button "Find record" + end + + def then_i_see_no_records + expect(page).to have_content("No teachers found") + expect(page).to have_link("Try another search") + end +end