Skip to content

Commit 0ac32ee

Browse files
danielabarSukhpreet-s
authored andcommitted
[rubyforgood#4789] add step-wise editing for banks view of partner profile (rubyforgood#4799)
1 parent 41a60e8 commit 0ac32ee

File tree

3 files changed

+161
-4
lines changed

3 files changed

+161
-4
lines changed

app/controllers/profiles_controller.rb

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
class ProfilesController < ApplicationController
22
def edit
33
@partner = current_organization.partners.find(params[:id])
4-
54
@counties = County.in_category_name_order
65
@client_share_total = @partner.profile.client_share_total
6+
7+
if Flipper.enabled?("partner_step_form")
8+
@sections_with_errors = []
9+
render "profiles/step/edit"
10+
else
11+
render "edit"
12+
end
713
end
814

915
def update
1016
@counties = County.in_category_name_order
1117
@partner = current_organization.partners.find(params[:id])
1218
result = PartnerProfileUpdateService.new(@partner, edit_partner_params, edit_profile_params).call
1319
if result.success?
14-
redirect_to partner_path(@partner) + "#partner-information", notice: "#{@partner.name} updated!"
20+
flash[:success] = "Details were successfully updated."
21+
if Flipper.enabled?("partner_step_form")
22+
if params[:save_review]
23+
redirect_to partner_path(@partner) + "#partner-information"
24+
else
25+
redirect_to edit_profile_path
26+
end
27+
else
28+
redirect_to partner_path(@partner) + "#partner-information"
29+
end
1530
else
16-
flash[:error] = "Something didn't work quite right -- try again? %s " % result.error
17-
render action: :edit
31+
flash.now[:error] = "There is a problem. Try again: %s " % result.error
32+
if Flipper.enabled?("partner_step_form")
33+
error_keys = @partner.profile.errors.attribute_names
34+
@sections_with_errors = Partners::SectionErrorService.sections_with_errors(error_keys)
35+
render "profiles/step/edit"
36+
else
37+
render :edit
38+
end
1839
end
1940
end
2041

app/views/profiles/step/edit.html.erb

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<section class="content-header">
2+
<div class="container-fluid">
3+
<div class="row mb-2">
4+
<div class="col-sm-12">
5+
<% content_for :title, "Editing - #{@partner.name}" %>
6+
<h1><i class="fa fa-edit"></i>&nbsp;&nbsp;Editing Partner - <%= @partner.name %>
7+
</h1>
8+
</div>
9+
</div>
10+
</div>
11+
</section>
12+
13+
<div class="alert alert-info mx-5 mt-3" role="alert">
14+
Instructions: Please fill out the following form sections carefully. Ensure that all required fields are completed.
15+
</div>
16+
17+
<div data-controller="accordion">
18+
<%= simple_form_for @partner,
19+
url: profile_path,
20+
data: { controller: "form-input", accordion_target: "form" },
21+
html: {role: 'form', class: 'form-horizontal'} do |f| %>
22+
23+
<%= render 'partners/profiles/step/form_actions', f: f, partner: @partner %>
24+
25+
<div class="accordion mx-5 mt-3" id="accordionExample">
26+
<%= render 'partners/profiles/step/accordion_section', f: f, partner: @partner, section_id: 'agency_information', section_title: 'Agency Information', icon_class: 'fa-edit', partial_name: 'agency_information', sections_with_errors: @sections_with_errors %>
27+
<%= render 'partners/profiles/step/accordion_section', f: f, partner: @partner, section_id: 'program_delivery_address', section_title: 'Program / Delivery Address', icon_class: 'fa-map', partial_name: 'program_delivery_address', sections_with_errors: @sections_with_errors %>
28+
<% @partner.partials_to_show.each do |partial| %>
29+
<%= render 'partners/profiles/step/accordion_section', f: f, partner: @partner, section_id: partial, section_title: partial_display_name(partial), icon_class: 'fa-cogs', partial_name: partial, sections_with_errors: @sections_with_errors %>
30+
<% end %>
31+
<%= render 'partners/profiles/step/accordion_section', f: f, partner: @partner, section_id: 'partner_settings', section_title: 'Settings', icon_class: 'fa-cog', partial_name: 'partner_settings', sections_with_errors: @sections_with_errors %>
32+
</div>
33+
34+
<%= render 'partners/profiles/step/form_actions', f: f, partner: @partner %>
35+
<% end %>
36+
</div>

spec/system/partner_system_spec.rb

+100
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,106 @@
380380
end
381381
end
382382

383+
describe "#edit_profile" do
384+
let!(:partner) { create(:partner, name: "Frank") }
385+
subject { edit_profile_path(partner.id) }
386+
387+
context "when step-wise editing is enabled" do
388+
before do
389+
Flipper.enable(:partner_step_form)
390+
visit subject
391+
end
392+
393+
it "displays all sections in a closed state by default" do
394+
within ".accordion" do
395+
expect(page).to have_css("#agency_information.accordion-collapse.collapse", visible: false)
396+
expect(page).to have_css("#program_delivery_address.accordion-collapse.collapse", visible: false)
397+
398+
partner.partials_to_show.each do |partial|
399+
expect(page).to have_css("##{partial}.accordion-collapse.collapse", visible: false)
400+
end
401+
end
402+
end
403+
404+
it "allows sections to be opened, closed, filled in any order, and reviewed" do
405+
# Media
406+
find("button[data-bs-target='#media_information']").click
407+
expect(page).to have_css("#media_information.accordion-collapse.collapse.show", visible: true)
408+
within "#media_information" do
409+
fill_in "Website", with: "https://www.example.com"
410+
end
411+
find("button[data-bs-target='#media_information']").click
412+
expect(page).to have_css("#media_information.accordion-collapse.collapse", visible: false)
413+
414+
# Executive director
415+
find("button[data-bs-target='#executive_director']").click
416+
expect(page).to have_css("#executive_director.accordion-collapse.collapse.show", visible: true)
417+
within "#executive_director" do
418+
fill_in "Executive Director Name", with: "Lisa Smith"
419+
end
420+
421+
# Save Progress
422+
all("input[type='submit'][value='Save Progress']").last.click
423+
expect(page).to have_css(".alert-success", text: "Details were successfully updated.")
424+
425+
# Save and Review
426+
all("input[type='submit'][value='Save and Review']").last.click
427+
expect(current_path).to eq(partner_path(partner.id))
428+
expect(page).to have_css(".alert-success", text: "Details were successfully updated.")
429+
end
430+
431+
it "displays the edit view with sections containing validation errors expanded" do
432+
# Open up Media section and clear out website value
433+
find("button[data-bs-target='#media_information']").click
434+
within "#media_information" do
435+
fill_in "Website", with: ""
436+
end
437+
438+
# Open Pick up person section and fill in 4 email addresses
439+
find("button[data-bs-target='#pick_up_person']").click
440+
within "#pick_up_person" do
441+
fill_in "Pick Up Person's Email", with: "[email protected], [email protected], [email protected], [email protected]"
442+
end
443+
444+
# Open Partner Settings section and uncheck all options
445+
find("button[data-bs-target='#partner_settings']").click
446+
within "#partner_settings" do
447+
uncheck "Enable Quantity-based Requests" if has_checked_field?("Enable Quantity-based Requests")
448+
uncheck "Enable Child-based Requests (unclick if you only do bulk requests)" if has_checked_field?("Enable Child-based Requests (unclick if you only do bulk requests)")
449+
uncheck "Enable Requests for Individuals" if has_checked_field?("Enable Requests for Individuals")
450+
end
451+
452+
# Save Progress
453+
all("input[type='submit'][value='Save Progress']").last.click
454+
455+
# Expect an alert-danger message containing validation errors
456+
expect(page).to have_css(".alert-danger", text: /There is a problem/)
457+
expect(page).to have_content("No social media presence must be checked if you have not provided any of Website, Twitter, Facebook, or Instagram.")
458+
expect(page).to have_content("Enable child based requests At least one request type must be set")
459+
expect(page).to have_content("Pick up email can't have more than three email addresses")
460+
461+
# Expect media section, executive director section, and partner settings section to be opened
462+
expect(page).to have_css("#media_information.accordion-collapse.collapse.show", visible: true)
463+
expect(page).to have_css("#pick_up_person.accordion-collapse.collapse.show", visible: true)
464+
expect(page).to have_css("#partner_settings.accordion-collapse.collapse.show", visible: true)
465+
466+
# Try to Submit and Review from error state
467+
all("input[type='submit'][value='Save and Review']").last.click
468+
469+
# Expect an alert-danger message containing validation errors
470+
expect(page).to have_css(".alert-danger", text: /There is a problem/)
471+
expect(page).to have_content("No social media presence must be checked if you have not provided any of Website, Twitter, Facebook, or Instagram.")
472+
expect(page).to have_content("Enable child based requests At least one request type must be set")
473+
expect(page).to have_content("Pick up email can't have more than three email addresses")
474+
475+
# Expect media section, executive director section, and partner settings section to be opened
476+
expect(page).to have_css("#media_information.accordion-collapse.collapse.show", visible: true)
477+
expect(page).to have_css("#pick_up_person.accordion-collapse.collapse.show", visible: true)
478+
expect(page).to have_css("#partner_settings.accordion-collapse.collapse.show", visible: true)
479+
end
480+
end
481+
end
482+
383483
describe "#approve_partner" do
384484
let(:tooltip_message) do
385485
"Partner has not requested approval yet. Partners are able to request approval by going into 'My Organization' and clicking 'Request Approval' button."

0 commit comments

Comments
 (0)