Browse Source

Fix tests and lint

pull/739/head
Kat 3 years ago
parent
commit
836af2d60d
  1. 4
      app/models/scheme.rb
  2. 2
      app/views/form/_select_question.html.erb
  3. 48
      spec/features/form/accessible_autocomplete_spec.rb

4
app/models/scheme.rb

@ -148,10 +148,10 @@ class Scheme < ApplicationRecord
end end
def appended_text def appended_text
"(" + locations.count.to_s + " locations)" "(#{locations.count} locations)"
end end
def hint def hint
[primary_client_group, secondary_client_group].filter { |x| x.present? }.join(", ") [primary_client_group, secondary_client_group].filter(&:present?).join(", ")
end end
end end

2
app/views/form/_select_question.html.erb

@ -2,7 +2,7 @@
<% selected = @case_log.public_send(question.id) || "" %> <% selected = @case_log.public_send(question.id) || "" %>
<% answers = question.displayed_answer_options(@case_log).map { |key, value| OpenStruct.new(id: key, name: value.respond_to?(:service_name) ? value.service_name : nil, resource: value) } %> <% answers = question.displayed_answer_options(@case_log).map { |key, value| OpenStruct.new(id: key, name: value.respond_to?(:service_name) ? value.service_name : nil, resource: value) } %>
<%= f.govuk_select(question.id.to_sym, <%= f.govuk_select(question.id.to_sym,
label: legend(question, page_header, conditional), label: legend(question, page_header, conditional),
"data-controller": "accessible-autocomplete", "data-controller": "accessible-autocomplete",
caption: caption(caption_text, page_header, conditional), caption: caption(caption_text, page_header, conditional),

48
spec/features/form/accessible_autocomplete_spec.rb

@ -14,6 +14,7 @@ RSpec.describe "Accessible Automcomplete" do
is_la_inferred: false, is_la_inferred: false,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
created_by: user,
) )
end end
@ -23,12 +24,6 @@ RSpec.describe "Accessible Automcomplete" do
context "when using accessible autocomplete" do context "when using accessible autocomplete" do
before do before do
allow_any_instance_of(Form::Question).to receive(:answer_option_synonyms).and_call_original
allow_any_instance_of(Form::Question).to receive(:answer_option_synonyms).with("Manchester").and_return("synonym")
allow_any_instance_of(Form::Question).to receive(:answer_option_append).and_call_original
allow_any_instance_of(Form::Question).to receive(:answer_option_append).with("Manchester").and_return(" (append)")
allow_any_instance_of(Form::Question).to receive(:answer_option_hint).and_call_original
allow_any_instance_of(Form::Question).to receive(:answer_option_hint).with("Manchester").and_return("hint")
visit("/logs/#{case_log.id}/accessible-select") visit("/logs/#{case_log.id}/accessible-select")
end end
@ -52,21 +47,6 @@ RSpec.describe "Accessible Automcomplete" do
expect(find("#case-log-prevloc-field").value).to eq("The one and only york town") expect(find("#case-log-prevloc-field").value).to eq("The one and only york town")
end end
it "can match on synonyms", js: true do
find("#case-log-prevloc-field").click.native.send_keys("s", "y", "n", "o", "n", :down, :enter)
expect(find("#case-log-prevloc-field").value).to eq("Manchester")
end
it "displays appended text next to the options", js: true do
find("#case-log-prevloc-field").click.native.send_keys("m", "a", "n", :down, :enter)
expect(find(".autocomplete__option__append", visible: :hidden, text: /(append)/)).to be_present
end
it "displays hint text under the options", js: true do
find("#case-log-prevloc-field").click.native.send_keys("m", "a", "n", :down, :enter)
expect(find(".autocomplete__option__hint", visible: :hidden, text: /hint/)).to be_present
end
it "maintains enhancement state across back navigation", js: true do it "maintains enhancement state across back navigation", js: true do
find("#case-log-prevloc-field").click.native.send_keys("T", "h", "a", "n", :down, :enter) find("#case-log-prevloc-field").click.native.send_keys("T", "h", "a", "n", :down, :enter)
click_button("Save and continue") click_button("Save and continue")
@ -79,6 +59,32 @@ RSpec.describe "Accessible Automcomplete" do
end end
end end
context "when searching schemes" do
let(:scheme) { FactoryBot.create(:scheme, owning_organisation_id: case_log.created_by.organisation_id, primary_client_group: "Q", secondary_client_group: "P") }
before do
FactoryBot.create(:location, scheme:, postcode: "W6 0ST")
FactoryBot.create(:location, scheme:, postcode: "SE6 1LB")
case_log.update!(needstype: 2)
visit("/logs/#{case_log.id}/scheme")
end
it "can match on synonyms", js: true do
find("#case-log-scheme-id-field").click.native.send_keys("w", "6", :down, :enter)
expect(find("#case-log-scheme-id-field").value).to eq(scheme.service_name)
end
it "displays appended text next to the options", js: true do
find("#case-log-scheme-id-field").click.native.send_keys("w", "6", :down, :enter)
expect(find(".autocomplete__option__append", visible: :hidden, text: /(2 locations)/)).to be_present
end
it "displays hint text under the options", js: true do
find("#case-log-scheme-id-field").click.native.send_keys("w", "6", :down, :enter)
expect(find(".autocomplete__option__hint", visible: :hidden, text: /Young people at risk, Young people leaving care/)).to be_present
end
end
it "has the correct option selected if one has been saved" do it "has the correct option selected if one has been saved" do
case_log.update!(postcode_known: 0, previous_la_known: 1, prevloc: "Oxford") case_log.update!(postcode_known: 0, previous_la_known: 1, prevloc: "Oxford")
visit("/logs/#{case_log.id}/accessible-select") visit("/logs/#{case_log.id}/accessible-select")

Loading…
Cancel
Save