|
38 | 38 |
|
39 | 39 | sign_in user |
40 | 40 | visit reports_path |
| 41 | + end |
41 | 42 |
|
| 43 | + it "redirects to root", :aggregate_failures do |
42 | 44 | expect(page).not_to have_text "Case Contacts Report" |
43 | 45 | expect(page).to have_text "Sorry, you are not authorized to perform this action." |
44 | 46 | end |
45 | 47 | end |
46 | 48 |
|
47 | | - context "supervisor user" do |
48 | | - it "renders form elements", :js do |
49 | | - user = create(:supervisor) |
50 | | - |
51 | | - sign_in user |
52 | | - visit reports_path |
53 | | - |
54 | | - expect(page).to have_text "Case Contacts Report" |
55 | | - expect(page).to have_field("report_start_date", with: 6.months.ago.strftime("%Y-%m-%d")) |
56 | | - expect(page).to have_field("report_end_date", with: Date.today) |
57 | | - expect(page).to have_text "Assigned To" |
58 | | - expect(page).to have_text "Volunteers" |
59 | | - expect(page).to have_text "Contact Type" |
60 | | - expect(page).to have_text "Contact Type Group" |
61 | | - expect(page).to have_text "Want Driving Reimbursement" |
62 | | - expect(page).to have_text "Contact Made" |
63 | | - expect(page).to have_text "Transition Aged Youth" |
64 | | - expect(page).to have_field("Both", count: 3) |
65 | | - expect(page).to have_field("Yes", count: 3) |
66 | | - expect(page).to have_field("No", count: 3) |
67 | | - end |
68 | | - |
69 | | - it "downloads report", :js do |
70 | | - user = create(:supervisor) |
71 | | - |
72 | | - sign_in user |
73 | | - visit reports_path |
74 | | - |
75 | | - click_on "Download Report" |
76 | | - expect(page).to have_text("Downloading Report") |
| 49 | + %i[supervisor casa_admin].each do |role| |
| 50 | + # rubocop:disable RSpec/MultipleMemoizedHelpers |
| 51 | + context "with a #{role} user" do |
| 52 | + let(:user) { create(role) } |
| 53 | + let(:volunteer_name) { Faker::Name.unique.name } |
| 54 | + let(:supervisor_name) { Faker::Name.unique.name } |
| 55 | + let(:contact_type_name) { Faker::Lorem.unique.word } |
| 56 | + let(:contact_type_group_name) { Faker::Lorem.unique.word } |
| 57 | + let(:filter_start_date) { "2025-01-01" } |
| 58 | + let(:filter_end_date) { "2025-10-08" } |
| 59 | + |
| 60 | + before do |
| 61 | + sign_in user |
| 62 | + visit reports_path |
| 63 | + end |
| 64 | + |
| 65 | + it "renders form elements", :aggregate_failures do |
| 66 | + expect(page).to have_text "Case Contacts Report" |
| 67 | + expect(page).to have_field("report_start_date", with: 6.months.ago.strftime("%Y-%m-%d")) |
| 68 | + expect(page).to have_field("report_end_date", with: Date.today) |
| 69 | + expect(page).to have_text "Assigned To" |
| 70 | + expect(page).to have_text "Volunteers" |
| 71 | + expect(page).to have_text "Contact Type" |
| 72 | + expect(page).to have_text "Contact Type Group" |
| 73 | + expect(page).to have_text "Want Driving Reimbursement" |
| 74 | + expect(page).to have_text "Contact Made" |
| 75 | + expect(page).to have_text "Transition Aged Youth" |
| 76 | + expect(page).to have_field("Both", count: 3) |
| 77 | + expect(page).to have_field("Yes", count: 3) |
| 78 | + expect(page).to have_field("No", count: 3) |
| 79 | + end |
| 80 | + |
| 81 | + it "downloads case contacts report with default filters" do |
| 82 | + click_on "Download Report" |
| 83 | + expect(page).to have_text("Downloading Report") |
| 84 | + end |
| 85 | + |
| 86 | + include_examples "downloads report button", "Mileage Report", "Downloading Mileage Report" |
| 87 | + include_examples "downloads report button", "Missing Data Report", "Downloading Missing Data Report" |
| 88 | + include_examples "downloads report button", "Learning Hours Report", "Downloading Learning Hours Report" |
| 89 | + include_examples "downloads report button", "Export Volunteers Emails", "Downloading Export Volunteers Emails" |
| 90 | + include_examples "downloads report button", "Followups Report", "Downloading Followups Report" |
| 91 | + include_examples "downloads report button", "Placements Report", "Downloading Placements Report" |
| 92 | + |
| 93 | + shared_examples "case contacts report with filter" do |filter_type| |
| 94 | + it "downloads case contacts report with #{filter_type}" do |
| 95 | + click_on "Download Report" |
| 96 | + expect(page).to have_text("Downloading Report") |
| 97 | + end |
| 98 | + end |
| 99 | + |
| 100 | + context "with an assigned supervisor filter" do |
| 101 | + before do |
| 102 | + create(:supervisor, casa_org: user.casa_org, display_name: supervisor_name) |
| 103 | + visit reports_path |
| 104 | + select_report_filter_option(SUPERVISOR_SELECT_ID, supervisor_name) |
| 105 | + end |
| 106 | + |
| 107 | + include_examples "case contacts report with filter", "assigned supervisor" |
| 108 | + end |
| 109 | + |
| 110 | + context "with a volunteer filter" do |
| 111 | + before do |
| 112 | + create(:volunteer, casa_org: user.casa_org, display_name: volunteer_name) |
| 113 | + visit reports_path |
| 114 | + select_report_filter_option(VOLUNTEER_SELECT_ID, volunteer_name) |
| 115 | + end |
| 116 | + |
| 117 | + include_examples "case contacts report with filter", "volunteer" |
| 118 | + end |
| 119 | + |
| 120 | + context "with a contact type filter" do |
| 121 | + before do |
| 122 | + create(:contact_type, casa_org: user.casa_org, name: contact_type_name) |
| 123 | + visit reports_path |
| 124 | + select_report_filter_option(CONTACT_TYPE_SELECT_ID, contact_type_name) |
| 125 | + end |
| 126 | + |
| 127 | + include_examples "case contacts report with filter", "contact type" |
| 128 | + end |
| 129 | + |
| 130 | + context "with a contact type group filter" do |
| 131 | + before do |
| 132 | + create(:contact_type_group, casa_org: user.casa_org, name: contact_type_group_name) |
| 133 | + visit reports_path |
| 134 | + select_report_filter_option(CONTACT_TYPE_GROUP_SELECT_ID, contact_type_group_name) |
| 135 | + end |
| 136 | + |
| 137 | + include_examples "case contacts report with filter", "contact type group" |
| 138 | + end |
| 139 | + |
| 140 | + context "with a driving reimbursement filter" do |
| 141 | + before do |
| 142 | + visit reports_path |
| 143 | + choose_report_radio_option("want_driving_reimbursement", "true") |
| 144 | + end |
| 145 | + |
| 146 | + include_examples "case contacts report with filter", "driving reimbursement" |
| 147 | + end |
| 148 | + |
| 149 | + context "with a contact made filters" do |
| 150 | + before do |
| 151 | + visit reports_path |
| 152 | + choose_report_radio_option("contact_made", "true") |
| 153 | + end |
| 154 | + |
| 155 | + include_examples "case contacts report with filter", "contact made" |
| 156 | + end |
| 157 | + |
| 158 | + context "with a transition aged youth filter" do |
| 159 | + before do |
| 160 | + visit reports_path |
| 161 | + choose_report_radio_option("has_transitioned", "true") |
| 162 | + end |
| 163 | + |
| 164 | + include_examples "case contacts report with filter", "transition aged youth" |
| 165 | + end |
| 166 | + |
| 167 | + context "with a date range filter" do |
| 168 | + before do |
| 169 | + visit reports_path |
| 170 | + set_report_date_range(start_date: filter_start_date, end_date: filter_end_date) |
| 171 | + end |
| 172 | + |
| 173 | + include_examples "case contacts report with filter", "date range" |
| 174 | + end |
| 175 | + |
| 176 | + context "with multiple filters" do |
| 177 | + before do |
| 178 | + create(:volunteer, casa_org: user.casa_org, display_name: volunteer_name) |
| 179 | + create(:contact_type, casa_org: user.casa_org, name: contact_type_name) |
| 180 | + visit reports_path |
| 181 | + set_report_date_range(start_date: filter_start_date, end_date: filter_end_date) |
| 182 | + select_report_filter_option(VOLUNTEER_SELECT_ID, volunteer_name) |
| 183 | + select_report_filter_option(CONTACT_TYPE_SELECT_ID, contact_type_name) |
| 184 | + choose_report_radio_option("want_driving_reimbursement", "false") |
| 185 | + end |
| 186 | + |
| 187 | + include_examples "case contacts report with filter", "multiple filters" |
| 188 | + end |
| 189 | + |
| 190 | + context "with no volunteers in the org" do |
| 191 | + include_examples "empty select downloads report", VOLUNTEER_SELECT_ID, "volunteers" |
| 192 | + end |
| 193 | + |
| 194 | + context "with no contact type groups in the org" do |
| 195 | + include_examples "empty select downloads report", CONTACT_TYPE_GROUP_SELECT_ID, "contact type groups" |
| 196 | + end |
| 197 | + |
| 198 | + context "with no contact types in the org" do |
| 199 | + include_examples "empty select downloads report", CONTACT_TYPE_SELECT_ID, "contact types" |
| 200 | + end |
77 | 201 | end |
| 202 | + # rubocop:enable RSpec/MultipleMemoizedHelpers |
78 | 203 | end |
79 | 204 |
|
80 | | - context "casa_admin user" do |
81 | | - it "renders form elements", :js do |
82 | | - user = create(:casa_admin) |
| 205 | + private |
83 | 206 |
|
84 | | - sign_in user |
85 | | - visit reports_path |
86 | | - |
87 | | - expect(page).to have_text "Case Contacts Report" |
88 | | - expect(page).to have_field("report_start_date", with: 6.months.ago.strftime("%Y-%m-%d")) |
89 | | - expect(page).to have_field("report_end_date", with: Date.today) |
90 | | - expect(page).to have_text "Assigned To" |
91 | | - expect(page).to have_text "Volunteers" |
92 | | - expect(page).to have_text "Contact Type" |
93 | | - expect(page).to have_text "Contact Type Group" |
94 | | - expect(page).to have_text "Want Driving Reimbursement" |
95 | | - expect(page).to have_text "Contact Made" |
96 | | - expect(page).to have_text "Transition Aged Youth" |
97 | | - expect(page).to have_field("Both", count: 3) |
98 | | - expect(page).to have_field("Yes", count: 3) |
99 | | - expect(page).to have_field("No", count: 3) |
100 | | - end |
101 | | - |
102 | | - it "downloads report", :js do |
103 | | - user = create(:casa_admin) |
104 | | - |
105 | | - sign_in user |
106 | | - visit reports_path |
107 | | - |
108 | | - click_on "Download Report" |
109 | | - expect(page).to have_text("Downloading Report") |
110 | | - end |
111 | 207 | def select_report_filter_option(select_id, option) |
112 | 208 | expect(page).to have_select(select_id, with_options: [option]) |
113 | 209 | find("##{select_id}").select(option) |
|
0 commit comments