feat(cond): add tests
This commit is contained in:
parent
d513c364d8
commit
16a48c02aa
2 changed files with 208 additions and 134 deletions
|
@ -1,10 +1,10 @@
|
|||
describe Administrateurs::ConditionsController, type: :controller do
|
||||
include Logic
|
||||
|
||||
before { sign_in(procedure.administrateurs.first.user) }
|
||||
|
||||
context 'without bloc repetition' do
|
||||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :integer_number }] * 3) }
|
||||
let(:first_coordinate) { procedure.draft_revision.revision_types_de_champ.first }
|
||||
let(:second_coordinate) { procedure.draft_revision.revision_types_de_champ.first }
|
||||
let(:third_coordinate) { procedure.draft_revision.revision_types_de_champ.first }
|
||||
let(:first_tdc) { procedure.draft_revision.types_de_champ.first }
|
||||
let(:second_tdc) { procedure.draft_revision.types_de_champ.second }
|
||||
let(:third_tdc) { procedure.draft_revision.types_de_champ.third }
|
||||
|
@ -116,3 +116,44 @@ describe Administrateurs::ConditionsController, type: :controller do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a repetiton bloc' do
|
||||
let(:procedure) do
|
||||
create(:procedure, types_de_champ_public: [
|
||||
{ type: :integer_number, libelle: 'top_1' },
|
||||
{
|
||||
type: :repetition,
|
||||
libelle: 'repetition',
|
||||
children: [
|
||||
{ type: :integer_number, libelle: 'child_1' },
|
||||
{ type: :integer_number, libelle: 'child_2' }
|
||||
]
|
||||
}
|
||||
])
|
||||
end
|
||||
let(:tdcs) { procedure.draft_revision.types_de_champ }
|
||||
let(:top) { tdcs.find_by(libelle: 'top_1') }
|
||||
let(:repetition) { tdcs.find_by(libelle: 'repetition') }
|
||||
let(:child_1) { tdcs.find_by(libelle: 'child_1') }
|
||||
let(:child_2) { tdcs.find_by(libelle: 'child_2') }
|
||||
|
||||
let(:default_params) do
|
||||
{
|
||||
procedure_id: procedure.id,
|
||||
stable_id: child_2.stable_id
|
||||
}
|
||||
end
|
||||
|
||||
describe '#add_row' do
|
||||
before do
|
||||
post :add_row, params: default_params, format: :turbo_stream
|
||||
end
|
||||
|
||||
it do
|
||||
expect(child_2.reload.condition).to eq(empty_operator(empty, empty))
|
||||
expect(assigns(:coordinate)).to eq(procedure.draft_revision.coordinate_for(child_2))
|
||||
expect(assigns(:upper_tdcs)).to eq([child_1, top])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -289,52 +289,87 @@ describe 'The user' do
|
|||
include Logic
|
||||
|
||||
context 'with a repetition' do
|
||||
let(:stable_id) { 999 }
|
||||
let(:condition) { greater_than_eq(champ_value(stable_id), constant(18)) }
|
||||
let(:procedure) do
|
||||
procedure = create(:procedure, :published, :for_individual,
|
||||
create(:procedure, :published, :for_individual,
|
||||
types_de_champ_public: [
|
||||
{ type: :integer_number, libelle: 'age' },
|
||||
{ type: :integer_number, libelle: 'age', stable_id: },
|
||||
{
|
||||
type: :repetition, libelle: 'repetition', children: [
|
||||
type: :repetition, libelle: 'repetition', condition:, children: [
|
||||
{ type: :text, libelle: 'nom', mandatory: true }
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
age = procedure.published_revision.types_de_champ.where(libelle: 'age').first
|
||||
repetition = procedure.published_revision.types_de_champ.repetition.first
|
||||
repetition.update(condition: greater_than_eq(champ_value(age.stable_id), constant(18)))
|
||||
|
||||
procedure
|
||||
end
|
||||
|
||||
scenario 'submit a dossier with an hidden mandatory champ within a repetition', js: true do
|
||||
log_in(user, procedure)
|
||||
|
||||
fill_individual
|
||||
|
||||
fill_in('age', with: 10)
|
||||
click_on 'Déposer le dossier'
|
||||
expect(page).to have_current_path(merci_dossier_path(user_dossier))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a required conditionnal champ' do
|
||||
context 'with a condition inside repetition' do
|
||||
let(:a_stable_id) { 999 }
|
||||
let(:b_stable_id) { 9999 }
|
||||
let(:a_condition) { ds_eq(champ_value(a_stable_id), constant(true)) }
|
||||
let(:b_condition) { ds_eq(champ_value(b_stable_id), constant(true)) }
|
||||
let(:condition) { ds_or([a_condition, b_condition]) }
|
||||
let(:procedure) do
|
||||
procedure = create(:procedure, :published, :for_individual,
|
||||
create(:procedure, :published, :for_individual,
|
||||
types_de_champ_public: [
|
||||
{ type: :integer_number, libelle: 'age' },
|
||||
{ type: :text, libelle: 'nom', mandatory: true }
|
||||
{ type: :checkbox, libelle: 'champ_a', stable_id: a_stable_id },
|
||||
{
|
||||
type: :repetition, libelle: 'repetition', children: [
|
||||
{ type: :checkbox, libelle: 'champ_b', stable_id: b_stable_id },
|
||||
{ type: :text, libelle: 'champ_c', condition: }
|
||||
]
|
||||
}
|
||||
])
|
||||
end
|
||||
|
||||
age, nom = procedure.draft_revision.types_de_champ.all
|
||||
nom.update(condition: greater_than_eq(champ_value(age.stable_id), constant(18)))
|
||||
scenario 'fill a dossier', js: true do
|
||||
log_in(user, procedure)
|
||||
|
||||
procedure
|
||||
fill_individual
|
||||
|
||||
expect(page).to have_no_css('label', text: 'champ_c', visible: true)
|
||||
check('champ_a')
|
||||
wait_for_autosave
|
||||
|
||||
expect(page).to have_css('label', text: 'champ_c', visible: true)
|
||||
uncheck('champ_a')
|
||||
wait_for_autosave
|
||||
|
||||
expect(page).to have_no_css('label', text: 'champ_c', visible: true)
|
||||
check('champ_b')
|
||||
wait_for_autosave
|
||||
|
||||
expect(page).to have_css('label', text: 'champ_c', visible: true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a required conditionnal champ' do
|
||||
let(:stable_id) { 999 }
|
||||
let(:condition) { greater_than_eq(champ_value(stable_id), constant(18)) }
|
||||
let(:procedure) do
|
||||
create(:procedure, :published, :for_individual,
|
||||
types_de_champ_public: [
|
||||
{ type: :integer_number, libelle: 'age', stable_id: },
|
||||
{ type: :text, libelle: 'nom', mandatory: true, condition: }
|
||||
])
|
||||
end
|
||||
|
||||
scenario 'submit a dossier with an hidden mandatory champ ', js: true do
|
||||
log_in(user, procedure)
|
||||
|
||||
fill_individual
|
||||
|
||||
click_on 'Déposer le dossier'
|
||||
expect(page).to have_current_path(merci_dossier_path(user_dossier))
|
||||
end
|
||||
|
@ -353,23 +388,21 @@ describe 'The user' do
|
|||
end
|
||||
|
||||
context 'with a visibilite in cascade' do
|
||||
let(:age_stable_id) { 999 }
|
||||
let(:permis_stable_id) { 9999 }
|
||||
let(:tonnage_stable_id) { 99999 }
|
||||
let(:permis_condition) { greater_than_eq(champ_value(age_stable_id), constant(18)) }
|
||||
let(:tonnage_condition) { ds_eq(champ_value(permis_stable_id), constant(true)) }
|
||||
let(:parking_condition) { less_than_eq(champ_value(tonnage_stable_id), constant(20)) }
|
||||
|
||||
let(:procedure) do
|
||||
procedure = create(:procedure, :for_individual).tap do |p|
|
||||
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'age')
|
||||
p.draft_revision.add_type_de_champ(type_champ: :yes_no, libelle: 'permis de conduire')
|
||||
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'tonnage')
|
||||
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'parking')
|
||||
end
|
||||
|
||||
age, permis, tonnage, parking = procedure.draft_revision.types_de_champ.all
|
||||
|
||||
permis.update(condition: greater_than_eq(champ_value(age.stable_id), constant(18)))
|
||||
tonnage.update(condition: ds_eq(champ_value(permis.stable_id), constant(true)))
|
||||
parking.update(condition: less_than_eq(champ_value(tonnage.stable_id), constant(20)))
|
||||
|
||||
procedure.publish!
|
||||
|
||||
procedure
|
||||
create(:procedure, :published, :for_individual,
|
||||
types_de_champ_public: [
|
||||
{ type: :integer_number, libelle: 'age', stable_id: age_stable_id },
|
||||
{ type: :yes_no, libelle: 'permis de conduire', stable_id: permis_stable_id, condition: permis_condition },
|
||||
{ type: :integer_number, libelle: 'tonnage', stable_id: tonnage_stable_id, condition: tonnage_condition },
|
||||
{ type: :text, libelle: 'parking', condition: parking_condition }
|
||||
])
|
||||
end
|
||||
|
||||
scenario 'fill a dossier', js: true do
|
||||
|
|
Loading…
Add table
Reference in a new issue