Skip to content

Commit 44f18be

Browse files
Move more system tests to request specs
System tests are costly to maintain. Leaving just the tests that make more sense to be tested in the browser.
1 parent 9d87f0d commit 44f18be

2 files changed

Lines changed: 45 additions & 60 deletions

File tree

spec/requests/requests_requests_spec.rb

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
response
1212
end
1313

14-
before do
15-
create(:request)
16-
end
17-
1814
context "html" do
1915
let(:response_format) { 'html' }
2016

@@ -25,6 +21,33 @@
2521
let(:response_format) { 'csv' }
2622

2723
it { is_expected.to be_successful }
24+
25+
context 'when exporting as CSV' do
26+
it "exports only the cancelled requests CSV when 'Include Cancelled' is checked and 'Filter by Status' is 'Cancelled'" do
27+
create(:request, :started)
28+
create(:request, :cancelled)
29+
30+
get requests_path(format: :csv, params: {include_cancelled: "1", filters: { by_status: :cancelled}})
31+
32+
csv = CSV.parse(response.body, headers: true)
33+
34+
expect(csv.count).to eq(1)
35+
expect(csv.first["Status"]).to eq("Cancelled")
36+
end
37+
38+
it "exports the requests CSV including cancelled requests when 'Include Cancelled' is checked" do
39+
create(:request, :started)
40+
create(:request, :cancelled)
41+
42+
get requests_path(format: :csv, params: {include_cancelled: "1"})
43+
44+
csv = CSV.parse(response.body, headers: true)
45+
46+
expect(csv.count).to eq(2)
47+
expect(csv[0]["Status"]).to eq("Started")
48+
expect(csv[1]["Status"]).to eq("Cancelled")
49+
end
50+
end
2851
end
2952

3053
context "when there are pending or started requests" do
@@ -190,6 +213,24 @@
190213
expect(response.body).not_to include('Units (if applicable)')
191214
end
192215
end
216+
217+
context 'when the request has a cancelled status' do
218+
it 'does not display the Cancel and Fulfill request buttons' do
219+
cancelled_request = create(:request, :cancelled, organization:)
220+
221+
get request_path(cancelled_request)
222+
223+
page = Nokogiri::HTML(response.body)
224+
225+
cancel_button = page.at_css("form[action='/requests/#{cancelled_request.id}/cancelation/new']")
226+
fulfill_button = page.at_css("form[action='/requests/#{cancelled_request.id}/start']")
227+
expect(cancel_button).to be_nil
228+
expect(fulfill_button).to be_nil
229+
230+
print_link = page.at_css("a[href='/requests/#{cancelled_request.id}/print_picklist']")
231+
expect(print_link).to be_present
232+
end
233+
end
193234
end
194235

195236
describe 'POST #start' do

spec/system/request_system_spec.rb

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,6 @@
7575
expect(rows.join).not_to have_text('Cancelled')
7676
expect(headers).to have_text(item2.name, count: 1)
7777
end
78-
79-
it "exports the requests CSV including cancelled requests when 'Include Cancelled' is checked" do
80-
_cancelled_request = create(:request, :with_item_requests, :cancelled, partner: partner1, request_items: [{ "item_id": item1.id, "quantity": '6' }])
81-
82-
visit subject
83-
check "Include Cancelled?"
84-
click_on 'Filter'
85-
86-
click_on "Export Requests"
87-
88-
wait_for_download
89-
expect(downloads.length).to eq(1)
90-
expect(download).to match(/.*\.csv/)
91-
92-
headers, *rows = download_content.split("\n")
93-
94-
expect(rows.size).to eq(6)
95-
expect(rows.join).to have_text(partner1.name, count: 5)
96-
expect(rows.join).to have_text('Cancelled')
97-
expect(headers).to have_text(item2.name, count: 1)
98-
end
9978
end
10079

10180
context "when filtering on the index page" do
@@ -160,28 +139,6 @@
160139
expect(rows.join).to have_text('13', count: 1)
161140
expect(rows.join).to have_text(partner1.name, count: 1)
162141
end
163-
164-
it "exports only the cancelled requests CSV when 'Include Cancelled' is checked and 'Filter by Status' is 'Cancelled'" do
165-
_cancelled_request = create(:request, :with_item_requests, :cancelled, partner: partner1, request_items: [{ "item_id": item1.id, "quantity": '6' }])
166-
167-
visit subject
168-
check "Include Cancelled?"
169-
select "Cancelled", from: "Filter by status"
170-
click_on 'Filter'
171-
172-
click_on "Export Requests"
173-
174-
wait_for_download
175-
expect(downloads.length).to eq(1)
176-
expect(download).to match(/.*\.csv/)
177-
178-
headers, *rows = download_content.split("\n")
179-
180-
expect(rows.size).to eq(1)
181-
expect(rows.join).to have_text(partner1.name, count: 1)
182-
expect(rows.join).to have_text('Cancelled')
183-
expect(headers).to have_text(item1.name, count: 1)
184-
end
185142
end
186143
end
187144

@@ -278,19 +235,6 @@
278235
expect(page).to have_content("334")
279236
end
280237

281-
context 'when the request has a cancelled status' do
282-
it 'does not display the Cancel and Fulfill request buttons' do
283-
cancelled_request = create(:request, :with_item_requests, :cancelled, organization: organization)
284-
285-
visit request_path(cancelled_request.id)
286-
287-
expect(page).to have_content('Cancelled')
288-
expect(page).not_to have_button('Cancel')
289-
expect(page).not_to have_button('Fulfill request')
290-
expect(page).to have_content('Print')
291-
end
292-
end
293-
294238
context "change status request" do
295239
before do
296240
visit subject

0 commit comments

Comments
 (0)