Improuve champ blank check
This commit is contained in:
parent
38b73f0fee
commit
ac0f50b488
6 changed files with 39 additions and 18 deletions
|
@ -95,15 +95,8 @@ class Champ < ApplicationRecord
|
|||
end
|
||||
|
||||
def blank?
|
||||
case type_de_champ.type_champ
|
||||
when TypeDeChamp.type_champs.fetch(:carte)
|
||||
geo_areas.blank? || value == '[]'
|
||||
when TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
|
||||
value.blank? || value == '[]'
|
||||
else
|
||||
value.blank?
|
||||
end
|
||||
end
|
||||
|
||||
def search_terms
|
||||
[to_s]
|
||||
|
|
|
@ -109,6 +109,10 @@ class Champs::CarteChamp < Champ
|
|||
nil
|
||||
end
|
||||
|
||||
def blank?
|
||||
geo_areas.blank?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def selection_utilisateur_legacy_geometry
|
||||
|
|
|
@ -62,6 +62,10 @@ class Champs::MultipleDropDownListChamp < Champ
|
|||
enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX
|
||||
end
|
||||
|
||||
def blank?
|
||||
selected_options.blank?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_before_save
|
||||
|
|
|
@ -30,8 +30,8 @@ class Champs::RepetitionChamp < Champ
|
|||
end
|
||||
end
|
||||
|
||||
def mandatory_and_blank?
|
||||
mandatory? && champs.empty?
|
||||
def blank?
|
||||
champs.empty?
|
||||
end
|
||||
|
||||
def search_terms
|
||||
|
|
|
@ -176,7 +176,11 @@ FactoryBot.define do
|
|||
factory :champ_repetition, class: 'Champs::RepetitionChamp' do
|
||||
type_de_champ { association :type_de_champ_repetition, procedure: dossier.procedure }
|
||||
|
||||
after(:build) do |champ_repetition, _evaluator|
|
||||
transient do
|
||||
rows { 2 }
|
||||
end
|
||||
|
||||
after(:build) do |champ_repetition, evaluator|
|
||||
types_de_champ = champ_repetition.type_de_champ.types_de_champ
|
||||
existing_type_de_champ_text = types_de_champ.find { |tdc| tdc.libelle == 'Nom' }
|
||||
type_de_champ_text = existing_type_de_champ_text || build(
|
||||
|
@ -195,13 +199,13 @@ FactoryBot.define do
|
|||
)
|
||||
|
||||
champ_repetition.type_de_champ.types_de_champ << [type_de_champ_text, type_de_champ_number]
|
||||
evaluator.rows.times do |row|
|
||||
champ_repetition.champs << [
|
||||
build(:champ_text, dossier: champ_repetition.dossier, row: 0, type_de_champ: type_de_champ_text, parent: champ_repetition),
|
||||
build(:champ_number, dossier: champ_repetition.dossier, row: 0, type_de_champ: type_de_champ_number, parent: champ_repetition),
|
||||
build(:champ_text, dossier: champ_repetition.dossier, row: 1, type_de_champ: type_de_champ_text, parent: champ_repetition),
|
||||
build(:champ_number, dossier: champ_repetition.dossier, row: 1, type_de_champ: type_de_champ_number, parent: champ_repetition)
|
||||
build(:champ_text, dossier: champ_repetition.dossier, row: row, type_de_champ: type_de_champ_text, parent: champ_repetition),
|
||||
build(:champ_number, dossier: champ_repetition.dossier, row: row, type_de_champ: type_de_champ_number, parent: champ_repetition)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
trait :without_champs do
|
||||
after(:build) do |champ_repetition, _evaluator|
|
||||
|
|
|
@ -11,16 +11,32 @@ shared_examples 'champ_spec' do
|
|||
|
||||
context 'when carte mandatory and blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
|
||||
let(:value) { '[]' }
|
||||
let(:champ) { build(:champ_carte, type_de_champ: type_de_champ, value: value) }
|
||||
let(:value) { nil }
|
||||
it { expect(champ.mandatory_and_blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when multiple_drop_down_list mandatory and blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, mandatory: mandatory) }
|
||||
let(:champ) { build(:champ_multiple_drop_down_list, type_de_champ: type_de_champ, value: value) }
|
||||
let(:value) { '[]' }
|
||||
it { expect(champ.mandatory_and_blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when repetition blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_repetition) }
|
||||
let(:champ) { build(:champ_repetition, type_de_champ: type_de_champ, rows: 0) }
|
||||
|
||||
it { expect(champ.blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when repetition not blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_repetition) }
|
||||
let(:champ) { build(:champ_repetition, type_de_champ: type_de_champ) }
|
||||
|
||||
it { expect(champ.blank?).to be(false) }
|
||||
end
|
||||
|
||||
context 'when not blank' do
|
||||
let(:value) { 'yop' }
|
||||
it { expect(champ.mandatory_and_blank?).to be(false) }
|
||||
|
|
Loading…
Reference in a new issue