Skip to content

Commit eea0530

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 eea0530

2 files changed

Lines changed: 45 additions & 91 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 & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@
3030
create(:request, :with_item_requests, :pending, partner: partner1, request_items: [{ "item_id": item1.id, "quantity": '16' }])
3131
end
3232

33-
it "excludes cancelled requests by default" do
34-
visit subject
35-
36-
expect(find_field("include_cancelled")).not_to be_checked
37-
38-
expect(page).to have_xpath("//h1", text: "Requests")
39-
expect(page.find("table")).to have_content('Started', count: 3)
40-
expect(page.find("table")).to have_content('Fulfilled', count: 1)
41-
expect(page.find("table")).to have_content('Pending', count: 1)
42-
end
43-
4433
context "when 'Include Cancelled?' is checked" do
4534
it 'does not display the Cancel button for cancelled requests' do
4635
_cancelled_request = create(:request, :with_item_requests, :cancelled, partner: partner1, request_items: [{ "item_id": item1.id, "quantity": '6' }])
@@ -57,47 +46,6 @@
5746
end
5847
end
5948

60-
context "exporting requests" do
61-
it "exports the requests CSV excluding cancelled requests by default" do
62-
_cancelled_request = create(:request, :with_item_requests, :cancelled, partner: partner1, request_items: [{ "item_id": item1.id, "quantity": '6' }])
63-
64-
visit subject
65-
click_on "Export Requests"
66-
67-
wait_for_download
68-
expect(downloads.length).to eq(1)
69-
expect(download).to match(/.*\.csv/)
70-
71-
headers, *rows = download_content.split("\n")
72-
73-
expect(rows.size).to eq(5)
74-
expect(rows.join).to have_text(partner1.name, count: 4)
75-
expect(rows.join).not_to have_text('Cancelled')
76-
expect(headers).to have_text(item2.name, count: 1)
77-
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
99-
end
100-
10149
context "when filtering on the index page" do
10250
context "with filters cleared" do
10351
it "displays all requests" do
@@ -160,28 +108,6 @@
160108
expect(rows.join).to have_text('13', count: 1)
161109
expect(rows.join).to have_text(partner1.name, count: 1)
162110
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
185111
end
186112
end
187113

@@ -278,19 +204,6 @@
278204
expect(page).to have_content("334")
279205
end
280206

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-
294207
context "change status request" do
295208
before do
296209
visit subject

0 commit comments

Comments
 (0)