feat(procedure.validation): extract validation context: types_de_champ_public_editor, types_de_champ_private_editor and publication [combining both contextes]. validate conditions, headers_sections, regexp on type_de_champ_private too. dry validation
This commit is contained in:
parent
f508921d2f
commit
ef3ca9839b
37 changed files with 398 additions and 221 deletions
|
@ -0,0 +1,30 @@
|
|||
describe Procedure::Card::AnnotationsComponent, type: :component do
|
||||
describe 'render' do
|
||||
let(:procedure) { create(:procedure, id: 1, types_de_champ_private:, types_de_champ_public:) }
|
||||
let(:types_de_champ_private) { [] }
|
||||
let(:types_de_champ_public) { [] }
|
||||
before { procedure.validate(:publication) }
|
||||
subject { render_inline(described_class.new(procedure: procedure)) }
|
||||
|
||||
context 'when no errors' do
|
||||
it 'does not render' do
|
||||
expect(subject).to have_selector('.fr-badge--info', text: 'À configurer')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when errors on types_de_champs_public' do
|
||||
let(:types_de_champ_public) { [{ type: :drop_down_list, options: [] }] }
|
||||
it 'does not render' do
|
||||
expect(subject).to have_selector('.fr-badge--info', text: 'À configurer')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when errors on types_de_champs_private' do
|
||||
let(:types_de_champ_private) { [{ type: :drop_down_list, options: [] }] }
|
||||
|
||||
it 'render the template' do
|
||||
expect(subject).to have_selector('.fr-badge--error', text: 'À modifier')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
30
spec/components/procedures/card/champs_component_spec.rb
Normal file
30
spec/components/procedures/card/champs_component_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
describe Procedure::Card::ChampsComponent, type: :component do
|
||||
describe 'render' do
|
||||
let(:procedure) { create(:procedure, id: 1, types_de_champ_private:, types_de_champ_public:) }
|
||||
let(:types_de_champ_private) { [] }
|
||||
let(:types_de_champ_public) { [] }
|
||||
before { procedure.validate(:publication) }
|
||||
subject { render_inline(described_class.new(procedure: procedure)) }
|
||||
|
||||
context 'when no errors' do
|
||||
it 'does not render' do
|
||||
expect(subject).to have_selector('.fr-badge--warning', text: 'À faire')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when errors on types_de_champs_public' do
|
||||
let(:types_de_champ_public) { [{ type: :drop_down_list, options: [] }] }
|
||||
it 'does not render' do
|
||||
expect(subject).to have_selector('.fr-badge--error', text: 'À modifier')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when errors on types_de_champs_private' do
|
||||
let(:types_de_champ_private) { [{ type: :drop_down_list, options: [] }] }
|
||||
|
||||
it 'render the template' do
|
||||
expect(subject).to have_selector('.fr-badge--warning', text: 'À faire')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
80
spec/components/procedures/errors_summary_spec.rb
Normal file
80
spec/components/procedures/errors_summary_spec.rb
Normal file
|
@ -0,0 +1,80 @@
|
|||
describe Procedure::ErrorsSummary, type: :component do
|
||||
subject { render_inline(described_class.new(procedure:, validation_context:)) }
|
||||
|
||||
describe 'validations context' do
|
||||
let(:procedure) { create(:procedure, types_de_champ_private:, types_de_champ_public:) }
|
||||
let(:types_de_champ_private) { [{ type: :drop_down_list, options: [], libelle: 'private' }] }
|
||||
let(:types_de_champ_public) { [{ type: :drop_down_list, options: [], libelle: 'public' }] }
|
||||
|
||||
before { subject }
|
||||
|
||||
context 'when :publication' do
|
||||
let(:validation_context) { :publication }
|
||||
|
||||
it 'shows errors for public and private tdc' do
|
||||
expect(page).to have_text("Le champ « public » doit comporter au moins un choix sélectionnable")
|
||||
expect(page).to have_text("L’annotation privée « private » doit comporter au moins un choix sélectionnable")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when :types_de_champ_public_editor' do
|
||||
let(:validation_context) { :types_de_champ_public_editor }
|
||||
|
||||
it 'shows errors for public only tdc' do
|
||||
expect(page).to have_text("Le champ « public » doit comporter au moins un choix sélectionnable")
|
||||
expect(page).not_to have_text("L’annotation privée « private » doit comporter au moins un choix sélectionnable")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when :types_de_champ_private_editor' do
|
||||
let(:validation_context) { :types_de_champ_private_editor }
|
||||
|
||||
it 'shows errors for private only tdc' do
|
||||
expect(page).not_to have_text("Le champ « public » doit comporter au moins un choix sélectionnable")
|
||||
expect(page).to have_text("L’annotation privée « private » doit comporter au moins un choix sélectionnable")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'render all kind of champs errors' do
|
||||
include Logic
|
||||
|
||||
let(:procedure) do
|
||||
create(:procedure, id: 1, types_de_champ_public: [
|
||||
{ libelle: 'repetition requires children', type: :repetition, children: [] },
|
||||
{ libelle: 'drop down list requires options', type: :drop_down_list, options: [] },
|
||||
{ libelle: 'invalid condition', type: :text, condition: ds_eq(constant(true), constant(1)) },
|
||||
{ libelle: 'header sections must have consistent order', type: :header_section, level: 2 }
|
||||
])
|
||||
end
|
||||
|
||||
let(:validation_context) { :types_de_champ_public_editor }
|
||||
|
||||
before { subject }
|
||||
|
||||
it 'renders all errors on champ' do
|
||||
expect(page).to have_text("Le champ « drop down list requires options » doit comporter au moins un choix sélectionnable")
|
||||
expect(page).to have_text("Le champ « repetition requires children » doit comporter au moins un champ répétable")
|
||||
expect(page).to have_text("Le champ « invalid condition » a une logique conditionnelle invalide")
|
||||
expect(page).to have_text("Le champ « header sections must have consistent order » devrait être précédé d'un titre de niveau 1")
|
||||
# TODO, test attestation_template, initiated_mail, :received_mail, :closed_mail, :refused_mail, :without_continuation_mail, :re_instructed_mail
|
||||
end
|
||||
end
|
||||
|
||||
describe 'render error for other kind of associated objects' do
|
||||
let(:validation_context) { :publication }
|
||||
let(:procedure) { create(:procedure, attestation_template:, initiated_mail:) }
|
||||
let(:attestation_template) { build(:attestation_template) }
|
||||
let(:initiated_mail) { build(:initiated_mail) }
|
||||
|
||||
before do
|
||||
[:attestation_template, :initiated_mail].map { procedure.send(_1).update_column(:body, '--invalidtag--') }
|
||||
subject
|
||||
end
|
||||
|
||||
it 'render error nicely' do
|
||||
expect(page).to have_text("Le modèle d’attestation n'est pas valide")
|
||||
expect(page).to have_text("L’email de notification de passage de dossier en instruction n'est pas valide")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue