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