From 704ad63527dda16444b6d24409fcb29629b532d7 Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Fri, 12 Jul 2024 16:42:57 -0400 Subject: [PATCH 01/10] #4398: Support units in requests --- .../partners/requests_controller.rb | 6 ++- .../controllers/item_units_controller.js | 40 +++++++++++++++++++ .../partners/request_create_service.rb | 1 + .../partners/requests/_item_request.html.erb | 16 +++++++- app/views/partners/requests/new.html.erb | 7 +++- ..._backfill_partner_child_requested_items.rb | 2 + 6 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 app/javascript/controllers/item_units_controller.js diff --git a/app/controllers/partners/requests_controller.rb b/app/controllers/partners/requests_controller.rb index eec3c8cf4a..014f48fbd7 100644 --- a/app/controllers/partners/requests_controller.rb +++ b/app/controllers/partners/requests_controller.rb @@ -12,6 +12,10 @@ def new @partner_request.item_requests.build @requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.id).call + # hash of (item ID => hash of (request unit name => request unit plural name)) + @item_units = current_partner.organization.items.to_h do |i| + [i.id, i.request_units.to_h { |u| [u.name, u.name.pluralize] }] + end end def show @@ -44,7 +48,7 @@ def create private def partner_request_params - params.require(:request).permit(:comments, item_requests_attributes: [:item_id, :quantity]) + params.require(:request).permit(:comments, item_requests_attributes: [:item_id, :quantity, :request_unit]) end end end diff --git a/app/javascript/controllers/item_units_controller.js b/app/javascript/controllers/item_units_controller.js new file mode 100644 index 0000000000..d964f364b0 --- /dev/null +++ b/app/javascript/controllers/item_units_controller.js @@ -0,0 +1,40 @@ +import { Controller } from "@hotwired/stimulus"; + +// Connects to data-controller="form-input" +export default class extends Controller { + static targets = ["itemSelect", "requestSelect"] + static values = { + // hash of (item ID => hash of (request unit name => request unit plural name)) + "itemUnits": Object + } + + addOption(val, text, selected) { + let option = document.createElement("option"); + option.value = val; + option.text = text; + if (selected) { + option.selected = true; + } + this.requestSelectTarget.appendChild(option); + } + + clearOptions() { + while (this.requestSelectTarget.options.length > 0) { + this.requestSelectTarget.remove(this.requestSelectTarget.options[0]) + } + } + + itemSelected() { + if (!this.hasRequestSelectTarget) { + return; + } + let option = this.itemSelectTarget.options[this.itemSelectTarget.selectedIndex] + let units = this.itemUnitsValue[option.value] + this.clearOptions() + this.addOption('', 'Units') + for (const [index, [name, displayName]] of Object.entries(Object.entries(units))) { + this.addOption(name, displayName, index === "0") + } + } + +} diff --git a/app/services/partners/request_create_service.rb b/app/services/partners/request_create_service.rb index 8df880ebbf..df1b5ecf6c 100644 --- a/app/services/partners/request_create_service.rb +++ b/app/services/partners/request_create_service.rb @@ -71,6 +71,7 @@ def populate_item_request(partner_request) else items[input_item['item_id']] = Partners::ItemRequest.new( item_id: input_item['item_id'], + request_unit: input_item['request_unit'], quantity: input_item['quantity'], children: input_item['children'] || [], # will create ChildItemRequests if there are any name: fetch_organization_item_name(input_item['item_id']), diff --git a/app/views/partners/requests/_item_request.html.erb b/app/views/partners/requests/_item_request.html.erb index bcb6bdcc17..595f0851e5 100644 --- a/app/views/partners/requests/_item_request.html.erb +++ b/app/views/partners/requests/_item_request.html.erb @@ -1,13 +1,25 @@ <%= form.fields_for :item_requests, defined?(object) ? object : nil do |field| %> - + <%= field.label :item_id, "Item Requested", {class: 'sr-only'} %> - <%= field.select :item_id, @requestable_items, {include_blank: 'Select an item'}, {class: 'form-control'} %> + <%= field.select :item_id, @requestable_items, {include_blank: 'Select an item'}, + data: { :'item-units-target' => 'itemSelect', + action: 'change->item-units#itemSelected', + class: 'form-control' } %> <%= field.label :quantity, "Quantity", {class: 'sr-only'} %> <%= field.number_field :quantity, label: false, step: 1, min: 1, class: 'form-control' %> + + <% if current_partner.organization.request_units.any? %> + + <%= field.label :request_unit, "Unit", {class: 'sr-only'} %> + <%= field.select :request_unit, [], {include_blank: 'Units'}, + { :'data-item-units-target' => 'requestSelect', class: 'form-control'} %> + + + <% end %> <%= remove_element_button "Remove", container_selector: "tr" %> diff --git a/app/views/partners/requests/new.html.erb b/app/views/partners/requests/new.html.erb index c25ee9e3d2..c973b6df6f 100644 --- a/app/views/partners/requests/new.html.erb +++ b/app/views/partners/requests/new.html.erb @@ -39,15 +39,18 @@ Item Requested Quantity + <% if current_partner.organization.request_units.any? %> + Units (if applicable) + <% end %> - <%= render 'item_request', form: form %> + <%= render partial: 'item_request', locals: { form: form, item_units: @item_units } %>
<%= add_element_button('Add Another Item', container_selector: '.fields') do %> - <%= render 'item_request', form: form, object: @partner_request.item_requests.build %> + <%= render partial: 'item_request', locals: { form: form, item_units: @item_units }, object: @partner_request.item_requests.build %> <% end %>
diff --git a/db/migrate/20240704214509_backfill_partner_child_requested_items.rb b/db/migrate/20240704214509_backfill_partner_child_requested_items.rb index 9e4cdba70d..dc6443933e 100644 --- a/db/migrate/20240704214509_backfill_partner_child_requested_items.rb +++ b/db/migrate/20240704214509_backfill_partner_child_requested_items.rb @@ -1,5 +1,7 @@ class BackfillPartnerChildRequestedItems < ActiveRecord::Migration[7.1] def change + return unless Rails.env.production? + Partners::Child.unscoped.where.not(item_needed_diaperid: nil).each do |child| child.requested_items << Item.find_by(id: child.item_needed_diaperid) end From ab8315c13616b0e1251fa94c5e22b7729ca65207 Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Fri, 12 Jul 2024 16:44:34 -0400 Subject: [PATCH 02/10] fix style --- app/views/partners/requests/_item_request.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/partners/requests/_item_request.html.erb b/app/views/partners/requests/_item_request.html.erb index 595f0851e5..aa4576d5f0 100644 --- a/app/views/partners/requests/_item_request.html.erb +++ b/app/views/partners/requests/_item_request.html.erb @@ -4,8 +4,8 @@ <%= field.label :item_id, "Item Requested", {class: 'sr-only'} %> <%= field.select :item_id, @requestable_items, {include_blank: 'Select an item'}, data: { :'item-units-target' => 'itemSelect', - action: 'change->item-units#itemSelected', - class: 'form-control' } %> + action: 'change->item-units#itemSelected'}, + class: 'form-control' %> <%= field.label :quantity, "Quantity", {class: 'sr-only'} %> From 895c9806d988ec4234aad0a5184c3bcb24a9e964 Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Fri, 12 Jul 2024 16:50:25 -0400 Subject: [PATCH 03/10] fixes --- .../controllers/item_units_controller.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/javascript/controllers/item_units_controller.js b/app/javascript/controllers/item_units_controller.js index d964f364b0..3a063f4caf 100644 --- a/app/javascript/controllers/item_units_controller.js +++ b/app/javascript/controllers/item_units_controller.js @@ -24,16 +24,26 @@ export default class extends Controller { } } + connect() { + this.itemSelected(); + } + itemSelected() { if (!this.hasRequestSelectTarget) { return; } let option = this.itemSelectTarget.options[this.itemSelectTarget.selectedIndex] let units = this.itemUnitsValue[option.value] - this.clearOptions() - this.addOption('', 'Units') - for (const [index, [name, displayName]] of Object.entries(Object.entries(units))) { - this.addOption(name, displayName, index === "0") + if (!units || Object.keys(units).length === 0) { + this.requestSelectTarget.style.display = 'none'; + } + else { + this.requestSelectTarget.style.display = 'inline'; + this.clearOptions() + this.addOption('', 'Units') + for (const [index, [name, displayName]] of Object.entries(Object.entries(units))) { + this.addOption(name, displayName, index === "0") + } } } From 9b929c45f8899b09eb64ba16e13e8e516029e0cf Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Fri, 19 Jul 2024 16:57:25 -0400 Subject: [PATCH 04/10] Add specs --- spec/requests/partners/requests_spec.rb | 3 + spec/system/partners/requests_system_spec.rb | 66 ++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 spec/system/partners/requests_system_spec.rb diff --git a/spec/requests/partners/requests_spec.rb b/spec/requests/partners/requests_spec.rb index ca4b2995ff..ddd6423810 100644 --- a/spec/requests/partners/requests_spec.rb +++ b/spec/requests/partners/requests_spec.rb @@ -100,6 +100,7 @@ item_requests_attributes: { "0" => { item_id: item1.id, + request_unit: 'pack', quantity: Faker::Number.within(range: 4..13) } } @@ -109,6 +110,8 @@ before do sign_in(partner_user) + FactoryBot.create(:unit, organization: organization, name: 'pack') + FactoryBot.create(:item_unit, item: item1, name: 'pack') end context 'when given valid parameters' do diff --git a/spec/system/partners/requests_system_spec.rb b/spec/system/partners/requests_system_spec.rb new file mode 100644 index 0000000000..fc3ace9f19 --- /dev/null +++ b/spec/system/partners/requests_system_spec.rb @@ -0,0 +1,66 @@ +RSpec.describe "Partners profile served area behaviour", type: :system, js: true do + let(:organization) { create(:organization) } + let(:partner) { create(:partner, organization: organization) } + let(:partner_user) { partner.primary_user } + + before(:each) do + sign_in(partner_user) + end + + describe "GET #index" do + let!(:item1) { FactoryBot.create(:item, organization: organization, name: "Item 1") } + let!(:item2) { FactoryBot.create(:item, organization: organization, name: "Item 2") } + before(:each) do + FactoryBot.create(:item_unit, name: "pack", item: item1) + end + + context "with packs off" do + before(:each) do + Flipper.disable(:enable_packs) + end + + it "should not show packs on selection" do + visit new_partners_request_path + select "Item 1", from: "request_item_requests_attributes_0_item_id" + expect(page).not_to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) + end + end + + context "with packs on" do + before(:each) do + Flipper.enable(:enable_packs) + end + + it "should show packs on selection" do + visit new_partners_request_path + expect(Request.count).to eq(0) + expect(page).not_to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) + select "Item 1", from: "request_item_requests_attributes_0_item_id" + expect(page).to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) + expect(page).to have_select("request_item_requests_attributes_0_request_unit", selected: "packs", options: ["Units", "packs"]) + select "packs", from: "request_item_requests_attributes_0_request_unit" + click_on "Add Another Item" + + # get selector to use in subsequent steps + new_item = find_all(:css, "select[data-item-units-target=itemSelect]")[1] + id = new_item[:id].match(/\d+/)[0] + + expect(page).not_to have_selector("request_item_requests_attributes_#{id}_request_unit", visible: true) + select "Item 2", from: "request_item_requests_attributes_#{id}_item_id" + expect(page).not_to have_selector("request_item_requests_attributes_#{id}_request_unit", visible: true) + fill_in "request_item_requests_attributes_0_quantity", with: 50 + fill_in "request_item_requests_attributes_#{id}_quantity", with: 20 + click_on "Submit Essentials Request" + + expect(Request.count).to eq(1) + request = Request.last + expect(request.item_requests[0].quantity).to eq("50") + expect(request.item_requests[0].item_id).to eq(item1.id) + expect(request.item_requests[0].request_unit).to eq("pack") + expect(request.item_requests[1].quantity).to eq("20") + expect(request.item_requests[1].item_id).to eq(item2.id) + expect(request.item_requests[1].request_unit).to eq("") + end + end + end +end From 3529e4c505bb9be9df00edb9e7ace7b04a62516b Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Fri, 26 Jul 2024 15:45:15 -0400 Subject: [PATCH 05/10] Fix error case --- app/controllers/partners/requests_controller.rb | 6 ++++++ app/javascript/controllers/item_units_controller.js | 1 + 2 files changed, 7 insertions(+) diff --git a/app/controllers/partners/requests_controller.rb b/app/controllers/partners/requests_controller.rb index bce7c84102..66c185422c 100644 --- a/app/controllers/partners/requests_controller.rb +++ b/app/controllers/partners/requests_controller.rb @@ -40,6 +40,12 @@ def create @errors = create_service.errors @requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.id).call + if Flipper.enabled?(:enable_packs) + # hash of (item ID => hash of (request unit name => request unit plural name)) + @item_units = current_partner.organization.items.to_h do |i| + [i.id, i.request_units.to_h { |u| [u.name, u.name.pluralize] }] + end + end Rails.logger.info("[Request Creation Failure] partner_user_id=#{current_user.id} reason=#{@errors.full_messages}") diff --git a/app/javascript/controllers/item_units_controller.js b/app/javascript/controllers/item_units_controller.js index 3a063f4caf..07b6334a0e 100644 --- a/app/javascript/controllers/item_units_controller.js +++ b/app/javascript/controllers/item_units_controller.js @@ -36,6 +36,7 @@ export default class extends Controller { let units = this.itemUnitsValue[option.value] if (!units || Object.keys(units).length === 0) { this.requestSelectTarget.style.display = 'none'; + this.requestSelectTarget.selectedIndex = -1; } else { this.requestSelectTarget.style.display = 'inline'; From e043ede3547aabf047aa2e751e79c3819cf08922 Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Fri, 2 Aug 2024 09:57:34 -0400 Subject: [PATCH 06/10] Fix test --- spec/system/partners/requests_system_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/partners/requests_system_spec.rb b/spec/system/partners/requests_system_spec.rb index fc3ace9f19..cc6c608ad4 100644 --- a/spec/system/partners/requests_system_spec.rb +++ b/spec/system/partners/requests_system_spec.rb @@ -59,7 +59,7 @@ expect(request.item_requests[0].request_unit).to eq("pack") expect(request.item_requests[1].quantity).to eq("20") expect(request.item_requests[1].item_id).to eq(item2.id) - expect(request.item_requests[1].request_unit).to eq("") + expect(request.item_requests[1].request_unit).to eq(nil) end end end From 0a74e07a2f715db269da43b1a7d58ec07b95a30b Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Sun, 11 Aug 2024 10:04:21 -0400 Subject: [PATCH 07/10] CR changes --- .../partners/requests_controller.rb | 27 +++++++++---------- .../controllers/item_units_controller.js | 7 ++--- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/app/controllers/partners/requests_controller.rb b/app/controllers/partners/requests_controller.rb index 66c185422c..983e4049dc 100644 --- a/app/controllers/partners/requests_controller.rb +++ b/app/controllers/partners/requests_controller.rb @@ -11,13 +11,7 @@ def new @partner_request = ::Request.new @partner_request.item_requests.build - @requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.id).call - if Flipper.enabled?(:enable_packs) - # hash of (item ID => hash of (request unit name => request unit plural name)) - @item_units = current_partner.organization.items.to_h do |i| - [i.id, i.request_units.to_h { |u| [u.name, u.name.pluralize] }] - end - end + fetch_items end def show @@ -39,13 +33,7 @@ def create @partner_request = create_service.partner_request @errors = create_service.errors - @requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.id).call - if Flipper.enabled?(:enable_packs) - # hash of (item ID => hash of (request unit name => request unit plural name)) - @item_units = current_partner.organization.items.to_h do |i| - [i.id, i.request_units.to_h { |u| [u.name, u.name.pluralize] }] - end - end + fetch_items Rails.logger.info("[Request Creation Failure] partner_user_id=#{current_user.id} reason=#{@errors.full_messages}") @@ -58,5 +46,16 @@ def create def partner_request_params params.require(:request).permit(:comments, item_requests_attributes: [:item_id, :quantity, :request_unit]) end + + def fetch_items + @requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.id).call + if Flipper.enabled?(:enable_packs) + # hash of (item ID => hash of (request unit name => request unit plural name)) + @item_units = Item.where(id: @requestable_items.to_h.values).to_h do |i| + [i.id, i.request_units.to_h { |u| [u.name, u.name.pluralize] }] + end + end + end + end end diff --git a/app/javascript/controllers/item_units_controller.js b/app/javascript/controllers/item_units_controller.js index 07b6334a0e..36418febdb 100644 --- a/app/javascript/controllers/item_units_controller.js +++ b/app/javascript/controllers/item_units_controller.js @@ -8,13 +8,10 @@ export default class extends Controller { "itemUnits": Object } - addOption(val, text, selected) { + addOption(val, text) { let option = document.createElement("option"); option.value = val; option.text = text; - if (selected) { - option.selected = true; - } this.requestSelectTarget.appendChild(option); } @@ -43,7 +40,7 @@ export default class extends Controller { this.clearOptions() this.addOption('', 'Units') for (const [index, [name, displayName]] of Object.entries(Object.entries(units))) { - this.addOption(name, displayName, index === "0") + this.addOption(name, displayName) } } } From 270c28f0cdf2da4bb062ffe25244a6e1dafd3e9b Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Sun, 11 Aug 2024 10:11:15 -0400 Subject: [PATCH 08/10] Fix tests --- app/controllers/partners/requests_controller.rb | 1 - spec/system/partners/requests_system_spec.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/partners/requests_controller.rb b/app/controllers/partners/requests_controller.rb index 983e4049dc..6d5ebdfd29 100644 --- a/app/controllers/partners/requests_controller.rb +++ b/app/controllers/partners/requests_controller.rb @@ -56,6 +56,5 @@ def fetch_items end end end - end end diff --git a/spec/system/partners/requests_system_spec.rb b/spec/system/partners/requests_system_spec.rb index cc6c608ad4..1c500463b8 100644 --- a/spec/system/partners/requests_system_spec.rb +++ b/spec/system/partners/requests_system_spec.rb @@ -37,7 +37,7 @@ expect(page).not_to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) select "Item 1", from: "request_item_requests_attributes_0_item_id" expect(page).to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) - expect(page).to have_select("request_item_requests_attributes_0_request_unit", selected: "packs", options: ["Units", "packs"]) + expect(page).to have_select("request_item_requests_attributes_0_request_unit", selected: "Units", options: ["Units", "packs"]) select "packs", from: "request_item_requests_attributes_0_request_unit" click_on "Add Another Item" From 9ce328ed16259a4e75a85236853d90c7f730d096 Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Sun, 11 Aug 2024 10:33:28 -0400 Subject: [PATCH 09/10] Update based on feedback --- .../controllers/item_units_controller.js | 1 + .../partners/request_create_service.rb | 4 ++++ app/views/partners/requests/_error.html.erb | 3 +++ spec/system/partners/requests_system_spec.rb | 19 ++++++++++++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/javascript/controllers/item_units_controller.js b/app/javascript/controllers/item_units_controller.js index 36418febdb..c647c9e876 100644 --- a/app/javascript/controllers/item_units_controller.js +++ b/app/javascript/controllers/item_units_controller.js @@ -38,6 +38,7 @@ export default class extends Controller { else { this.requestSelectTarget.style.display = 'inline'; this.clearOptions() + this.addOption('-1', 'Please select a unit') this.addOption('', 'Units') for (const [index, [name, displayName]] of Object.entries(Object.entries(units))) { this.addOption(name, displayName) diff --git a/app/services/partners/request_create_service.rb b/app/services/partners/request_create_service.rb index df1b5ecf6c..732f4c2a31 100644 --- a/app/services/partners/request_create_service.rb +++ b/app/services/partners/request_create_service.rb @@ -69,6 +69,10 @@ def populate_item_request(partner_request) # object (either this one or the FamilyRequestCreateService). pre_existing_entry.children = (pre_existing_entry.children + (input_item['children'] || [])).uniq else + if input_item['request_unit'].to_s == '-1' # nothing selected + errors.add(:base, "Please select a unit for #{Item.find(input_item["item_id"]).name}") + next + end items[input_item['item_id']] = Partners::ItemRequest.new( item_id: input_item['item_id'], request_unit: input_item['request_unit'], diff --git a/app/views/partners/requests/_error.html.erb b/app/views/partners/requests/_error.html.erb index b9d46c399c..ecdb3fe320 100644 --- a/app/views/partners/requests/_error.html.erb +++ b/app/views/partners/requests/_error.html.erb @@ -8,6 +8,9 @@

Oops! Something went wrong with your Request

Ensure each line item has a item selected AND a quantity greater than 0. + <% if Flipper.enabled?(:enable_packs) && current_partner.organization.request_units.any? %> + Please ensure a unit is selected for each item that supports it. + <% end %>

Still need help? Please contact your essentials bank, <%= current_partner.organization.name %>, if you need further assistance.
diff --git a/spec/system/partners/requests_system_spec.rb b/spec/system/partners/requests_system_spec.rb index 1c500463b8..8343db0b29 100644 --- a/spec/system/partners/requests_system_spec.rb +++ b/spec/system/partners/requests_system_spec.rb @@ -31,13 +31,30 @@ Flipper.enable(:enable_packs) end + it "should require a unit selection" do + visit new_partners_request_path + expect(Request.count).to eq(0) + expect(page).not_to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) + select "Item 1", from: "request_item_requests_attributes_0_item_id" + expect(page).to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) + expect(page).to have_select("request_item_requests_attributes_0_request_unit", + selected: "Please select a unit", + options: ["Please select a unit", "Units", "packs"]) + fill_in "request_item_requests_attributes_0_quantity", with: 50 + click_on "Submit Essentials Request" + expect(Request.count).to eq(0) + expect(page).to have_text "Please ensure a unit is selected for each item that supports it." + end + it "should show packs on selection" do visit new_partners_request_path expect(Request.count).to eq(0) expect(page).not_to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) select "Item 1", from: "request_item_requests_attributes_0_item_id" expect(page).to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) - expect(page).to have_select("request_item_requests_attributes_0_request_unit", selected: "Units", options: ["Units", "packs"]) + expect(page).to have_select("request_item_requests_attributes_0_request_unit", + selected: "Please select a unit", + options: ["Please select a unit", "Units", "packs"]) select "packs", from: "request_item_requests_attributes_0_request_unit" click_on "Add Another Item" From 579925665c3401b5403fb16fbd697a9adc9de2d6 Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Mon, 19 Aug 2024 08:42:14 -0400 Subject: [PATCH 10/10] Update request verification pop-up and specs [#4398] --- app/views/partners/requests/validate.html.erb | 6 ++++++ spec/system/partners/requests_system_spec.rb | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/views/partners/requests/validate.html.erb b/app/views/partners/requests/validate.html.erb index 1455e3cb8c..37d53adebc 100644 --- a/app/views/partners/requests/validate.html.erb +++ b/app/views/partners/requests/validate.html.erb @@ -11,6 +11,9 @@ Item Name Total Items + <% if Flipper.enabled?(:enable_packs) && @partner_request.item_requests.any?( &:request_unit ) %> + Units + <% end %> @@ -18,6 +21,9 @@ <%= line_item.name %> <%= line_item.quantity %> + <% if Flipper.enabled?(:enable_packs) && @partner_request.item_requests.any?( &:request_unit ) %> + <%= line_item.request_unit %> + <% end %> <% end %> diff --git a/spec/system/partners/requests_system_spec.rb b/spec/system/partners/requests_system_spec.rb index 8343db0b29..0c4bc9ebf2 100644 --- a/spec/system/partners/requests_system_spec.rb +++ b/spec/system/partners/requests_system_spec.rb @@ -42,8 +42,9 @@ options: ["Please select a unit", "Units", "packs"]) fill_in "request_item_requests_attributes_0_quantity", with: 50 click_on "Submit Essentials Request" - expect(Request.count).to eq(0) + expect(page).to have_text "Please ensure a unit is selected for each item that supports it." + expect(Request.count).to eq(0) end it "should show packs on selection" do @@ -68,6 +69,8 @@ fill_in "request_item_requests_attributes_0_quantity", with: 50 fill_in "request_item_requests_attributes_#{id}_quantity", with: 20 click_on "Submit Essentials Request" + click_on "Yes, it's correct" + expect(page).to have_text "Request has been successfully created" expect(Request.count).to eq(1) request = Request.last