Skip to content

Commit

Permalink
Merge pull request #5865 from rubyforgood/5775-improve-discoverabilty…
Browse files Browse the repository at this point in the history
…-for-creating-and-editting-court-report-topics

added additional logic to contact_topic_answers to improve discoverab…
  • Loading branch information
compwron authored Jul 5, 2024
2 parents 53452bd + 3e3182b commit e5d68e7
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 50 deletions.
27 changes: 16 additions & 11 deletions app/views/case_contacts/form/details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,24 @@
</div>
</div>

<div class="card-style-1 pl-25 pr-25 mb-10">
<h4 class="mb-20 details__topics-label">Court Report Topics <span class="content-1">(optional)</span></h4>
<div>
<% if @case_contact.contact_topic_answers.any? %>
<div class="card-style-1 pl-25 mb-10">
<h4 class="mb-20 details__topics-label">Court report <%= "topic".pluralize(@case_contact.contact_topic_answers.count) %> <span class="content-1">(optional)</span></label></h4>
<div class="">
<%= form.fields_for(:contact_topic_answers) do |f| %>
<div class="form-check checkbox-style mb-10 ml-5">
<%= f.check_box :selected, class: ["form-check-input", "casa-case-id"] %>
<%= f.label :selected, f.object.contact_topic.question, class: "form-check-label" %>
</div>
<% end %>
</div>
</div>
<%= form.fields_for(:contact_topic_answers) do |f| %>
<div class="form-check checkbox-style mb-10 ml-5">
<%= f.check_box :selected, class: ["form-check-input", "casa-case-id"] %>
<%= f.label :selected, f.object.contact_topic.question, class: "form-check-label" %>
</div>
<% end %>
<% elsif current_user.casa_admin? %>
Visit <%= link_to "Manage Case Contact Topics", edit_casa_org_path(current_user.casa_org_id) %> to set your organization Court report topics.
<% else %>
Your organization has not set any Court Report Topics yet. Contact your admin to learn more.
<% end %>
</div>
</div>

<div class="actions mb-10 case-contacts-form-buttons">
<%= link_to leave_case_contacts_form_path, class: "btn-sm main-btn #{@case_contact.draft_case_ids.empty? ? 'danger' : 'primary'}-btn-outline btn-hover", data: { controller: "alert", "action": "alert#confirm", "alert-ignore-value": !@case_contact.draft_case_ids.empty?, "alert-title-value": "Discard draft?", "alert-message-value": "Are you sure? If you don't save and continue to the next step, this draft will not be recoverable." } do %>
Back
Expand Down
105 changes: 66 additions & 39 deletions spec/requests/case_contacts/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
let(:creator) { admin }
let!(:casa_case) { create(:casa_case, casa_org: organization) }

before { sign_in admin }

describe "GET /show" do
let!(:case_contact) { create(:case_contact, :details_status, casa_case: casa_case) }
let!(:contact_type_group_b) { create(:contact_type_group, casa_org: organization, name: "B") }
Expand All @@ -27,64 +25,93 @@
create(:contact_type, name: "Parent", contact_type_group: contact_type_group_a)
]
end
subject(:request) do
get case_contact_form_path(:details, case_contact_id: case_contact.id)

context "details step" do
subject(:request) do
get case_contact_form_path(:details, case_contact_id: case_contact.id)
response
end

response
end
describe "admin view" do
before { sign_in admin }

it "shows all contact types once" do
page = request.parsed_body.to_html
expected_contact_types = [].concat(contact_types_a, contact_types_b).map(&:name)
expected_contact_types.each { |contact_type| expect(page.scan(contact_type).size).to eq(1) }
end
context "details step" do
it "shows all contact types once" do
page = request.parsed_body.to_html
expected_contact_types = [].concat(contact_types_a, contact_types_b).map(&:name)
expected_contact_types.each { |contact_type| expect(page.scan(contact_type).size).to eq(1) }
end

context "when the case has specific contact types assigned" do
let!(:casa_case) { create(:casa_case, :with_casa_case_contact_types, casa_org: organization) }
context "when the case has specific contact types assigned" do
let!(:casa_case) { create(:casa_case, :with_casa_case_contact_types, casa_org: organization) }

it "shows only contact types assigned to selected casa case" do
page = request.parsed_body.to_html
expect(page).to include(*casa_case.contact_types.pluck(:name))
expect(page).not_to include(*contact_types_a.pluck(:name))
expect(page).not_to include(*contact_types_b.pluck(:name))
it "shows only contact types assigned to selected casa case" do
page = request.parsed_body.to_html
expect(page).to include(*casa_case.contact_types.pluck(:name))
expect(page).not_to include(*contact_types_a.pluck(:name))
expect(page).not_to include(*contact_types_b.pluck(:name))
end
end
context "when an org has no topics" do
let(:organization) { create(:casa_org) }
let!(:case_contact) { create(:case_contact, :details_status, casa_case: casa_case) }

it "it shows the admin the contact topics link" do
page = request.parsed_body.to_html
expect(page).to include("Manage Case Contact Topics</a> to set your organization Court report topics.")
end
end
context "when the org has topics assigned" do
let(:contact_topics) {
[
build(:contact_topic, active: true, soft_delete: false),
build(:contact_topic, active: false, soft_delete: false),
build(:contact_topic, active: true, soft_delete: true),
build(:contact_topic, active: false, soft_delete: true)
]
}
let(:organization) { create(:casa_org, contact_topics:) }
let!(:case_contact) { create(:case_contact, :details_status, :with_org_topics, casa_case: casa_case) }

it "shows contact topics" do
page = request.parsed_body.to_html
expect(page).to include(contact_topics[0].question)
expect(page).to_not include(contact_topics[1].question)
expect(page).to_not include(contact_topics[2].question)
expect(page).to_not include(contact_topics[3].question)
end
end
end
end
describe "volunteer view" do
before { sign_in volunteer }

context "when an org has no topics" do
context "details step - when an org has no topics" do
let(:organization) { create(:casa_org) }
let!(:case_contact) { create(:case_contact, :details_status, casa_case: casa_case) }
let!(:case_contact) { create(:case_contact, :details_status, casa_case: casa_case, creator: volunteer) }

it "does not show contact topic card" do
it "guides volunteer to contact admin" do
page = request.parsed_body.to_html
expect(page).to_not include("Court report topics")
expect(page).to include("Your organization has not set any Court Report Topics yet. Contact your admin to learn more.")
end
end
context "when the org has topics assigned" do
let(:contact_topics) {
[
build(:contact_topic, active: true, soft_delete: false),
build(:contact_topic, active: false, soft_delete: false),
build(:contact_topic, active: true, soft_delete: true),
build(:contact_topic, active: false, soft_delete: true)
]
}
let(:organization) { create(:casa_org, contact_topics:) }
let!(:case_contact) { create(:case_contact, :details_status, :with_org_topics, casa_case: casa_case) }
end
describe "supervisor view" do
before { sign_in supervisor }

context "details step - when an org has no topics" do
let(:organization) { create(:casa_org) }
let!(:case_contact) { create(:case_contact, :details_status, casa_case:, creator: supervisor) }

it "shows contact topics" do
it "guides supervisor to contact admin" do
page = request.parsed_body.to_html
expect(page).to include(contact_topics[0].question)
expect(page).to_not include(contact_topics[1].question)
expect(page).to_not include(contact_topics[2].question)
expect(page).to_not include(contact_topics[3].question)
expect(page).to include("Your organization has not set any Court Report Topics yet. Contact your admin to learn more.")
end
end
end
end

describe "PATCH /update" do
before { sign_in admin }
let!(:casa_case) { create(:casa_case, casa_org: organization) }
let!(:case_contact) { create(:case_contact, :details_status, casa_case:) }
let(:advance_form) { true }
Expand Down

0 comments on commit e5d68e7

Please sign in to comment.