|
184 | 184 | context "when viewing an existing storage location" do |
185 | 185 | let(:items) { create_list(:item, 2) } |
186 | 186 | let!(:storage_location) { create(:storage_location, name: "here") } |
| 187 | + let(:result) do |
| 188 | + [ |
| 189 | + { |
| 190 | + item_id: items[0].id, |
| 191 | + item_name: items[0].name, |
| 192 | + quantity_in: 10, |
| 193 | + quantity_out: 5, |
| 194 | + change: 5, |
| 195 | + total_quantity_in: 16, |
| 196 | + total_quantity_out: 7, |
| 197 | + total_change: 9 |
| 198 | + }, |
| 199 | + { |
| 200 | + item_id: items[1].id, |
| 201 | + item_name: items[1].name, |
| 202 | + quantity_in: 6, |
| 203 | + quantity_out: 2, |
| 204 | + change: 4, |
| 205 | + total_quantity_in: 16, |
| 206 | + total_quantity_out: 7, |
| 207 | + total_change: 9 |
| 208 | + } |
| 209 | + ].map(&:with_indifferent_access) |
| 210 | + end |
187 | 211 | subject { storage_location_path(storage_location.id) } |
188 | 212 |
|
189 | 213 | context "Inventory Flow Tab" do |
|
200 | 224 |
|
201 | 225 | it "shows the inventory flow for the storage location" do |
202 | 226 | within("#custom-tabs-inventory-flow table tbody") do |
203 | | - items.each do |item| |
204 | | - row = find(:css, "tr[id='#{item.id}']") |
205 | | - change_column_css = item.quantity_change(storage_location).negative? ? "td.modal-body-warning-text" : "td" |
206 | | - expect(row).to have_link(item.name, href: item_path(item.id)) |
207 | | - expect(row).to have_css("td", text: item.quantity_in_storage(storage_location.id)) |
208 | | - expect(row).to have_css("td", text: item.quantity_out_storage(storage_location.id)) |
209 | | - expect(row).to have_css(change_column_css, text: item.quantity_change(storage_location.id)) |
| 227 | + result.each do |item| |
| 228 | + row = find(:css, "tr[id='#{item[:item_id]}']") |
| 229 | + change_column_css = item[:change].negative? ? "td.modal-body-warning-text" : "td" |
| 230 | + expect(row).to have_link(item[:name], href: item_path(item[:item_id])) |
| 231 | + expect(row).to have_css("td", text: item[:quantity_in]) |
| 232 | + expect(row).to have_css("td", text: item[:quantity_out]) |
| 233 | + expect(row).to have_css(change_column_css, text: item[:change]) |
210 | 234 | end |
211 | 235 | end |
212 | 236 | within("#custom-tabs-inventory-flow table tfoot") do |
213 | 237 | expect(page).to have_css("td", text: "Total") |
214 | | - expect(page).to have_css("td", text: items.sum { |item| item.quantity_in_storage(storage_location.id) }) |
215 | | - expect(page).to have_css("td", text: items.sum { |item| item.quantity_out_storage(storage_location.id) }) |
216 | | - expect(page).to have_css("td", text: items.sum { |item| item.quantity_change(storage_location.id) }) |
| 238 | + expect(page).to have_css("td", text: result.first[:total_quantity_in]) |
| 239 | + expect(page).to have_css("td", text: result.first[:total_quantity_out]) |
| 240 | + expect(page).to have_css("td", text: result.first[:total_change]) |
217 | 241 | end |
218 | 242 | end |
219 | 243 |
|
220 | 244 | context "date range filter" do |
221 | 245 | let!(:start_date) { 2.days.ago } |
222 | 246 | let!(:end_date) { 1.day.ago } |
223 | 247 | let!(:item) { create(:item, name: "Filtered Item", created_at: start_date) } |
| 248 | + let(:result) do |
| 249 | + [ |
| 250 | + { |
| 251 | + item_id: item.id, |
| 252 | + item_name: item.name, |
| 253 | + quantity_in: 10, |
| 254 | + quantity_out: 0, |
| 255 | + change: 10, |
| 256 | + total_quantity_in: 10, |
| 257 | + total_quantity_out: 0, |
| 258 | + total_change: 10 |
| 259 | + } |
| 260 | + ].map(&:with_indifferent_access) |
| 261 | + end |
224 | 262 | before do |
225 | 263 | create(:donation, :with_items, item: item, item_quantity: 10, storage_location: storage_location) |
226 | 264 | fill_in "filters[date_range]", with: "#{start_date} - #{end_date}" |
|
231 | 269 | it "filters the inventory flow by date range" do |
232 | 270 | within("#custom-tabs-inventory-flow table tbody") do |
233 | 271 | expect(page).to have_css("tr", count: 1) |
234 | | - row = find(:css, "tr[id='#{item.id}']") |
235 | | - expect(row).to have_link(item.name, href: item_path(item.id)) |
236 | | - expect(row).to have_css("td", text: item.quantity_in_storage(storage_location.id)) |
237 | | - expect(row).to have_css("td", text: item.quantity_out_storage(storage_location.id)) |
238 | | - expect(row).to have_css("td", text: item.quantity_change(storage_location.id)) |
| 272 | + row = find(:css, "tr[id='#{result.first[:item_id]}']") |
| 273 | + expect(row).to have_link(result.first[:name], href: item_path(result.first[:item_id])) |
| 274 | + expect(row).to have_css("td", text: result.first[:quantity_in]) |
| 275 | + expect(row).to have_css("td", text: result.first[:quantity_out]) |
| 276 | + expect(row).to have_css("td", text: result.first[:change]) |
239 | 277 | end |
240 | 278 | end |
241 | 279 | end |
|
0 commit comments