Skip to content

Commit abfe8fa

Browse files
committed
bug-4976 updates rendering for contact-name & business name when creating a drive participant 'on-the-fly'
1 parent d15baae commit abfe8fa

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

app/views/product_drive_participants/create.js.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
$("#modal_new").modal("hide");
33
$("#donation_product_drive_participant_id").empty();
44
$("#donation_product_drive_participant_id").
5-
html('<%= j options_from_collection_for_select(current_organization.product_drive_participants, :id, :business_name) %>');
5+
html('<%= j options_from_collection_for_select(current_organization.product_drive_participants, :id, lambda { |p| p.business_name.present? ? p.business_name : p.contact_name }) %>');
66
$("#donation_product_drive_participant_id").append('<option value="">---Create new Participant---</option>');
77
$("#donation_product_drive_participant_id").val('<%= @product_drive_participant[:id] %>');

spec/system/donation_system_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,30 @@
280280
fill_in "product_drive_participant_email", with: "123@mail.ru"
281281
fill_in "product_drive_participant_comment", with: "test comment"
282282
click_on "product-drive-participant-submit"
283+
expect(page).to have_select('donation_product_drive_participant_id', with_options: ['businesstest'])
284+
283285
select "businesstest", from: "donation_product_drive_participant_id"
284286
end
285287

288+
#seems like a duplicate check but this update happens via JS, so we have to test that code works too
289+
it "Renders ProductDrive Participants sources by business name then contact name after creating a participant" do
290+
select Donation::SOURCES[:product_drive], from: "donation_source"
291+
select "---Create new Participant---", from: "donation_product_drive_participant_id"
292+
293+
find(".modal-content")
294+
expect(page).to have_content("New Product Drive Participant")
295+
296+
fill_in "product_drive_participant_business_name", with: ""
297+
fill_in "product_drive_participant_contact_name", with: "2nd contact without business name"
298+
fill_in "product_drive_participant_email", with: "1233@mail.ru"
299+
fill_in "product_drive_participant_comment", with: "test comment"
300+
click_on "product-drive-participant-submit"
301+
302+
select ProductDrive.first.name, from: "donation_product_drive_id"
303+
#note that I'm not explicitly testing the business name here, this is handled in the previous test
304+
expect(page).to have_select('donation_product_drive_participant_id', with_options: ['2nd contact without business name'])
305+
end
306+
286307
it "Allows User to create a donation for a Manufacturer source" do
287308
select Donation::SOURCES[:manufacturer], from: "donation_source"
288309
expect(page).to have_xpath("//select[@id='donation_manufacturer_id']")

0 commit comments

Comments
 (0)