diff --git a/app/views/case_court_reports/index.html.erb b/app/views/case_court_reports/index.html.erb
index 7efb730310..d4495565a0 100644
--- a/app/views/case_court_reports/index.html.erb
+++ b/app/views/case_court_reports/index.html.erb
@@ -13,12 +13,18 @@
<%= label_tag :case_number, t(".label.case_number") %>
<% select_options = @assigned_cases.map { |casa_case| casa_case.decorate.court_report_select_option } %>
+
+ <% show_search = !current_user.volunteer? %>
+
+ <% select_case_prompt = show_search ? t(".prompt.search_case_number") : t(".prompt.select_case_number") %>
+ <% select2_class = show_search ? "select2" : "" %>
+
<%= select_tag :case_number,
options_for_select(select_options),
- prompt: t(".prompt.select_case_number"),
+ prompt: select_case_prompt,
include_blank: false,
id: "case-selection",
- class: "custom-select select2" %>
+ class: "custom-select #{select2_class}" %>
diff --git a/config/locales/views.en.yml b/config/locales/views.en.yml
index 65b063c351..105bd5863e 100644
--- a/config/locales/views.en.yml
+++ b/config/locales/views.en.yml
@@ -179,7 +179,8 @@ en:
label:
case_number: "Case Number:"
prompt:
- select_case_number: Search by volunteer name or case number
+ select_case_number: Select case number
+ search_case_number: Search by volunteer name or case number
button:
generate: Generate Report
download: Download Court Report
diff --git a/spec/system/case_court_reports/index_spec.rb b/spec/system/case_court_reports/index_spec.rb
index 9bf04ba8b2..2953f9bcfe 100644
--- a/spec/system/case_court_reports/index_spec.rb
+++ b/spec/system/case_court_reports/index_spec.rb
@@ -2,6 +2,7 @@
RSpec.describe "case_court_reports/index", :disable_bullet, type: :system do
let(:volunteer) { create(:volunteer, :with_cases_and_contacts, :with_assigned_supervisor, display_name: "Name Last") }
+ let(:supervisor) { volunteer.supervisor }
let(:casa_cases) { CasaCase.actively_assigned_to(volunteer) }
before do
@@ -16,8 +17,10 @@
expect(page).to have_selector "#btnGenerateReport", **options
end
- it "shows a select element with default selection 'Search by volunteer name or case number'" do
- expected_text = "Search by volunteer name or case number"
+ it { expect(page).not_to have_selector ".select2" }
+
+ it "shows a select element with default selection 'Select case number'" do
+ expected_text = "Select case number"
find("#case-selection").click.first("option", text: expected_text).select_option
expect(page).to have_selector "#case-selection option:first-of-type", text: expected_text
@@ -51,14 +54,14 @@
end
context "when choosing the prompt option (value is empty) and click on 'Generate Report' button, nothing should happen", js: true do
- let(:option_text) { "Search by volunteer name or case number" }
+ let(:option_text) { "Select case number" }
before do
# to find the select element, use either 'name' or 'id' attribute
# in this case, id = "case-selection", name = "case_number"
- page.select "Search by volunteer name or case number", from: "case-selection"
+ page.select "Select case number", from: "case-selection"
# the above will have the same effect as the below
- # find("#case-selection").select "Search by volunteer name or case number"
+ # find("#case-selection").select "Select case number"
click_button "Generate Report"
end
@@ -197,4 +200,29 @@
end
end
end
+
+ describe "as a supervisor" do
+ before do
+ sign_in supervisor
+ visit case_court_reports_path
+ end
+
+ it { expect(page).to have_selector ".select2" }
+ it { expect(page).to have_text "Search by volunteer name or case number" }
+
+ context "when searching for cases" do
+ let(:casa_case) { volunteer.casa_cases.first }
+ let(:search_term) { casa_case.case_number[-3..] }
+
+ it "selects the correct case", js: true do
+ page.find("span.select2").click
+ page.find(".select2-search__field").click
+
+ send_keys(search_term)
+ send_keys :enter
+
+ expect(find(".select2-selection__rendered").text).to match /^#{casa_case.case_number}/
+ end
+ end
+ end
end