|
195 | 195 | expect(page).to have_content("Delete Audit") |
196 | 196 | expect(page).to have_content("Finalize Audit") |
197 | 197 | end |
| 198 | + |
| 199 | + it "detects duplicate items and allows merging", js: true do |
| 200 | + visit subject |
| 201 | + click_link "New Audit" |
| 202 | + |
| 203 | + await_select2("#audit_line_items_attributes_0_item_id") do |
| 204 | + select storage_location.name, from: "Storage location" |
| 205 | + end |
| 206 | + |
| 207 | + # Add first entry for the item |
| 208 | + select item.name, from: "audit_line_items_attributes_0_item_id" |
| 209 | + fill_in "audit_line_items_attributes_0_quantity", with: "10" |
| 210 | + |
| 211 | + # Add a new line item row |
| 212 | + click_button "Add Another Item" |
| 213 | + |
| 214 | + # Add second entry for the same item |
| 215 | + select item.name, from: "audit_line_items_attributes_1_item_id" |
| 216 | + fill_in "audit_line_items_attributes_1_quantity", with: "15" |
| 217 | + |
| 218 | + # Try to save - should trigger duplicate detection modal |
| 219 | + click_button "Save Progress" |
| 220 | + |
| 221 | + # Verify duplicate detection modal appears |
| 222 | + expect(page).to have_content("Multiple Item Entries Detected") |
| 223 | + expect(page).to have_content(item.name) |
| 224 | + expect(page).to have_content("Merged Result: #{item.name} : 25") |
| 225 | + expect(page).to have_button("Merge Items") |
| 226 | + expect(page).to have_button("Make Changes") |
| 227 | + |
| 228 | + # Click merge to proceed |
| 229 | + click_button "Merge Items" |
| 230 | + |
| 231 | + # Verify audit was saved successfully with merged quantities |
| 232 | + expect(page).to have_content("Audit's progress was successfully saved.") |
| 233 | + expect(Audit.last.line_items.count).to eq(1) |
| 234 | + expect(Audit.last.line_items.first.quantity).to eq(25) |
| 235 | + expect(Audit.last.line_items.first.item).to eq(item) |
| 236 | + end |
198 | 237 | end |
199 | 238 |
|
200 | 239 | context "with an existing audit" do |
|
0 commit comments