Skip to content

Commit 5b31b10

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 5b31b10

2 files changed

Lines changed: 61 additions & 116 deletions

File tree

spec/requests/requests_requests_spec.rb

Lines changed: 61 additions & 13 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,12 +21,37 @@
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
31-
it "shows print unfulfilled picklists button with correct quantity" do
32-
Request.delete_all
33-
54+
it "shows print unfulfilled picklists button with correct quantity, excluding cancelled requests by default" do
3455
create(:request, :pending)
3556
create(:request, :started)
3657
create(:request, :fulfilled)
@@ -44,9 +65,22 @@
4465
end
4566

4667
context "when 'include_cancelled' param is present" do
47-
it "shows print unfulfilled picklists button with correct quantity including cancelled requests" do
48-
Request.delete_all
68+
it 'does not display the Cancel button for cancelled requests' do
69+
pending_request = create(:request, :pending)
70+
cancelled_request = create(:request, :cancelled)
71+
72+
get requests_path, params: {include_cancelled: "1"}
4973

74+
page = Nokogiri::HTML(response.body)
75+
76+
cancelled_request_cancel_button = page.at_css("form[action='/requests/#{cancelled_request.id}/cancelation/new']")
77+
expect(cancelled_request_cancel_button).to be_nil
78+
79+
pending_request_cancel_button = page.at_css("a[href='/requests/#{pending_request.id}/cancelation/new']")
80+
expect(pending_request_cancel_button).to be_present
81+
end
82+
83+
it "shows print unfulfilled picklists button with correct quantity including cancelled requests" do
5084
create(:request, :pending)
5185
create(:request, :started)
5286
create(:request, :cancelled)
@@ -60,8 +94,6 @@
6094

6195
context "when 'Include Cancelled?' is checked and filter by Cancelled" do
6296
it "constrains the list for cancelled requests only" do
63-
Request.delete_all
64-
6597
create(:request, :started, comments: "Need more supplies")
6698
create(:request, :pending, comments: "Awaiting for confirmation")
6799
create(:request, :cancelled, comments: 'Not necessary anymore')
@@ -76,8 +108,6 @@
76108

77109
context "when there is a filter applied" do
78110
it "shows only filtered requests, print unfulfilled picklists button with correct quantity" do
79-
Request.delete_all
80-
81111
create(:request, :started, comments: "Started request - should appear")
82112
create(:request, :pending, comments: "Pending request - should not appear")
83113
create(:request, :cancelled, comments: 'Cancelled request - a comment')
@@ -190,6 +220,24 @@
190220
expect(response.body).not_to include('Units (if applicable)')
191221
end
192222
end
223+
224+
context 'when the request has a cancelled status' do
225+
it 'does not display the Cancel and Fulfill request buttons' do
226+
cancelled_request = create(:request, :cancelled, organization:)
227+
228+
get request_path(cancelled_request)
229+
230+
page = Nokogiri::HTML(response.body)
231+
232+
cancel_button = page.at_css("form[action='/requests/#{cancelled_request.id}/cancelation/new']")
233+
fulfill_button = page.at_css("form[action='/requests/#{cancelled_request.id}/start']")
234+
expect(cancel_button).to be_nil
235+
expect(fulfill_button).to be_nil
236+
237+
print_link = page.at_css("a[href='/requests/#{cancelled_request.id}/print_picklist']")
238+
expect(print_link).to be_present
239+
end
240+
end
193241
end
194242

195243
describe 'POST #start' do

spec/system/request_system_spec.rb

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -30,74 +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-
44-
context "when 'Include Cancelled?' is checked" do
45-
it 'does not display the Cancel button for cancelled requests' do
46-
_cancelled_request = create(:request, :with_item_requests, :cancelled, partner: partner1, request_items: [{ "item_id": item1.id, "quantity": '6' }])
47-
48-
visit subject
49-
50-
check "Include Cancelled?"
51-
click_on 'Filter'
52-
53-
within "table tbody" do
54-
expect(page).to have_content("Cancelled", count: 1)
55-
expect(page).to have_link("Cancel", count: 5) # 5 requests created in the before block
56-
end
57-
end
58-
end
59-
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-
10133
context "when filtering on the index page" do
10234
context "with filters cleared" do
10335
it "displays all requests" do
@@ -160,28 +92,6 @@
16092
expect(rows.join).to have_text('13', count: 1)
16193
expect(rows.join).to have_text(partner1.name, count: 1)
16294
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
18595
end
18696
end
18797

@@ -278,19 +188,6 @@
278188
expect(page).to have_content("334")
279189
end
280190

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-
294191
context "change status request" do
295192
before do
296193
visit subject

0 commit comments

Comments
 (0)