Skip to content

Commit

Permalink
4780: Fix item lookup issues on new kit page (#4781)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
coalest authored Nov 22, 2024
1 parent 1025cf5 commit f0b9f80
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/views/audits/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
<div class="row links">
<div class="col-xs-12 p-3">
<%= add_element_button "Add Another Item", container_selector: "#audit_line_items" do %>
<%= add_element_button "Add Another Item", container_selector: "#audit_line_items", id: "__add_line_item" do %>
<%= render 'line_items/line_item_fields', form: f, object: LineItem.new %>
<% end %>
</div>
Expand Down
8 changes: 3 additions & 5 deletions app/views/kits/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
<%= render 'line_items/line_item_fields', form: f %>
</div>
<div class="row links col-xs-12 justify-content-end">
<div class="col-xs-12">
<%= add_element_button "Add Another Item", container_selector: "#kit_line_items" do %>
<%= render 'line_items/line_item_fields', form: f, object: LineItem.new %>
<% end %>
</div>
<%= add_element_button "Add Another Item", container_selector: "#kit_line_items", id: "__add_line_item" do %>
<%= render 'line_items/line_item_fields', form: f, object: LineItem.new %>
<% end %>
</div>
</fieldset>

Expand Down
1 change: 1 addition & 0 deletions app/views/kits/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
</section>

<%= render 'form' %>
<%= render partial: "barcode_items/barcode_modal" %>
52 changes: 52 additions & 0 deletions spec/system/audit_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,58 @@

find('option', text: item.name.to_s)
end

context "when adding new items" do
let!(:existing_barcode) { create(:barcode_item) }
let(:item_with_barcode) { existing_barcode.item }

it "allows user to add items by barcode" do
visit new_audit_path

within "#audit_line_items" do
# Scan existing barcode
expect(page).to have_xpath("//input[@id='_barcode-lookup-0']")
Barcode.boop(existing_barcode.value)

# Ensure item quantity and name have been filled in
expect(page).to have_field "_barcode-lookup-0", with: existing_barcode.value
expect(page).to have_field "audit_line_items_attributes_0_quantity", with: existing_barcode.quantity.to_s
expect(page).to have_field "audit_line_items_attributes_0_item_id", with: existing_barcode.item.id.to_s
end
end

it "allows user to add items that do not yet have a barcode", :js do
item_without_barcode = create(:item)
new_barcode = "00000000"
new_item_name = item_without_barcode.name

visit new_audit_path

# Scan new barcode
within "#audit_line_items" do
expect(page).to have_xpath("//input[@id='_barcode-lookup-0']")
Barcode.boop(new_barcode)
end

# Item lookup finds no barcode and responds by prompting user to choose an item and quantity
within "#newBarcode" do
fill_in "Quantity", with: 10
select new_item_name, from: "Item"
expect(page).to have_field("barcode_item_quantity", with: '10')
expect(page).to have_field("barcode_item_value", with: new_barcode)
click_on "Save"
end

within "#audit_line_items" do
# Ensure item fields have been filled in
expect(page).to have_field "audit_line_items_attributes_0_quantity", with: '10'
expect(page).to have_field "audit_line_items_attributes_0_item_id", with: item_without_barcode.id.to_s

# Ensure new line item was added and has focus
expect(page).to have_field("_barcode-lookup-1", focused: true)
end
end
end
end

context "when viewing the audits index" do
Expand Down
3 changes: 3 additions & 0 deletions spec/system/donation_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@
qty = page.find(:xpath, '//input[@id="donation_line_items_attributes_0_quantity"]').value

expect(qty).to eq(@existing_barcode.quantity.to_s)

# the form should add another empty line
expect(page).to have_field("_barcode-lookup-1", focused: true)
end

it "Updates the line item when the same barcode is scanned twice", :js do
Expand Down
26 changes: 26 additions & 0 deletions spec/system/kit_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@
expect(page).to have_content("#{quantity_per_kit} #{item.name}")
end

it "can add items correctly" do
visit new_kit_path
new_barcode = "1234567890"
quantity = "1"

find(:id, "_barcode-lookup-0").set(new_barcode).send_keys(:enter)

within "#newBarcode" do
expect(page).to have_field("Quantity", with: "")
fill_in "Quantity", with: quantity

expect(page).to have_field("Item", with: "")
select(Item.last.name, from: "barcode_item[barcodeable_id]")
end

within ".modal-footer" do
click_button "Save"
end

expect(page).to have_content("Barcode Added to Inventory")
# Check that item details have been filled in via javascript
expect(page).to have_field("kit_line_items_attributes_0_quantity", with: quantity)
# Check that new field has been added via javascript
expect(page).to have_css(".line_item_section", count: 2)
end

it 'can allocate and deallocate quantity per storage location from kit index' do
visit kits_path

Expand Down

0 comments on commit f0b9f80

Please sign in to comment.