-
-
Notifications
You must be signed in to change notification settings - Fork 485
/
new_spec.rb
173 lines (138 loc) · 6.12 KB
/
new_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
require "rails_helper"
RSpec.describe "casa_cases/new", type: :system do
context "when signed in as a Casa Org Admin" do
context "when all fields are filled" do
it "is successful", js: true do
casa_org = build(:casa_org)
admin = create(:casa_admin, casa_org: casa_org)
contact_type_group = create(:contact_type_group, casa_org: casa_org)
contact_type = create(:contact_type, contact_type_group: contact_type_group)
case_number = "12345"
court_date = 21.days.from_now
sign_in admin
visit root_path
click_on "Cases"
click_on "New Case"
travel_to Time.zone.local(2020, 12, 1) do
fourteen_years = (Date.today.year - 14).to_s
fill_in "Case number", with: case_number
fill_in "Court Date", with: court_date
select "March", from: "casa_case_birth_month_year_youth_2i"
select fourteen_years, from: "casa_case_birth_month_year_youth_1i"
select "Submitted", from: "casa_case_court_report_status"
find(".ts-control").click
find("span", text: contact_type.name).click
within ".top-page-actions" do
click_on "Create CASA Case"
end
expect(page).to have_content(case_number)
expect(page).to have_content(I18n.l(court_date, format: :day_and_date))
expect(page).to have_content("CASA case was successfully created.")
expect(page).not_to have_content("Court Report Due Date: Thursday, 1-APR-2021") # accurate for frozen time
expect(page).to have_content("Transition Aged Youth: Yes")
end
end
end
context "when non-mandatory fields are not filled" do
it "is successful", js: true do
casa_org = build(:casa_org)
admin = create(:casa_admin, casa_org: casa_org)
contact_type_group = create(:contact_type_group, casa_org: casa_org)
contact_type = create(:contact_type, contact_type_group: contact_type_group)
case_number = "12345"
sign_in admin
visit new_casa_case_path
fill_in "Case number", with: case_number
fill_in "Next Court Date", with: DateTime.now.next_month
five_years = (Date.today.year - 5).to_s
select "March", from: "casa_case_birth_month_year_youth_2i"
select five_years, from: "casa_case_birth_month_year_youth_1i"
find(".ts-control").click
find("span", text: contact_type.name).click
within ".actions-cc" do
click_on "Create CASA Case"
end
expect(page).to have_content(case_number)
expect(page).to have_content("CASA case was successfully created.")
expect(page).to have_content("Next Court Date: ")
expect(page).not_to have_content("Court Report Due Date:")
expect(page).to have_content("Transition Aged Youth: No")
end
end
context "when the case number field is not filled" do
it "does not create a new case" do
casa_org = build(:casa_org)
admin = create(:casa_admin, casa_org: casa_org)
sign_in admin
visit new_casa_case_path
within ".actions-cc" do
click_on "Create CASA Case"
end
expect(page).to have_current_path(casa_cases_path, ignore_query: true)
expect(page).to have_content("Case number can't be blank")
end
end
context "when the court date field is not filled" do
context "when empty court date checkbox is checked" do
it "creates a new case", js: true do
casa_org = build(:casa_org)
admin = create(:casa_admin, casa_org: casa_org)
contact_type_group = create(:contact_type_group, casa_org: casa_org)
contact_type = create(:contact_type, contact_type_group: contact_type_group)
case_number = "12345"
sign_in admin
visit new_casa_case_path
fill_in "Case number", with: case_number
five_years = (Date.today.year - 5).to_s
select "March", from: "casa_case_birth_month_year_youth_2i"
select five_years, from: "casa_case_birth_month_year_youth_1i"
check "casa_case_empty_court_date"
find(".ts-control").click
find("span", text: contact_type.name).click
within ".actions-cc" do
click_on "Create CASA Case"
end
expect(page).to have_content(case_number)
expect(page).to have_content("CASA case was successfully created.")
expect(page).to have_content("Next Court Date:")
expect(page).not_to have_content("Court Report Due Date:")
expect(page).to have_content("Transition Aged Youth: No")
end
end
context "when empty court date checkbox is not checked" do
it "does not create a new case" do
casa_org = build(:casa_org)
admin = create(:casa_admin, casa_org: casa_org)
case_number = "12345"
sign_in admin
visit new_casa_case_path
fill_in "Case number", with: case_number
five_years = (Date.today.year - 5).to_s
select "March", from: "casa_case_birth_month_year_youth_2i"
select five_years, from: "casa_case_birth_month_year_youth_1i"
within ".actions-cc" do
click_on "Create CASA Case"
end
expect(page).to have_current_path(casa_cases_path, ignore_query: true)
expect(page).to have_content("Court dates date can't be blank")
end
end
end
context "when the case number already exists in the organization" do
it "does not create a new case" do
casa_org = build(:casa_org)
admin = create(:casa_admin, casa_org: casa_org)
case_number = "12345"
_existing_casa_case = create(:casa_case, case_number: case_number, casa_org: casa_org)
sign_in admin
visit new_casa_case_path
fill_in "Case number", with: case_number
within ".actions-cc" do
click_on "Create CASA Case"
end
expect(page).to have_current_path(casa_cases_path, ignore_query: true)
expect(page).to have_content("Case number has already been taken")
end
end
end
end