Skip to content

Commit f0b9f80

Browse files
authored
4780: Fix item lookup issues on new kit page (#4781)
* 4780: Fix item lookup issues on new kit page * Move __add_line_item id back to method argument * Add audit system spec for barcode item lookup * Add id to add element button on donation forms * Refactor kit system specs
1 parent 1025cf5 commit f0b9f80

File tree

6 files changed

+86
-6
lines changed

6 files changed

+86
-6
lines changed

app/views/audits/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</div>
2323
<div class="row links">
2424
<div class="col-xs-12 p-3">
25-
<%= add_element_button "Add Another Item", container_selector: "#audit_line_items" do %>
25+
<%= add_element_button "Add Another Item", container_selector: "#audit_line_items", id: "__add_line_item" do %>
2626
<%= render 'line_items/line_item_fields', form: f, object: LineItem.new %>
2727
<% end %>
2828
</div>

app/views/kits/_form.html.erb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
<%= render 'line_items/line_item_fields', form: f %>
2626
</div>
2727
<div class="row links col-xs-12 justify-content-end">
28-
<div class="col-xs-12">
29-
<%= add_element_button "Add Another Item", container_selector: "#kit_line_items" do %>
30-
<%= render 'line_items/line_item_fields', form: f, object: LineItem.new %>
31-
<% end %>
32-
</div>
28+
<%= add_element_button "Add Another Item", container_selector: "#kit_line_items", id: "__add_line_item" do %>
29+
<%= render 'line_items/line_item_fields', form: f, object: LineItem.new %>
30+
<% end %>
3331
</div>
3432
</fieldset>
3533

app/views/kits/new.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
</section>
2222

2323
<%= render 'form' %>
24+
<%= render partial: "barcode_items/barcode_modal" %>

spec/system/audit_system_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,58 @@
4848

4949
find('option', text: item.name.to_s)
5050
end
51+
52+
context "when adding new items" do
53+
let!(:existing_barcode) { create(:barcode_item) }
54+
let(:item_with_barcode) { existing_barcode.item }
55+
56+
it "allows user to add items by barcode" do
57+
visit new_audit_path
58+
59+
within "#audit_line_items" do
60+
# Scan existing barcode
61+
expect(page).to have_xpath("//input[@id='_barcode-lookup-0']")
62+
Barcode.boop(existing_barcode.value)
63+
64+
# Ensure item quantity and name have been filled in
65+
expect(page).to have_field "_barcode-lookup-0", with: existing_barcode.value
66+
expect(page).to have_field "audit_line_items_attributes_0_quantity", with: existing_barcode.quantity.to_s
67+
expect(page).to have_field "audit_line_items_attributes_0_item_id", with: existing_barcode.item.id.to_s
68+
end
69+
end
70+
71+
it "allows user to add items that do not yet have a barcode", :js do
72+
item_without_barcode = create(:item)
73+
new_barcode = "00000000"
74+
new_item_name = item_without_barcode.name
75+
76+
visit new_audit_path
77+
78+
# Scan new barcode
79+
within "#audit_line_items" do
80+
expect(page).to have_xpath("//input[@id='_barcode-lookup-0']")
81+
Barcode.boop(new_barcode)
82+
end
83+
84+
# Item lookup finds no barcode and responds by prompting user to choose an item and quantity
85+
within "#newBarcode" do
86+
fill_in "Quantity", with: 10
87+
select new_item_name, from: "Item"
88+
expect(page).to have_field("barcode_item_quantity", with: '10')
89+
expect(page).to have_field("barcode_item_value", with: new_barcode)
90+
click_on "Save"
91+
end
92+
93+
within "#audit_line_items" do
94+
# Ensure item fields have been filled in
95+
expect(page).to have_field "audit_line_items_attributes_0_quantity", with: '10'
96+
expect(page).to have_field "audit_line_items_attributes_0_item_id", with: item_without_barcode.id.to_s
97+
98+
# Ensure new line item was added and has focus
99+
expect(page).to have_field("_barcode-lookup-1", focused: true)
100+
end
101+
end
102+
end
51103
end
52104

53105
context "when viewing the audits index" do

spec/system/donation_system_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,9 @@
453453
qty = page.find(:xpath, '//input[@id="donation_line_items_attributes_0_quantity"]').value
454454

455455
expect(qty).to eq(@existing_barcode.quantity.to_s)
456+
457+
# the form should add another empty line
458+
expect(page).to have_field("_barcode-lookup-1", focused: true)
456459
end
457460

458461
it "Updates the line item when the same barcode is scanned twice", :js do

spec/system/kit_system_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,32 @@
5252
expect(page).to have_content("#{quantity_per_kit} #{item.name}")
5353
end
5454

55+
it "can add items correctly" do
56+
visit new_kit_path
57+
new_barcode = "1234567890"
58+
quantity = "1"
59+
60+
find(:id, "_barcode-lookup-0").set(new_barcode).send_keys(:enter)
61+
62+
within "#newBarcode" do
63+
expect(page).to have_field("Quantity", with: "")
64+
fill_in "Quantity", with: quantity
65+
66+
expect(page).to have_field("Item", with: "")
67+
select(Item.last.name, from: "barcode_item[barcodeable_id]")
68+
end
69+
70+
within ".modal-footer" do
71+
click_button "Save"
72+
end
73+
74+
expect(page).to have_content("Barcode Added to Inventory")
75+
# Check that item details have been filled in via javascript
76+
expect(page).to have_field("kit_line_items_attributes_0_quantity", with: quantity)
77+
# Check that new field has been added via javascript
78+
expect(page).to have_css(".line_item_section", count: 2)
79+
end
80+
5581
it 'can allocate and deallocate quantity per storage location from kit index' do
5682
visit kits_path
5783

0 commit comments

Comments
 (0)