Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4789] add step-wise editing for banks view of partner profile #4799

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
class ProfilesController < ApplicationController
def edit
@partner = current_organization.partners.find(params[:id])

@counties = County.in_category_name_order
@client_share_total = @partner.profile.client_share_total

if Flipper.enabled?("partner_step_form")
@sections_with_errors = []
render "profiles/step/edit"
else
render "edit"
end
end

def update
@counties = County.in_category_name_order
@partner = current_organization.partners.find(params[:id])
result = PartnerProfileUpdateService.new(@partner, edit_partner_params, edit_profile_params).call
if result.success?
redirect_to partner_path(@partner) + "#partner-information", notice: "#{@partner.name} updated!"
flash[:success] = "Details were successfully updated."
if Flipper.enabled?("partner_step_form")
if params[:save_review]
redirect_to partner_path(@partner) + "#partner-information"
else
redirect_to edit_profile_path
end
else
redirect_to partner_path(@partner) + "#partner-information"
end
else
flash[:error] = "Something didn't work quite right -- try again? %s " % result.error
render action: :edit
flash.now[:error] = "There is a problem. Try again: %s " % result.error
if Flipper.enabled?("partner_step_form")
error_keys = @partner.profile.errors.attribute_names
@sections_with_errors = Partners::SectionErrorService.sections_with_errors(error_keys)
render "profiles/step/edit"
else
render :edit
end
end
end

Expand Down
36 changes: 36 additions & 0 deletions app/views/profiles/step/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-12">
<% content_for :title, "Editing - #{@partner.name}" %>
<h1><i class="fa fa-edit"></i>&nbsp;&nbsp;Editing Partner - <%= @partner.name %>
</h1>
</div>
</div>
</div>
</section>

<div class="alert alert-info mx-5 mt-3" role="alert">
Instructions: Please fill out the following form sections carefully. Ensure that all required fields are completed.
</div>

<div data-controller="accordion">
<%= simple_form_for @partner,
url: profile_path,
data: { controller: "form-input", accordion_target: "form" },
html: {role: 'form', class: 'form-horizontal'} do |f| %>

<%= render 'partners/profiles/step/form_actions', f: f, partner: @partner %>

<div class="accordion mx-5 mt-3" id="accordionExample">
<%= 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 %>
<%= 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 %>
<% @partner.partials_to_show.each do |partial| %>
<%= 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 %>
<% end %>
<%= 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 %>
</div>

<%= render 'partners/profiles/step/form_actions', f: f, partner: @partner %>
<% end %>
</div>
100 changes: 100 additions & 0 deletions spec/system/partner_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,106 @@
end
end

describe "#edit_profile" do
let!(:partner) { create(:partner, name: "Frank") }
subject { edit_profile_path(partner.id) }

context "when step-wise editing is enabled" do
before do
Flipper.enable(:partner_step_form)
visit subject
end

it "displays all sections in a closed state by default" do
within ".accordion" do
expect(page).to have_css("#agency_information.accordion-collapse.collapse", visible: false)
expect(page).to have_css("#program_delivery_address.accordion-collapse.collapse", visible: false)

partner.partials_to_show.each do |partial|
expect(page).to have_css("##{partial}.accordion-collapse.collapse", visible: false)
end
end
end

it "allows sections to be opened, closed, filled in any order, and reviewed" do
# Media
find("button[data-bs-target='#media_information']").click
expect(page).to have_css("#media_information.accordion-collapse.collapse.show", visible: true)
within "#media_information" do
fill_in "Website", with: "https://www.example.com"
end
find("button[data-bs-target='#media_information']").click
expect(page).to have_css("#media_information.accordion-collapse.collapse", visible: false)

# Executive director
find("button[data-bs-target='#executive_director']").click
expect(page).to have_css("#executive_director.accordion-collapse.collapse.show", visible: true)
within "#executive_director" do
fill_in "Executive Director Name", with: "Lisa Smith"
end

# Save Progress
all("input[type='submit'][value='Save Progress']").last.click
expect(page).to have_css(".alert-success", text: "Details were successfully updated.")

# Save and Review
all("input[type='submit'][value='Save and Review']").last.click
expect(current_path).to eq(partner_path(partner.id))
expect(page).to have_css(".alert-success", text: "Details were successfully updated.")
end

it "displays the edit view with sections containing validation errors expanded" do
# Open up Media section and clear out website value
find("button[data-bs-target='#media_information']").click
within "#media_information" do
fill_in "Website", with: ""
end

# Open Pick up person section and fill in 4 email addresses
find("button[data-bs-target='#pick_up_person']").click
within "#pick_up_person" do
fill_in "Pick Up Person's Email", with: "[email protected], [email protected], [email protected], [email protected]"
end

# Open Partner Settings section and uncheck all options
find("button[data-bs-target='#partner_settings']").click
within "#partner_settings" do
uncheck "Enable Quantity-based Requests" if has_checked_field?("Enable Quantity-based Requests")
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)")
uncheck "Enable Requests for Individuals" if has_checked_field?("Enable Requests for Individuals")
end

# Save Progress
all("input[type='submit'][value='Save Progress']").last.click

# Expect an alert-danger message containing validation errors
expect(page).to have_css(".alert-danger", text: /There is a problem/)
expect(page).to have_content("No social media presence must be checked if you have not provided any of Website, Twitter, Facebook, or Instagram.")
expect(page).to have_content("Enable child based requests At least one request type must be set")
expect(page).to have_content("Pick up email can't have more than three email addresses")

# Expect media section, executive director section, and partner settings section to be opened
expect(page).to have_css("#media_information.accordion-collapse.collapse.show", visible: true)
expect(page).to have_css("#pick_up_person.accordion-collapse.collapse.show", visible: true)
expect(page).to have_css("#partner_settings.accordion-collapse.collapse.show", visible: true)

# Try to Submit and Review from error state
all("input[type='submit'][value='Save and Review']").last.click

# Expect an alert-danger message containing validation errors
expect(page).to have_css(".alert-danger", text: /There is a problem/)
expect(page).to have_content("No social media presence must be checked if you have not provided any of Website, Twitter, Facebook, or Instagram.")
expect(page).to have_content("Enable child based requests At least one request type must be set")
expect(page).to have_content("Pick up email can't have more than three email addresses")

# Expect media section, executive director section, and partner settings section to be opened
expect(page).to have_css("#media_information.accordion-collapse.collapse.show", visible: true)
expect(page).to have_css("#pick_up_person.accordion-collapse.collapse.show", visible: true)
expect(page).to have_css("#partner_settings.accordion-collapse.collapse.show", visible: true)
end
end
end

describe "#approve_partner" do
let(:tooltip_message) do
"Partner has not requested approval yet. Partners are able to request approval by going into 'My Organization' and clicking 'Request Approval' button."
Expand Down