|
1 | 1 | require "rails_helper" |
2 | 2 |
|
3 | 3 | RSpec.describe "court_dates/edit", type: :system do |
4 | | - let(:now) { Date.new(2021, 1, 1) } |
5 | 4 | let(:organization) { create(:casa_org) } |
6 | | - let(:admin) { create(:casa_admin, casa_org: organization) } |
7 | | - let(:supervisor) { create(:supervisor, casa_org: organization) } |
8 | | - let(:volunteer) { create(:volunteer, casa_org: organization) } |
9 | | - let!(:casa_case) { create(:casa_case, casa_org: organization) } |
10 | | - let!(:court_date) { create(:court_date, :with_court_details, casa_case: casa_case, date: now + 1.week) } |
| 5 | + |
| 6 | + let(:now) { Date.new(2021, 1, 1) } |
| 7 | + let(:displayed_date_format) { "%B %e, %Y" } |
| 8 | + let(:casa_case_number) { "CASA-CASE-NUMBER" } |
| 9 | + let!(:casa_case) { create(:casa_case, casa_org: organization, case_number: casa_case_number) } |
| 10 | + let(:court_date_as_date_object) { now + 1.week } |
| 11 | + let(:court_report_due_date_as_object) { now + 2.weeks } |
| 12 | + let!(:court_date) { create(:court_date, :with_court_details, casa_case: casa_case, court_report_due_date: court_report_due_date_as_object, date: court_date_as_date_object) } |
11 | 13 |
|
12 | 14 | before do |
13 | 15 | travel_to now |
14 | 16 | end |
15 | 17 |
|
16 | | - shared_examples "user able to view court date" do |user_type| |
| 18 | + shared_examples "a user able to view court date" do |user_type| |
17 | 19 | let(:user) { create(user_type, casa_org: organization) } |
18 | 20 |
|
19 | 21 | before(:all) do |
|
22 | 24 | end |
23 | 25 |
|
24 | 26 | it "can visit the court order page" do |
25 | | - expect(page).not_to have_content "Sorry, you are not authorized to perform this action." |
| 27 | + expect(page).not_to have_text "Sorry, you are not authorized to perform this action." |
26 | 28 | end |
27 | 29 |
|
28 | 30 | it "can see the court date" do |
| 31 | + expect(page).to have_text court_date_as_date_object.strftime(displayed_date_format) |
29 | 32 | end |
30 | 33 |
|
31 | 34 | it "can see the associated case number" do |
| 35 | + expect(page).to have_text casa_case_number |
32 | 36 | end |
33 | 37 |
|
34 | 38 | it "can see the associated court report due date" do |
| 39 | + expect(page).to have_text court_report_due_date.strftime(displayed_date_format) |
35 | 40 | end |
36 | 41 |
|
37 | 42 | it "can see the associated judge" do |
|
44 | 49 | end |
45 | 50 | end |
46 | 51 |
|
47 | | - shared_examples "user unable to view court date" do |user_type| |
| 52 | + shared_examples "a user unable to view court date" do |user_type| |
48 | 53 | let(:user) { create(user_type, casa_org: organization) } |
49 | 54 |
|
50 | 55 | it "is not allowed to visit the court order page" do |
51 | 56 | sign_in user |
52 | 57 | visit casa_case_court_date_path(casa_case, court_date) |
53 | 58 |
|
54 | | - expect(page).to have_content "Sorry, you are not authorized to perform this action." |
| 59 | + expect(page).to have_text "Sorry, you are not authorized to perform this action." |
55 | 60 | end |
56 | 61 | end |
57 | 62 |
|
58 | 63 | context "as a user from an organization not containing the court date" do |
59 | 64 | let(:organization) { create(:casa_org) } |
60 | 65 |
|
61 | | - it_should_behave_like "user unable to view court date", :admin |
62 | | - end |
63 | | - |
64 | | - context "as a volunteer not assigned to the case associated with the court case" do |
65 | | - it_should_behave_like "user unable to view court date", :volunteer |
| 66 | + it_should_behave_like "a user unable to view court date", :casa_admin |
66 | 67 | end |
67 | 68 |
|
68 | | - context "as a volunteer" do |
69 | | - it "can download a report which focuses on the court date", :js do |
70 | | - volunteer.casa_cases = [casa_case] |
71 | | - sign_in volunteer |
72 | | - |
73 | | - visit root_path |
74 | | - click_on "Cases" |
75 | | - click_on casa_case.case_number |
76 | | - |
77 | | - expect(CourtDate.count).to eq 2 |
78 | | - click_on "January 8, 2021" |
79 | | - expect(page).to have_content "Court Date" |
80 | | - |
81 | | - click_on "Download Report" |
82 | | - |
83 | | - wait_for_download |
| 69 | + context "as a user under the same org as the court date" do |
| 70 | + context "as a volunteer not assigned to the case associated with the court date" do |
| 71 | + it_should_behave_like "a user unable to view court date", :volunteer |
| 72 | + end |
84 | 73 |
|
85 | | - expect(download_docx.paragraphs.map(&:to_s)).to include("Hearing Date: January 8, 2021") |
| 74 | + context "as a volunteer assigned to the case associated with the court date" do |
| 75 | + it_should_behave_like "a user able to view court date" |
86 | 76 | end |
87 | 77 | end |
88 | 78 | end |
0 commit comments