Skip to content

Commit 9321c72

Browse files
committed
5446 add system test
1 parent ac46edd commit 9321c72

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

spec/system/audit_system_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,45 @@
195195
expect(page).to have_content("Delete Audit")
196196
expect(page).to have_content("Finalize Audit")
197197
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
198237
end
199238

200239
context "with an existing audit" do

0 commit comments

Comments
 (0)