Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2150] Restrict case court report searching to admins and supervisors #2176

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 6 additions & 4 deletions cypress/integration/volunteer/generate_court_report.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ context("Logging into cypress as a volunteer", () => {
it("should generate a court report", () => {
cy.get("#toggle-sidebar-js").click();
cy.contains("Generate Court Reports").click();
// Pick the first option from the case selection dropdown
cy.get('#case-selection')
.find('option').then(elements => {
const option = elements[1].getAttribute('value');

// Pick the first non-blank option from the case selection dropdown
cy.get("#case-selection option")
.eq(2)
.then(element => {
const option = element.val()
cy.get('#case-selection').select(option, {force: true});

cy.contains("Generate Report").click();
Expand Down
39 changes: 34 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 @@ -136,6 +139,7 @@
# to find the select element, use either 'name' or 'id' attribute
# in this case, id = "case-selection", name = "case_number"
page.select option_text, from: "case-selection"

@download_window = window_opened_by do
click_button "Generate Report"
end
Expand Down Expand Up @@ -197,4 +201,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