diff --git a/app/helpers/tab_nav_helper.rb b/app/helpers/tab_nav_helper.rb
index 1f6db638e..6e482b7ff 100644
--- a/app/helpers/tab_nav_helper.rb
+++ b/app/helpers/tab_nav_helper.rb
@@ -13,7 +13,8 @@ module TabNavHelper
def scheme_cell(scheme)
link_text = scheme.service_name
- [govuk_link_to(link_text, scheme), "Scheme #{scheme.primary_client_group}"].join("\n")
+ link = scheme.confirmed? ? scheme : scheme_check_answers_path(scheme)
+ [govuk_link_to(link_text, link), "Scheme #{scheme.primary_client_group}"].join("\n")
end
def org_cell(user)
diff --git a/app/models/scheme.rb b/app/models/scheme.rb
index accc4f17c..5ac48b310 100644
--- a/app/models/scheme.rb
+++ b/app/models/scheme.rb
@@ -6,7 +6,7 @@ class Scheme < ApplicationRecord
scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) }
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") }
- scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") }
+ scope :search_by_postcode, ->(postcode) { joins("LEFT JOIN locations ON locations.scheme_id = schemes.id").where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(filter_by_id(param)).distinct }
validate :validate_confirmed
diff --git a/app/views/schemes/_scheme_list.html.erb b/app/views/schemes/_scheme_list.html.erb
index c0a640103..976622ce0 100644
--- a/app/views/schemes/_scheme_list.html.erb
+++ b/app/views/schemes/_scheme_list.html.erb
@@ -29,7 +29,7 @@
<% row.cell(text: simple_format(scheme_cell(scheme), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: scheme.locations&.count) %>
<% row.cell(text: scheme.managing_organisation&.name) %>
- <% row.cell(text: scheme.created_at.to_formatted_s(:govuk_date)) %>
+ <% row.cell(text: scheme.confirmed? ? scheme.created_at.to_formatted_s(:govuk_date) : govuk_tag(colour: "grey", text: "Incomplete")) %>
<% end %>
<% end %>
<% end %>
diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb
index b0ab10d18..2cece714f 100644
--- a/spec/features/schemes_spec.rb
+++ b/spec/features/schemes_spec.rb
@@ -119,6 +119,14 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content(scheme_to_search.id_to_display)
end
+ it "returns results with no location" do
+ scheme_without_location = FactoryBot.create(:scheme)
+ visit "/schemes"
+ fill_in("search", with: scheme_without_location.id_to_display)
+ click_button("Search")
+ expect(page).to have_content(scheme_without_location.id_to_display)
+ end
+
it "allows clearing the search results" do
fill_in("search", with: scheme_to_search.id_to_display)
click_button("Search")
diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb
index 1b5a187fd..8549d79f0 100644
--- a/spec/requests/schemes_controller_spec.rb
+++ b/spec/requests/schemes_controller_spec.rb
@@ -68,6 +68,19 @@ RSpec.describe SchemesController, type: :request do
end
end
+ it "shows incomplete tag if the scheme is not confirmed" do
+ schemes[0].update!(confirmed: nil)
+ get "/schemes"
+ assert_select ".govuk-tag", text: /Incomplete/, count: 1
+ end
+
+ it "displays a link to check answers page if the scheme is incomplete" do
+ scheme = schemes[0]
+ scheme.update!(confirmed: nil)
+ get "/schemes"
+ expect(page).to have_link(nil, href: /schemes\/#{scheme.id}\/check-answers/)
+ end
+
it "shows a search bar" do
expect(page).to have_field("search", type: "search")
end
@@ -166,6 +179,15 @@ RSpec.describe SchemesController, type: :request do
end
end
+ it "returns results with no location" do
+ scheme_without_location = FactoryBot.create(:scheme)
+ get "/schemes?search=#{scheme_without_location.id}"
+ expect(page).to have_content(scheme_without_location.id_to_display)
+ schemes.each do |scheme|
+ expect(page).not_to have_content(scheme.id_to_display)
+ end
+ end
+
it "updates the table caption" do
expect(page).to have_content("1 scheme found matching ‘#{search_param}’")
end