Merge pull request #8833 from mfo/US/fix-valid-conditions-on-repetition
correctif(revision.validation-des-conditions): les conditions dans un bloc répétable ne remontenpt pas dans le composant ErrorsSummary
This commit is contained in:
commit
4336184fc8
2 changed files with 26 additions and 3 deletions
|
@ -392,6 +392,7 @@ class ProcedureRevision < ApplicationRecord
|
|||
public_tdcs = types_de_champ_public.to_a
|
||||
|
||||
public_tdcs
|
||||
.flat_map { _1.repetition? ? children_of(_1) : _1 }
|
||||
.map.with_index
|
||||
.filter_map { |tdc, i| tdc.condition? ? [tdc, i] : nil }
|
||||
.map { |tdc, i| [tdc, tdc.condition.errors(public_tdcs.take(i))] }
|
||||
|
|
|
@ -828,21 +828,22 @@ describe ProcedureRevision do
|
|||
draft_revision.errors
|
||||
end
|
||||
|
||||
before { second_champ.update(condition: condition) }
|
||||
|
||||
context 'when a champ has a valid condition (type)' do
|
||||
before { second_champ.update(condition: condition) }
|
||||
let(:condition) { ds_eq(constant(true), constant(true)) }
|
||||
|
||||
it { is_expected.to be_empty }
|
||||
end
|
||||
|
||||
context 'when a champ has a valid condition: needed tdc is up in the forms' do
|
||||
before { second_champ.update(condition: condition) }
|
||||
let(:condition) { ds_eq(champ_value(first_champ.stable_id), constant(1)) }
|
||||
|
||||
it { is_expected.to be_empty }
|
||||
end
|
||||
|
||||
context 'when a champ has an invalid condition' do
|
||||
before { second_champ.update(condition: condition) }
|
||||
let(:condition) { ds_eq(constant(true), constant(1)) }
|
||||
|
||||
it { expect(subject.first.attribute).to eq(:condition) }
|
||||
|
@ -851,7 +852,28 @@ describe ProcedureRevision do
|
|||
context 'when a champ has an invalid condition: needed tdc is down in the forms' do
|
||||
let(:need_second_champ) { ds_eq(constant('oui'), champ_value(second_champ.stable_id)) }
|
||||
|
||||
before { first_champ.update(condition: need_second_champ) }
|
||||
before do
|
||||
second_champ.update(condition: condition)
|
||||
first_champ.update(condition: need_second_champ)
|
||||
end
|
||||
|
||||
it { expect(subject.first.attribute).to eq(:condition) }
|
||||
end
|
||||
|
||||
context 'when a champ belongs to a repetition' do
|
||||
let(:procedure) do
|
||||
create(:procedure,
|
||||
types_de_champ_public: [{ type: :repetition, children: [{ type: :integer_number }, { type: :text }] }])
|
||||
end
|
||||
let(:condition) { ds_eq(constant(true), constant(1)) }
|
||||
|
||||
before do
|
||||
repetition = procedure.draft_revision.types_de_champ_public.find(&:repetition?)
|
||||
champs_repetition = procedure.draft_revision.children_of(repetition)
|
||||
integer_champ = champs_repetition.first
|
||||
text_champ = champs_repetition.last
|
||||
text_champ.update(condition: condition)
|
||||
end
|
||||
|
||||
it { expect(subject.first.attribute).to eq(:condition) }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue