Skip to content

Commit

Permalink
FIX bug where you can't add additional line items when creating kit
Browse files Browse the repository at this point in the history
* Add testing adding multiple line items to kit system rspec
  • Loading branch information
jimmyli97 committed Aug 30, 2024
1 parent 49ac15c commit 80dd89c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 3 additions & 1 deletion app/views/kits/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
<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 %>
<%= f.simple_fields_for @kit.item do |i| %>
<%= render 'line_items/line_item_fields', form: i, object: LineItem.new %>
<% end %>
<% end %>
</div>
</div>
Expand Down
23 changes: 15 additions & 8 deletions spec/system/kit_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
kit_creation_service.kit
end

let!(:existing_kit_item_1) { create(:item) }
let!(:existing_kit_item_1) { create(:item, name: existing_kit_item_name_1) }
let!(:existing_kit_item_1_quantity) { 5 }
let!(:existing_kit_item_2) { create(:item) }
let!(:existing_kit_item_name_1) { "TEST ITEM 1" }
let!(:existing_kit_item_2) { create(:item, name: existing_kit_item_name_2) }
let!(:existing_kit_item_2_quantity) { 3 }
let!(:existing_kit_item_name_2) { "TEST ITEM 2" }
before(:each) do
TestInventory.create_inventory(organization, {
storage_location.id => {
Expand All @@ -35,21 +37,26 @@

it "can create a new kit as a user with the proper quantity" do
visit new_kit_path
kit_traits = attributes_for(:kit)
kit_name = "TEST KIT"

fill_in "Name", with: kit_traits[:name]
fill_in "Name", with: kit_name
find(:css, '#kit_value_in_dollars').set('10.10')

item = Item.last
quantity_per_kit = 5
select item.name, from: "kit_item_line_items_attributes_0_item_id"
select existing_kit_item_name_1, from: "kit_item_line_items_attributes_0_item_id"
find(:css, '#kit_item_line_items_attributes_0_quantity').set(quantity_per_kit)

find(:xpath, "//a[text()=' Add Another Item']").click

find(:xpath, "(//select[contains(@id, 'kit_item_line_items_attributes')])[2]").find(:option, existing_kit_item_name_2).select_option
find(:xpath, "(//input[contains(@id, 'kit_item_line_items_attributes')])[2]").set(quantity_per_kit)

click_button "Save"

expect(page.find(".alert")).to have_content "Kit created successfully"
expect(page).to have_content(kit_traits[:name])
expect(page).to have_content("#{quantity_per_kit} #{item.name}")
expect(page).to have_content(kit_name)
expect(page).to have_content("#{quantity_per_kit} #{existing_kit_item_name_1}")
expect(page).to have_content("#{quantity_per_kit} #{existing_kit_item_name_2}")
end

it 'can allocate and deallocate quantity per storage location from kit index' do
Expand Down

0 comments on commit 80dd89c

Please sign in to comment.