Skip to content

Commit

Permalink
amelioration(ChorusComponent): ameliore le rendu de la tuile si celle…
Browse files Browse the repository at this point in the history
… ci n'est que partiellement rempli
  • Loading branch information
Martin committed Oct 13, 2023
1 parent b0642e6 commit 689318b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/components/procedure/card/chorus_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def render?
@procedure.chorusable?
end

def error_messages
[]
def complete?
@procedure.chorus_configuration.complete?
end
end
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
.fr-col-6.fr-col-md-4.fr-col-lg-3.chorus-component
= link_to edit_admin_procedure_chorus_path(@procedure), class: 'fr-tile fr-enlarge-link', title: 'Configurer le cadre budgetaire Chorus' do
.fr-tile__body.flex.column.align-center.justify-between
- if error_messages.present?
%div
%span.icon.refuse
%p.fr-tile-status-error À modifier
- elsif @count == 0
- if !@procedure.chorus_configuration.complete?
%div
%span.icon.clock
%p.fr-tile-status-todo À compléter
Expand Down
8 changes: 8 additions & 0 deletions app/models/chorus_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ def self.format_ref_programmation_label(api_result)
api_result = api_result.symbolize_keys
"#{api_result[:label]} - #{api_result[:code]}"
end

def complete?
[
centre_de_coup,
domaine_fonctionnel,
referentiel_de_programmation
].all?(&:present?)
end
end
16 changes: 16 additions & 0 deletions spec/factories/procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,22 @@
trait :svr do
sva_svr { SVASVRConfiguration.new(decision: :svr).attributes }
end

trait :empty_chorus do
chorus { ChorusConfiguration.new }
end

trait :partial_chorus do
chorus { ChorusConfiguration.new(centre_de_coup: { a: 1 }) }
end

trait :filled_chorus do
chorus do
ChorusConfiguration.new(centre_de_coup: { a: 1 },
domaine_fonctionnel: { b: 2 },
referentiel_de_programmation: { c: 3 })
end
end
end
end

Expand Down
28 changes: 22 additions & 6 deletions spec/models/chorus_configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
describe ChorusConfiguration do
subject { create(:procedure) }
it { is_expected.to be_valid }

context 'empty' do
subject { create(:procedure, chorus: {}) }
subject { create(:procedure, :empty_chorus) }
it { is_expected.to be_valid }
end

context 'partially filled chorus_configuration' do
subject { create(:procedure, chorus: { 'centre_de_cout' => '1' }) }
subject { create(:procedure, :partial_chorus) }
it { is_expected.to be_valid }
end

context 'fully filled chorus_configuration' do
subject { create(:procedure, chorus: { 'centre_de_coup' => {}, 'domaine_fonctionnel' => {}, 'referentiel_de_programmation' => {} }) }
subject { create(:procedure, :filled_chorus) }
it { is_expected.to be_valid }
end

Expand All @@ -33,4 +30,23 @@
end.not_to raise_error
end
end

describe '#complete?' do
subject { procedure.chorus_configuration.complete? }

context 'without data' do
let(:procedure) { create(:procedure, :empty_chorus) }
it { is_expected.to be_falsey }
end

context 'with partial data' do
let(:procedure) { create(:procedure, :partial_chorus) }
it { is_expected.to be_falsey }
end

context 'with all data' do
let(:procedure) { create(:procedure, :filled_chorus) }
it { is_expected.to be_truthy }
end
end
end

0 comments on commit 689318b

Please sign in to comment.