From 465449e6841f9f70dbd03c694066718d34a9763e Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Wed, 24 Jun 2020 10:55:53 +0200 Subject: [PATCH] fix unit tests --- spec/factories/drop_down_list.rb | 4 ++++ spec/factories/procedure.rb | 2 ++ spec/factories/type_de_champ.rb | 6 ++++++ spec/features/users/brouillon_spec.rb | 18 +++++++++++++----- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/spec/factories/drop_down_list.rb b/spec/factories/drop_down_list.rb index 5cc47a7fa..c2763e3c4 100644 --- a/spec/factories/drop_down_list.rb +++ b/spec/factories/drop_down_list.rb @@ -1,5 +1,9 @@ FactoryBot.define do factory :drop_down_list do value { "val1\r\nval2\r\n--separateur--\r\nval3" } + + trait :long do + value { "alpha\r\nbravo\r\n--separateur--\r\ncharly\r\ndelta\r\necho\r\nfox-trot\r\ngolf" } + end end end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 7fcc26f39..e111638d0 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -233,6 +233,8 @@ FactoryBot.define do end build(:"type_de_champ_#{type_champ}", mandatory: true, libelle: libelle, order_place: index) end + procedure.types_de_champ << build(:type_de_champ_drop_down_list, :long, mandatory: true, libelle: 'simple_choice_drop_down_list_long') + procedure.types_de_champ << build(:type_de_champ_multiple_drop_down_list, :long, mandatory: true, libelle: 'multiple_choice_drop_down_list_long') end end diff --git a/spec/factories/type_de_champ.rb b/spec/factories/type_de_champ.rb index 597d84c9e..ee8b84721 100644 --- a/spec/factories/type_de_champ.rb +++ b/spec/factories/type_de_champ.rb @@ -53,10 +53,16 @@ FactoryBot.define do libelle { 'Menu déroulant' } type_champ { TypeDeChamp.type_champs.fetch(:drop_down_list) } drop_down_list { create(:drop_down_list) } + trait :long do + drop_down_list { create(:drop_down_list, :long) } + end end factory :type_de_champ_multiple_drop_down_list do type_champ { TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) } drop_down_list { create(:drop_down_list) } + trait :long do + drop_down_list { create(:drop_down_list, :long) } + end end factory :type_de_champ_linked_drop_down_list do type_champ { TypeDeChamp.type_champs.fetch(:linked_drop_down_list) } diff --git a/spec/features/users/brouillon_spec.rb b/spec/features/users/brouillon_spec.rb index 8b6a02d2d..d9c126487 100644 --- a/spec/features/users/brouillon_spec.rb +++ b/spec/features/users/brouillon_spec.rb @@ -21,9 +21,12 @@ feature 'The user' do fill_in('email', with: 'loulou@yopmail.com') fill_in('phone', with: '1234567890') choose('Non') - select('val2', from: form_id_for('simple_drop_down_list')) - select('val1', from: form_id_for('multiple_drop_down_list')) - select('val3', from: form_id_for('multiple_drop_down_list')) + choose('val2') + check('val1') + check('val3') + select('bravo', from: form_id_for('simple_choice_drop_down_list_long')) + select('alpha', from: form_id_for('multiple_choice_drop_down_list_long')) + select('charly', from: form_id_for('multiple_choice_drop_down_list_long')) select('AUSTRALIE', from: 'pays') select_champ_geo('regions', 'Ma', 'Martinique') @@ -55,6 +58,8 @@ feature 'The user' do expect(champ_value_for('phone')).to eq('1234567890') expect(champ_value_for('yes_no')).to eq('false') expect(champ_value_for('simple_drop_down_list')).to eq('val2') + expect(champ_value_for('simple_choice_drop_down_list_long')).to eq('bravo') + expect(JSON.parse(champ_value_for('multiple_choice_drop_down_list_long'))).to match(['alpha', 'charly']) expect(JSON.parse(champ_value_for('multiple_drop_down_list'))).to match(['val1', 'val3']) expect(champ_value_for('pays')).to eq('AUSTRALIE') expect(champ_value_for('regions')).to eq('Martinique') @@ -76,8 +81,11 @@ feature 'The user' do expect(page).to have_field('email', with: 'loulou@yopmail.com') expect(page).to have_field('phone', with: '1234567890') expect(page).to have_checked_field('Non') - expect(page).to have_selected_value('simple_drop_down_list', selected: 'val2') - expect(page).to have_selected_value('multiple_drop_down_list', selected: ['val1', 'val3']) + expect(page).to have_checked_field('val2') + expect(page).to have_checked_field('val1') + expect(page).to have_checked_field('val3') + expect(page).to have_selected_value('simple_choice_drop_down_list_long', selected: 'bravo') + expect(page).to have_selected_value('multiple_choice_drop_down_list_long', selected: ['alpha', 'charly']) expect(page).to have_selected_value('pays', selected: 'AUSTRALIE') expect(page).to have_selected_value('regions', selected: 'Martinique') expect(page).to have_selected_value('departements', selected: '02 - Aisne')