From c54be8cd7fffc3c3e0c571bc176617a38b9bfdae Mon Sep 17 00:00:00 2001 From: Rhian Moraes Date: Mon, 21 Jun 2021 11:45:56 -0300 Subject: [PATCH 1/2] Restrict case court report searching to admins and supervisors --- app/views/case_court_reports/index.html.erb | 10 ++++- config/locales/views.en.yml | 3 +- spec/system/case_court_reports/index_spec.rb | 39 +++++++++++++++++--- 3 files changed, 44 insertions(+), 8 deletions(-) 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..4f880db203 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 @@ -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 @@ -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 From 6de3c2f4bdba01951b1e781ba859b38a4ebe992c Mon Sep 17 00:00:00 2001 From: Rhian Moraes Date: Tue, 22 Jun 2021 11:03:57 -0300 Subject: [PATCH 2/2] Fix generate court report cypress spec --- .../volunteer/generate_court_report.spec.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cypress/integration/volunteer/generate_court_report.spec.js b/cypress/integration/volunteer/generate_court_report.spec.js index 895b01422a..b47dbe86f4 100644 --- a/cypress/integration/volunteer/generate_court_report.spec.js +++ b/cypress/integration/volunteer/generate_court_report.spec.js @@ -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();