|
229 | 229 |
|
230 | 230 | describe "when duplicate items" do |
231 | 231 | it "detects duplicate items and shows modal", js: true do |
232 | | - # Disable server-side validation to test JS modal |
233 | | - #allow_any_instance_of(Audit).to receive(:line_items_unique_by_item_id) |
234 | 232 | visit new_kit_path |
235 | 233 | click_link "New Kit" |
236 | 234 |
|
237 | 235 | kit_traits = attributes_for(:kit) |
238 | 236 | fill_in "Name", with: kit_traits[:name] |
239 | 237 | find(:css, '#kit_value_in_dollars').set('10.10') |
240 | | - |
| 238 | + |
241 | 239 | item = Item.last |
242 | 240 |
|
243 | 241 | # Add first entry for the item |
244 | 242 | select item.name, from: "item_line_items_attributes_0_item_id" |
245 | 243 | fill_in "item_line_items_attributes_0_quantity", with: "10" |
246 | | - |
| 244 | + |
247 | 245 | # Add a new line item row |
248 | 246 | find("[data-form-input-target='addButton']").click |
249 | | - |
| 247 | + |
250 | 248 | # Add second entry for the same item |
251 | 249 | within all('.line_item_section').last do |
252 | 250 | item_select = find('select[name*="[item_id]"]') |
253 | 251 | select item.name, from: item_select[:id] |
254 | 252 | quantity_input = find('input[name*="[quantity]"]') |
255 | 253 | fill_in quantity_input[:id], with: "15" |
256 | 254 | end |
257 | | - |
| 255 | + |
258 | 256 | # Try to save - should trigger duplicate detection modal |
259 | 257 | click_button "Save" |
260 | | - |
| 258 | + |
261 | 259 | # JavaScript modal should appear |
262 | 260 | expect(page).to have_css("#duplicateItemsModal", visible: true) |
263 | 261 | expect(page).to have_content("Multiple Item Entries Detected") |
264 | 262 | expect(page).to have_content("Merge Items") |
265 | 263 | expect(page).to have_content("Make Changes") |
266 | | - |
267 | | - |
| 264 | + |
268 | 265 | # Test merge functionality |
269 | 266 | click_button "Merge Items" |
270 | | - |
| 267 | + |
271 | 268 | expect(page.find(".alert")).to have_content "Kit created successfully" |
272 | 269 | expect(page).to have_content(kit_traits[:name]) |
273 | 270 | expect(page).to have_content("25 #{item.name}") |
|
0 commit comments