Skip to content

Commit

Permalink
Create actions component instead of view partial
Browse files Browse the repository at this point in the history
  • Loading branch information
Kizr committed Feb 11, 2025
1 parent 4943df7 commit ec43e45
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 11 deletions.
28 changes: 28 additions & 0 deletions app/components/claims/support/claim/actions_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Claims::Support::Claim::ActionsComponent < ApplicationComponent
def initialize(claim:, classes: [], html_attributes: {})
super(classes:, html_attributes:)

@claim = claim
end

def call
tag.div(class: "claim-actions") do
render_actions
end
end

private

attr_reader :claim

def render_actions
case claim.status
when *Claims::Claim::PAYMENT_ACTIONABLE_STATUSES
render "claims/support/claims/payments/claims/actions", claim:
when *Claims::Claim::SAMPLING_STATUSES
render "claims/support/claims/samplings/actions", claim:
when *Claims::Claim::CLAWBACK_STATUSES
render "claims/support/claims/clawbacks/actions", claim:
end
end
end
10 changes: 0 additions & 10 deletions app/views/claims/support/claims/_actions.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/claims/support/claims/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<p class="govuk-caption-l"><%= t(".page_caption", reference: @claim.reference) %></p>
<h1 class="govuk-heading-l"><%= @claim.school_name %> <%= render Claim::StatusTagComponent.new(claim: @claim) %></h1>

<%= render "actions", claim: @claim %>
<%= render Claims::Support::Claim::ActionsComponent.new(claim: @claim) %>

<% if @claim.submitted_by_id? %>
<p class="govuk-body"><%= t(".submitted_by", name: @claim.submitted_by.full_name, date: l(@claim.submitted_on, format: :long)) %></p>
Expand Down
130 changes: 130 additions & 0 deletions spec/components/claims/support/claim/actions_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
require "rails_helper"

RSpec.describe Claims::Support::Claim::ActionsComponent, type: :component do
before { render_inline(described_class.new(claim:)) }

context "when claim status is submitted" do
let(:claim) { create(:claim, :submitted) }

it "does not render actions" do
expect(page).not_to have_element(:div, class: ".claim-actions")
end
end

context "when claim status is paid" do
let(:claim) { create(:claim, :paid) }

it "does not renders actions" do
expect(page).not_to have_element(:div, class: ".claim-actions")
end
end

context "when claim status is payment information requested" do
let(:claim) { create(:claim, :payment_information_requested, unpaid_reason: "Reason") }

it "renders actions" do
expect(page).to have_element(:h2, text: "Reason claim was not paid")
expect(page).to have_element(:p, text: "Reason")

expect(page).to have_element(:a, text: "Confirm information sent", class: "govuk-button")
expect(page).to have_link("Confirm information sent", href: "/support/claims/payments/claims/#{claim.id}/information-sent")

expect(page).to have_element(:a, text: "Reject claim", class: "govuk-button")
expect(page).to have_link("Reject claim", href: "/support/claims/payments/claims/#{claim.id}/reject")
end
end

context "when claim status is payment information sent" do
let(:claim) { create(:claim, :payment_information_sent, unpaid_reason: "Reason") }

it "renders actions" do
expect(page).to have_element(:h2, text: "Reason claim was not paid")
expect(page).to have_element(:p, text: "Reason")

expect(page).to have_element(:a, text: "Confirm claim paid", class: "govuk-button")
expect(page).to have_link("Confirm claim paid", href: "/support/claims/payments/claims/#{claim.id}/paid")

expect(page).to have_element(:a, text: "Reject claim", class: "govuk-button")
expect(page).to have_link("Reject claim", href: "/support/claims/payments/claims/#{claim.id}/reject")
end
end

context "when claim status is payment not approved" do
let(:claim) { create(:claim, :payment_not_approved) }

it "does not renders actions" do
expect(page).not_to have_element(:div, class: ".claim-actions")
end
end

context "when claim status is sampling in progress" do
let(:claim) { create(:claim, :audit_requested, sampling_reason: "Reason") }

it "renders actions" do
expect(page).to have_element(:div, class: "claim-actions")

expect(page).to have_element(:h3, text: "Reason claim is being audited")
expect(page).to have_element(:p, text: "Reason")

expect(page).to have_element(:a, text: "Approve claim", class: "govuk-button")
expect(page).to have_link("Approve claim", href: "/support/claims/sampling/claims/#{claim.id}/confirm_approval")

expect(page).to have_element(:a, text: "Confirm provider rejected claim")
expect(page).to have_link("Confirm provider rejected claim", href: "/support/claims/sampling/claims/#{claim.id}/provider_rejected/new")
end
end

context "when claim status is sampling provider not approved" do
let(:claim) { create(:claim, :sampling_provider_not_approved, mentor_trainings: [mentor_training]) }
let(:mentor) { build(:claims_mentor, first_name: "John", last_name: "Doe") }
let(:mentor_training) { build(:mentor_training, mentor:, not_assured: true, reason_not_assured: "Incorrect number of hours") }

it "renders actions" do
expect(page).to have_element(:div, class: "claim-actions")

expect(page).to have_element(:h3, text: "Provider response", class: "govuk-heading-s")
expect(page).to have_element(:li, text: "John Doe: Incorrect number of hours")

expect(page).to have_element(:a, text: "Approve claim", class: "govuk-button")
expect(page).to have_link("Approve claim", href: "/support/claims/sampling/claims/#{claim.id}/confirm_approval")

expect(page).to have_element(:a, text: "Reject claim", class: "govuk-button")
expect(page).to have_link("Reject claim", href: "/support/claims/sampling/claims/#{claim.id}/reject/new")
end
end

context "when claim status is sampling not approved" do
let(:claim) { create(:claim, :sampling_not_approved) }

it "renders actions" do
expect(page).to have_element(:div, class: "claim-actions")

expect(page).to have_element(:a, text: "Request clawback", class: "govuk-button")
expect(page).to have_link("Request clawback", href: "/support/claims/clawbacks/claims/new/#{claim.id}")
end
end

context "when claim status is clawback requested" do
let(:claim) { create(:claim, :clawback_requested) }

it "does not renders actions" do
expect(page).not_to have_element(:div, class: ".claim-actions")
end
end

context "when claim status is clawback in progress" do
let(:claim) { create(:claim, :clawback_in_progress) }

it "does not renders actions" do
expect(page).not_to have_element(:div, class: ".claim-actions")
end
end

context "when claim status is clawback complete" do
let(:claim) { create(:claim, :clawback_complete) }

it "does not renders actions" do
expect(page).not_to have_element(:div, class: ".claim-actions")
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Claims::Support::Claim::ActionsComponentPreview < ApplicationComponentPreview
def default
claim = FactoryBot.build(:claim, :submitted, school:)
render Claims::Support::Claim::ActionsComponent.new(claim:)
end

def with_payment_information_requested_claim
claim = FactoryBot.build(:claim, :payment_information_requested, school:)
render Claims::Support::Claim::ActionsComponent.new(claim:)
end

def with_payment_information_sent_claim
claim = FactoryBot.build(:claim, :payment_information_sent, school:)
render Claims::Support::Claim::ActionsComponent.new(claim:)
end

def with_sampling_in_progress_claim
claim = FactoryBot.build(:claim, :sampling_in_progress, school:)
render Claims::Support::Claim::ActionsComponent.new(claim:)
end

def with_sampling_provider_not_approved_claim
claim = FactoryBot.build(:claim, :sampling_provider_not_approved, school:)
render Claims::Support::Claim::ActionsComponent.new(claim:)
end

def with_sampling_not_approved_claim
claim = FactoryBot.build(:claim, :sampling_not_approved, school:)
render Claims::Support::Claim::ActionsComponent.new(claim:)
end
end
5 changes: 5 additions & 0 deletions spec/factories/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@
status { :payment_information_sent }
end

trait :payment_not_approved do
status { :payment_not_approved }
end

trait :audit_requested do
status { :sampling_in_progress }
sampling_reason { "Small claim" }
end
end
end

0 comments on commit ec43e45

Please sign in to comment.