Store drop_down_list values as jsonb
This commit is contained in:
parent
29d3d58645
commit
97f91513c8
19 changed files with 184 additions and 133 deletions
|
@ -1,9 +0,0 @@
|
|||
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
|
|
@ -52,21 +52,21 @@ FactoryBot.define do
|
|||
factory :type_de_champ_drop_down_list do
|
||||
libelle { 'Menu déroulant' }
|
||||
type_champ { TypeDeChamp.type_champs.fetch(:drop_down_list) }
|
||||
drop_down_list { create(:drop_down_list) }
|
||||
drop_down_list_value { "val1\r\nval2\r\n--separateur--\r\nval3" }
|
||||
trait :long do
|
||||
drop_down_list { create(:drop_down_list, :long) }
|
||||
drop_down_list_value { "alpha\r\nbravo\r\n--separateur--\r\ncharly\r\ndelta\r\necho\r\nfox-trot\r\ngolf" }
|
||||
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) }
|
||||
drop_down_list_value { "val1\r\nval2\r\n--separateur--\r\nval3" }
|
||||
trait :long do
|
||||
drop_down_list { create(:drop_down_list, :long) }
|
||||
drop_down_list_value { "alpha\r\nbravo\r\n--separateur--\r\ncharly\r\ndelta\r\necho\r\nfox-trot\r\ngolf" }
|
||||
end
|
||||
end
|
||||
factory :type_de_champ_linked_drop_down_list do
|
||||
type_champ { TypeDeChamp.type_champs.fetch(:linked_drop_down_list) }
|
||||
drop_down_list { create(:drop_down_list, value: "--primary--\nsecondary\n") }
|
||||
drop_down_list_value { "--primary--\nsecondary\n" }
|
||||
end
|
||||
factory :type_de_champ_pays do
|
||||
type_champ { TypeDeChamp.type_champs.fetch(:pays) }
|
||||
|
|
|
@ -139,7 +139,7 @@ feature 'As an administrateur I can edit types de champ', js: true do
|
|||
fill_in 'champ-0-libelle', with: 'Libellé de champ menu déroulant', fill_options: { clear: :backspace }
|
||||
fill_in 'champ-0-drop_down_list_value', with: 'Un menu', fill_options: { clear: :backspace }
|
||||
|
||||
wait_until { procedure.types_de_champ.first.drop_down_list&.value == 'Un menu' }
|
||||
wait_until { procedure.types_de_champ.first.drop_down_list_options == ['', 'Un menu'] }
|
||||
expect(page).to have_content('Formulaire enregistré')
|
||||
|
||||
page.refresh
|
||||
|
|
|
@ -13,8 +13,7 @@ feature 'linked dropdown lists' do
|
|||
Secondary 2.3
|
||||
END_OF_LIST
|
||||
end
|
||||
let(:drop_down_list) { create(:drop_down_list, value: list_items) }
|
||||
let(:type_de_champ) { create(:type_de_champ_linked_drop_down_list, libelle: 'linked dropdown', drop_down_list: drop_down_list) }
|
||||
let(:type_de_champ) { create(:type_de_champ_linked_drop_down_list, libelle: 'linked dropdown', drop_down_list_value: list_items) }
|
||||
|
||||
let!(:procedure) do
|
||||
p = create(:procedure, :published, :for_individual)
|
||||
|
|
|
@ -62,12 +62,12 @@ describe Champs::LinkedDropDownListChamp do
|
|||
end
|
||||
|
||||
describe '#mandatory_and_blank' do
|
||||
let(:drop_down_list) { build(:drop_down_list, value: "--Primary--\nSecondary") }
|
||||
let(:value) { "--Primary--\nSecondary" }
|
||||
|
||||
subject { described_class.new(type_de_champ: type_de_champ) }
|
||||
|
||||
context 'when the champ is not mandatory' do
|
||||
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_list: drop_down_list) }
|
||||
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_list_value: value) }
|
||||
|
||||
it 'blank is fine' do
|
||||
is_expected.not_to be_mandatory_and_blank
|
||||
|
@ -75,7 +75,7 @@ describe Champs::LinkedDropDownListChamp do
|
|||
end
|
||||
|
||||
context 'when the champ is mandatory' do
|
||||
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, mandatory: true, drop_down_list: drop_down_list) }
|
||||
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, mandatory: true, drop_down_list_value: value) }
|
||||
|
||||
context 'when there is no value' do
|
||||
it { is_expected.to be_mandatory_and_blank }
|
||||
|
@ -95,7 +95,7 @@ describe Champs::LinkedDropDownListChamp do
|
|||
end
|
||||
|
||||
context 'when there is nothing to select for the secondary value' do
|
||||
let(:drop_down_list) { build(:drop_down_list, value: "--A--\nAbbott\nAbelard\n--B--\n--C--\nCynthia") }
|
||||
let(:value) { "--A--\nAbbott\nAbelard\n--B--\n--C--\nCynthia" }
|
||||
before { subject.primary_value = 'B' }
|
||||
|
||||
it { is_expected.not_to be_mandatory_and_blank }
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
describe DropDownList do
|
||||
let(:dropdownlist) { create :drop_down_list, value: value }
|
||||
|
||||
describe '#options' do
|
||||
let(:value) do
|
||||
<<~EOS
|
||||
Cohésion sociale
|
||||
Dév.Eco / Emploi
|
||||
Cadre de vie / Urb.
|
||||
Pilotage / Ingénierie
|
||||
EOS
|
||||
end
|
||||
|
||||
it { expect(dropdownlist.options).to eq ['', 'Cohésion sociale', 'Dév.Eco / Emploi', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
|
||||
|
||||
context 'when one value is empty' do
|
||||
let(:value) do
|
||||
<<~EOS
|
||||
Cohésion sociale
|
||||
Cadre de vie / Urb.
|
||||
Pilotage / Ingénierie
|
||||
EOS
|
||||
end
|
||||
|
||||
it { expect(dropdownlist.options).to eq ['', 'Cohésion sociale', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'disabled_options' do
|
||||
let(:value) do
|
||||
<<~EOS
|
||||
tip
|
||||
--top--
|
||||
--troupt--
|
||||
ouaich
|
||||
EOS
|
||||
end
|
||||
|
||||
it { expect(dropdownlist.disabled_options).to match(['--top--', '--troupt--']) }
|
||||
end
|
||||
end
|
|
@ -187,4 +187,44 @@ shared_examples 'type_de_champ_spec' do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#drop_down_list_options' do
|
||||
let(:value) do
|
||||
<<~EOS
|
||||
Cohésion sociale
|
||||
Dév.Eco / Emploi
|
||||
Cadre de vie / Urb.
|
||||
Pilotage / Ingénierie
|
||||
EOS
|
||||
end
|
||||
let(:type_de_champ) { create(:type_de_champ_drop_down_list, drop_down_list_value: value) }
|
||||
|
||||
it { expect(type_de_champ.drop_down_list_options).to eq ['', 'Cohésion sociale', 'Dév.Eco / Emploi', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
|
||||
|
||||
context 'when one value is empty' do
|
||||
let(:value) do
|
||||
<<~EOS
|
||||
Cohésion sociale
|
||||
Cadre de vie / Urb.
|
||||
Pilotage / Ingénierie
|
||||
EOS
|
||||
end
|
||||
|
||||
it { expect(type_de_champ.drop_down_list_options).to eq ['', 'Cohésion sociale', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'disabled_options' do
|
||||
let(:value) do
|
||||
<<~EOS
|
||||
tip
|
||||
--top--
|
||||
--troupt--
|
||||
ouaich
|
||||
EOS
|
||||
end
|
||||
let(:type_de_champ) { create(:type_de_champ_drop_down_list, drop_down_list_value: value) }
|
||||
|
||||
it { expect(type_de_champ.drop_down_list_disabled_options).to match(['--top--', '--troupt--']) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
describe TypesDeChamp::LinkedDropDownListTypeDeChamp do
|
||||
let(:drop_down_list) { build(:drop_down_list, value: menu_options) }
|
||||
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_list: drop_down_list) }
|
||||
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_list_value: menu_options) }
|
||||
|
||||
subject { type_de_champ.dynamic_type }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue