Skip to content

Commit

Permalink
Restrict case court report searching to admins and supervisors
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhian Moraes committed Jun 21, 2021
1 parent 25148cb commit 3b34941
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
10 changes: 8 additions & 2 deletions app/views/case_court_reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
<div class="field form-group">
<%= 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}" %>

</div>
<div class="form-group">
Expand Down
3 changes: 2 additions & 1 deletion config/locales/views.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 33 additions & 5 deletions spec/system/case_court_reports/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 3b34941

Please sign in to comment.