Skip to content

Commit 5f607b2

Browse files
committed
5446 improve comments, use bootstrap modal to hide modal, specify id of audit to isolate audit more robustly in spec
1 parent f417ae7 commit 5f607b2

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

app/javascript/controllers/audit_duplicates_controller.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,18 @@ export default class extends Controller {
106106
duplicates.forEach(item => {
107107
const total = item.entries.reduce((sum, entry) => sum + entry.quantity, 0)
108108

109-
// Keep the first entry, remove the rest
109+
// Separate the first entry from remaining entries
110110
const [firstEntry, ...remainingEntries] = item.entries
111111

112112
// Update the first entry with the merged total
113113
firstEntry.section.querySelector('input[name*="[quantity]"]').value = total
114114

115-
// Remove all duplicate entries
115+
// Remove all duplicate entries from the form submission
116116
remainingEntries.forEach(entry => entry.section.remove())
117117
})
118118

119-
document.getElementById('duplicateItemsModal')?.remove()
120-
document.querySelector('.modal-backdrop')?.remove()
121-
document.body.classList.remove('modal-open')
122-
document.body.style.removeProperty('overflow')
119+
const modal = new bootstrap.Modal(document.getElementById('duplicateItemsModal'))
120+
modal.hide()
123121

124122
this.submitForm(buttonName)
125123
}

spec/system/audit_system_spec.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,18 @@
231231
expect(page).to have_content("Make Changes")
232232

233233
# Test merge functionality
234-
click_button "Merge Items"
235-
236-
# Should merge duplicates and submit successfully
237-
expect(page).to have_content("Audit's progress was successfully saved.")
234+
audit_id = nil
235+
expect {
236+
click_button "Merge Items"
237+
expect(page).to have_content("Audit's progress was successfully saved.")
238+
audit_id = Audit.maximum(:id)
239+
}.to change { Audit.count }.by(1)
238240

239241
# Verify only one line item with merged quantity (10 + 15 = 25)
240-
expect(Audit.last.line_items.count).to eq(1)
241-
expect(Audit.last.line_items.first.quantity).to eq(25)
242+
created_audit = Audit.find(audit_id)
243+
line_item = created_audit.line_items.find_by(item_id: item.id)
244+
expect(created_audit.line_items.count).to eq(1)
245+
expect(line_item.quantity).to eq(25)
242246
end
243247
end
244248

0 commit comments

Comments
 (0)