fix specs

This commit is contained in:
Lisa Durand 2023-05-22 16:26:50 +02:00
parent 4a51a9a351
commit b6cc35df68
8 changed files with 45 additions and 12 deletions

View file

@ -12,10 +12,21 @@ function syncFormToPreview() {
syncInputToElement('#procedure_libelle', '.procedure-title');
syncInputToElement('#procedure_description', '.procedure-description-body');
syncInputToElement('#procedure_description_what', '.js_description_what p');
syncInputToElement('#procedure_description_for_who', '.js_description_for_who p');
syncInputToElement(
'#procedure_description_for_who',
'.js_description_for_who p'
);
}
delegate('input', '.procedure-form #procedure_libelle', syncFormToPreview);
delegate('input', '.procedure-form #procedure_description', syncFormToPreview);
delegate('input', '.procedure-form #procedure_description_what', syncFormToPreview);
delegate('input', '.procedure-form #procedure_description_for_who', syncFormToPreview);
delegate(
'input',
'.procedure-form #procedure_description_what',
syncFormToPreview
);
delegate(
'input',
'.procedure-form #procedure_description_for_who',
syncFormToPreview
);

View file

@ -282,8 +282,8 @@ class Procedure < ApplicationRecord
}
validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :description, presence: true, allow_blank: false, allow_nil: false, if: -> { description_what.nil? && description_for_who.nil?}
validates :description_what, :description_for_who, presence: true, allow_blank: false, allow_nil: false, if: -> { description.nil?}
validates :description, presence: true, allow_blank: false, allow_nil: false, if: -> { description_what.nil? && description_for_who.nil? }
validates :description_what, :description_for_who, presence: true, allow_blank: false, allow_nil: false, if: -> { description.nil? }
validates :administrateurs, presence: true
validates :lien_site_web, presence: true, if: :publiee?
validates :draft_types_de_champ_public,

View file

@ -9,6 +9,7 @@
= render partial: 'shared/procedure_description', locals: { procedure: procedure }
- else
= render partial: 'layouts/commencer/no_procedure'
= yield
- content_for :footer do
- if procedure

View file

@ -37,12 +37,12 @@
.fr-accordions-group
%section.fr-accordion
%h3.fr-accordion__title
%button.fr-accordion__btn{"aria-controls" => "accordion-114", "aria-expanded" => "true"} Quel est lobjet de cette démarche ?
%button.fr-accordion__btn{ "aria-controls" => "accordion-114", "aria-expanded" => "true" } Quel est lobjet de cette démarche ?
#accordion-114.fr-collapse.js_description_what
= h render SimpleFormatComponent.new(procedure.description_what, allow_a: true)
%section.fr-accordion
%h3.fr-accordion__title
%button.fr-accordion__btn{"aria-controls" => "accordion-115", "aria-expanded" => "false"} À qui sadresse la démarche ?
%button.fr-accordion__btn{ "aria-controls" => "accordion-115", "aria-expanded" => "false" } À qui sadresse la démarche ?
#accordion-115.fr-collapse.js_description_for_who
= h render SimpleFormatComponent.new(procedure.description_for_who, allow_a: true)

View file

@ -178,9 +178,26 @@ describe Procedure do
end
context 'description' do
it { is_expected.not_to allow_value(nil).for(:description) }
it { is_expected.not_to allow_value('').for(:description) }
it { is_expected.to allow_value('Description Demande de subvention').for(:description) }
context 'description can not be nil if description_what and description_for_who are nil too' do
let(:procedure) { build(:procedure, description: nil) }
it { is_expected.to allow_value('Description Demande de subvention').for(:description) }
it { expect(procedure.valid?).to eq(false) }
end
context 'description can be nil if description_what and description_for_who are filled' do
let(:procedure) { build(:procedure, description: nil, description_for_who: 'for who', description_what: 'what') }
it { expect(procedure.valid?).to eq(true) }
end
context 'description_what and description_for_who can not be nil if description is nil too' do
let(:procedure) { build(:procedure, description: nil) }
it { expect(procedure.valid?).to eq(false) }
end
context 'description_what and description_for_who can be nil if description is filled' do
let(:procedure) { build(:procedure, description: 'description') }
it { expect(procedure.valid?).to eq(true) }
end
end
context 'organisation' do

View file

@ -5,5 +5,9 @@ module Capybara
def has_procedure_description?(procedure)
has_content?(procedure.libelle) && has_content?(procedure.description) && has_content?(procedure.service.email)
end
def has_procedure_sumup_description?(procedure)
has_content?(procedure.libelle) && has_content?(procedure.service.email)
end
end
end

View file

@ -43,7 +43,7 @@ describe 'Signin in:' do
click_on 'Commencer la démarche'
expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last)
expect(page).to have_procedure_description(procedure)
expect(page).to have_procedure_sumup_description(procedure)
expect(page).to have_content "Données didentité"
end
end

View file

@ -84,7 +84,7 @@ describe 'Signing up:' do
click_on 'Commencer la démarche'
expect(page).to have_current_path identite_dossier_path(procedure.reload.dossiers.last)
expect(page).to have_procedure_description(procedure)
expect(page).to have_procedure_sumup_description(procedure)
end
end