Merge pull request #6357 from tchak/fix-false-positive-unspecified-tags-messages
Fix false positive unspecified tags messages
This commit is contained in:
commit
99b836da2c
8 changed files with 43 additions and 26 deletions
|
@ -39,16 +39,12 @@ class AttestationTemplate < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def unspecified_champs_for_dossier(dossier)
|
def unspecified_champs_for_dossier(dossier)
|
||||||
all_champs_with_libelle_index = (dossier.champs + dossier.champs_private)
|
all_champs_with_libelle_index = (dossier.champs + dossier.champs_private).index_by { |champ| "tdc#{champ.stable_id}" }
|
||||||
.reduce({}) do |acc, champ|
|
|
||||||
acc[champ.libelle] = champ
|
|
||||||
acc
|
|
||||||
end
|
|
||||||
|
|
||||||
used_tags.filter_map do |used_tag|
|
used_tags.filter_map do |used_tag|
|
||||||
corresponding_champ = all_champs_with_libelle_index[used_tag]
|
corresponding_champ = all_champs_with_libelle_index[used_tag]
|
||||||
|
|
||||||
if corresponding_champ && corresponding_champ.value.blank?
|
if corresponding_champ && corresponding_champ.blank?
|
||||||
corresponding_champ
|
corresponding_champ
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -113,7 +109,7 @@ class AttestationTemplate < ApplicationRecord
|
||||||
# We can't use flat_map as scan will return 3 levels of array,
|
# We can't use flat_map as scan will return 3 levels of array,
|
||||||
# using flat_map would give us 2, whereas flatten will
|
# using flat_map would give us 2, whereas flatten will
|
||||||
# give us 1, which is what we want
|
# give us 1, which is what we want
|
||||||
[title, body]
|
[normalize_tags(title), normalize_tags(body)]
|
||||||
.map { |str| str.scan(delimiters_regex) }
|
.map { |str| str.scan(delimiters_regex) }
|
||||||
.flatten
|
.flatten
|
||||||
end
|
end
|
||||||
|
|
|
@ -95,14 +95,7 @@ class Champ < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def blank?
|
def blank?
|
||||||
case type_de_champ.type_champ
|
value.blank?
|
||||||
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
|
end
|
||||||
|
|
||||||
def search_terms
|
def search_terms
|
||||||
|
|
|
@ -109,6 +109,10 @@ class Champs::CarteChamp < Champ
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def blank?
|
||||||
|
geo_areas.blank?
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def selection_utilisateur_legacy_geometry
|
def selection_utilisateur_legacy_geometry
|
||||||
|
|
|
@ -62,6 +62,10 @@ class Champs::MultipleDropDownListChamp < Champ
|
||||||
enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX
|
enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def blank?
|
||||||
|
selected_options.blank?
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def format_before_save
|
def format_before_save
|
||||||
|
|
|
@ -30,8 +30,8 @@ class Champs::RepetitionChamp < Champ
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory_and_blank?
|
def blank?
|
||||||
mandatory? && champs.empty?
|
champs.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_terms
|
def search_terms
|
||||||
|
|
|
@ -176,7 +176,11 @@ FactoryBot.define do
|
||||||
factory :champ_repetition, class: 'Champs::RepetitionChamp' do
|
factory :champ_repetition, class: 'Champs::RepetitionChamp' do
|
||||||
type_de_champ { association :type_de_champ_repetition, procedure: dossier.procedure }
|
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
|
types_de_champ = champ_repetition.type_de_champ.types_de_champ
|
||||||
existing_type_de_champ_text = types_de_champ.find { |tdc| tdc.libelle == 'Nom' }
|
existing_type_de_champ_text = types_de_champ.find { |tdc| tdc.libelle == 'Nom' }
|
||||||
type_de_champ_text = existing_type_de_champ_text || build(
|
type_de_champ_text = existing_type_de_champ_text || build(
|
||||||
|
@ -195,12 +199,12 @@ FactoryBot.define do
|
||||||
)
|
)
|
||||||
|
|
||||||
champ_repetition.type_de_champ.types_de_champ << [type_de_champ_text, type_de_champ_number]
|
champ_repetition.type_de_champ.types_de_champ << [type_de_champ_text, type_de_champ_number]
|
||||||
champ_repetition.champs << [
|
evaluator.rows.times do |row|
|
||||||
build(:champ_text, dossier: champ_repetition.dossier, row: 0, type_de_champ: type_de_champ_text, parent: champ_repetition),
|
champ_repetition.champs << [
|
||||||
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: row, type_de_champ: type_de_champ_text, 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: row, type_de_champ: type_de_champ_number, parent: champ_repetition)
|
||||||
build(:champ_number, dossier: champ_repetition.dossier, row: 1, type_de_champ: type_de_champ_number, parent: champ_repetition)
|
]
|
||||||
]
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :without_champs do
|
trait :without_champs do
|
||||||
|
|
|
@ -11,16 +11,32 @@ shared_examples 'champ_spec' do
|
||||||
|
|
||||||
context 'when carte mandatory and blank' do
|
context 'when carte mandatory and blank' do
|
||||||
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
|
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) }
|
it { expect(champ.mandatory_and_blank?).to be(true) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when multiple_drop_down_list mandatory and blank' do
|
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(: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) { '[]' }
|
let(:value) { '[]' }
|
||||||
it { expect(champ.mandatory_and_blank?).to be(true) }
|
it { expect(champ.mandatory_and_blank?).to be(true) }
|
||||||
end
|
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
|
context 'when not blank' do
|
||||||
let(:value) { 'yop' }
|
let(:value) { 'yop' }
|
||||||
it { expect(champ.mandatory_and_blank?).to be(false) }
|
it { expect(champ.mandatory_and_blank?).to be(false) }
|
||||||
|
|
|
@ -564,7 +564,7 @@ describe Dossier do
|
||||||
|
|
||||||
describe "#unspecified_attestation_champs" do
|
describe "#unspecified_attestation_champs" do
|
||||||
let(:procedure) { create(:procedure, attestation_template: attestation_template, types_de_champ: types_de_champ, types_de_champ_private: types_de_champ_private) }
|
let(:procedure) { create(:procedure, attestation_template: attestation_template, types_de_champ: types_de_champ, types_de_champ_private: types_de_champ_private) }
|
||||||
let(:dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
|
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
||||||
let(:types_de_champ) { [] }
|
let(:types_de_champ) { [] }
|
||||||
let(:types_de_champ_private) { [] }
|
let(:types_de_champ_private) { [] }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue