|
11 | 11 | response |
12 | 12 | end |
13 | 13 |
|
14 | | - before do |
15 | | - create(:request) |
16 | | - end |
17 | | - |
18 | 14 | context "html" do |
19 | 15 | let(:response_format) { 'html' } |
20 | 16 |
|
|
25 | 21 | let(:response_format) { 'csv' } |
26 | 22 |
|
27 | 23 | 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 |
28 | 51 | end |
29 | 52 |
|
30 | 53 | 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 |
34 | 55 | create(:request, :pending) |
35 | 56 | create(:request, :started) |
36 | 57 | create(:request, :fulfilled) |
|
44 | 65 | end |
45 | 66 |
|
46 | 67 | 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"} |
49 | 73 |
|
| 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 |
50 | 84 | create(:request, :pending) |
51 | 85 | create(:request, :started) |
52 | 86 | create(:request, :cancelled) |
|
60 | 94 |
|
61 | 95 | context "when 'Include Cancelled?' is checked and filter by Cancelled" do |
62 | 96 | it "constrains the list for cancelled requests only" do |
63 | | - Request.delete_all |
64 | | - |
65 | 97 | create(:request, :started, comments: "Need more supplies") |
66 | 98 | create(:request, :pending, comments: "Awaiting for confirmation") |
67 | 99 | create(:request, :cancelled, comments: 'Not necessary anymore') |
|
76 | 108 |
|
77 | 109 | context "when there is a filter applied" do |
78 | 110 | it "shows only filtered requests, print unfulfilled picklists button with correct quantity" do |
79 | | - Request.delete_all |
80 | | - |
81 | 111 | create(:request, :started, comments: "Started request - should appear") |
82 | 112 | create(:request, :pending, comments: "Pending request - should not appear") |
83 | 113 | create(:request, :cancelled, comments: 'Cancelled request - a comment') |
|
190 | 220 | expect(response.body).not_to include('Units (if applicable)') |
191 | 221 | end |
192 | 222 | 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 |
193 | 241 | end |
194 | 242 |
|
195 | 243 | describe 'POST #start' do |
|
0 commit comments