Browse Source

Cldc 1392 schemes list (#784)

* shows incomplete tag if the scheme is not confirmed

* displays a link to check answers page if the scheme is incomplete

* return schemes with no location when searching

* update tests

* lint
pull/785/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
8e67c805f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/helpers/tab_nav_helper.rb
  2. 2
      app/models/scheme.rb
  3. 2
      app/views/schemes/_scheme_list.html.erb
  4. 8
      spec/features/schemes_spec.rb
  5. 22
      spec/requests/schemes_controller_spec.rb

3
app/helpers/tab_nav_helper.rb

@ -13,7 +13,8 @@ module TabNavHelper
def scheme_cell(scheme) def scheme_cell(scheme)
link_text = scheme.service_name link_text = scheme.service_name
[govuk_link_to(link_text, scheme), "<span class=\"govuk-visually-hidden\">Scheme </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{scheme.primary_client_group}</span>"].join("\n") link = scheme.confirmed? ? scheme : scheme_check_answers_path(scheme)
[govuk_link_to(link_text, link), "<span class=\"govuk-visually-hidden\">Scheme </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{scheme.primary_client_group}</span>"].join("\n")
end end
def org_cell(user) def org_cell(user)

2
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 :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_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 } scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(filter_by_id(param)).distinct }
validate :validate_confirmed validate :validate_confirmed

2
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: simple_format(scheme_cell(scheme), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: scheme.locations&.count) %> <% row.cell(text: scheme.locations&.count) %>
<% row.cell(text: scheme.managing_organisation&.name) %> <% 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 %> <% end %>
<% end %> <% end %>

8
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) expect(page).to have_content(scheme_to_search.id_to_display)
end 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 it "allows clearing the search results" do
fill_in("search", with: scheme_to_search.id_to_display) fill_in("search", with: scheme_to_search.id_to_display)
click_button("Search") click_button("Search")

22
spec/requests/schemes_controller_spec.rb

@ -68,6 +68,19 @@ RSpec.describe SchemesController, type: :request do
end end
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 it "shows a search bar" do
expect(page).to have_field("search", type: "search") expect(page).to have_field("search", type: "search")
end end
@ -166,6 +179,15 @@ RSpec.describe SchemesController, type: :request do
end end
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 it "updates the table caption" do
expect(page).to have_content("1 scheme found matching ‘#{search_param}") expect(page).to have_content("1 scheme found matching ‘#{search_param}")
end end

Loading…
Cancel
Save