2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-01-04 13:09:14 +01:00
|
|
|
describe ChampConditionalConcern do
|
|
|
|
include Logic
|
|
|
|
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :decimal_number, stable_id: 99 }, { type: :decimal_number, stable_id: 999, condition: }]) }
|
|
|
|
let(:dossier) { create(:dossier, :with_populated_champs, revision: procedure.active_revision) }
|
|
|
|
let(:champ) { dossier.champs.find { _1.stable_id == 99 }.tap { _1.update_column(:value, '1.1234') } }
|
|
|
|
let(:last_champ) { dossier.champs.find { _1.stable_id == 999 }.tap { _1.update_column(:value, '1.1234') } }
|
2024-04-05 10:34:01 +02:00
|
|
|
let(:condition) { nil }
|
2023-01-04 13:09:14 +01:00
|
|
|
|
|
|
|
describe '#dependent_conditions?' do
|
|
|
|
context "when there are no condition" do
|
|
|
|
it { expect(champ.dependent_conditions?).to eq(false) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when other tdc has a condition" do
|
2024-04-05 10:34:01 +02:00
|
|
|
let(:condition) { ds_eq(champ_value(99), constant(1)) }
|
2023-01-04 13:09:14 +01:00
|
|
|
|
|
|
|
it { expect(champ.dependent_conditions?).to eq(true) }
|
|
|
|
end
|
|
|
|
end
|
2024-04-05 10:34:01 +02:00
|
|
|
|
|
|
|
describe '#visible?' do
|
|
|
|
context "when there are no condition" do
|
|
|
|
it {
|
|
|
|
expect(champ.visible?).to eq(true)
|
|
|
|
expect(champ.valid?(:champs_public_value)).to eq(false)
|
|
|
|
|
|
|
|
expect(last_champ.visible?).to eq(true)
|
|
|
|
expect(last_champ.valid?(:champs_public_value)).to eq(false)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when other tdc has a condition" do
|
|
|
|
let(:condition) { ds_eq(champ_value(99), constant(1)) }
|
|
|
|
|
|
|
|
it {
|
|
|
|
expect(champ.visible?).to eq(true)
|
|
|
|
expect(champ.valid?(:champs_public_value)).to eq(false)
|
|
|
|
|
|
|
|
expect(last_champ.visible?).to eq(false)
|
|
|
|
expect(last_champ.valid?(:champs_public_value)).to eq(true)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2023-01-04 13:09:14 +01:00
|
|
|
end
|