add prefill decorator for multiple drop down list
This commit is contained in:
parent
cbe2dc9c2d
commit
d648ac31c2
4 changed files with 48 additions and 0 deletions
|
@ -0,0 +1,8 @@
|
|||
class TypesDeChamp::PrefillMultipleDropDownListTypeDeChamp < TypesDeChamp::PrefillDropDownListTypeDeChamp
|
||||
def example_value
|
||||
return nil if possible_values.empty?
|
||||
return possible_values.first if possible_values.one?
|
||||
|
||||
[possible_values.first, possible_values.second]
|
||||
end
|
||||
end
|
|
@ -5,6 +5,8 @@ class TypesDeChamp::PrefillTypeDeChamp < SimpleDelegator
|
|||
case type_de_champ.type_champ
|
||||
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
||||
TypesDeChamp::PrefillDropDownListTypeDeChamp.new(type_de_champ)
|
||||
when TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
|
||||
TypesDeChamp::PrefillMultipleDropDownListTypeDeChamp.new(type_de_champ)
|
||||
when TypeDeChamp.type_champs.fetch(:pays)
|
||||
TypesDeChamp::PrefillPaysTypeDeChamp.new(type_de_champ)
|
||||
when TypeDeChamp.type_champs.fetch(:regions)
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe TypesDeChamp::PrefillMultipleDropDownListTypeDeChamp do
|
||||
describe 'ancestors' do
|
||||
subject { described_class.new(build(:type_de_champ_multiple_drop_down_list)) }
|
||||
|
||||
it { is_expected.to be_kind_of(TypesDeChamp::PrefillDropDownListTypeDeChamp) }
|
||||
end
|
||||
|
||||
describe '#example_value' do
|
||||
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, drop_down_list_value: drop_down_list_value) }
|
||||
subject(:example_value) { described_class.new(type_de_champ).example_value }
|
||||
|
||||
context 'when the multiple drop down list has no option' do
|
||||
let(:drop_down_list_value) { "" }
|
||||
|
||||
it { expect(example_value).to eq(nil) }
|
||||
end
|
||||
|
||||
context 'when the multiple drop down list only has one option' do
|
||||
let(:drop_down_list_value) { "value" }
|
||||
|
||||
it { expect(example_value).to eq("value") }
|
||||
end
|
||||
|
||||
context 'when the multiple drop down list has two options or more' do
|
||||
let(:drop_down_list_value) { "value1\r\nvalue2\r\nvalue3" }
|
||||
|
||||
it { expect(example_value).to eq(["value1", "value2"]) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,6 +10,12 @@ RSpec.describe TypesDeChamp::PrefillTypeDeChamp, type: :model do
|
|||
it { expect(built).to be_kind_of(TypesDeChamp::PrefillDropDownListTypeDeChamp) }
|
||||
end
|
||||
|
||||
context 'when the type de champ is a multiple_drop_down_list' do
|
||||
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list) }
|
||||
|
||||
it { expect(built).to be_kind_of(TypesDeChamp::PrefillMultipleDropDownListTypeDeChamp) }
|
||||
end
|
||||
|
||||
context 'when the type de champ is a pays' do
|
||||
let(:type_de_champ) { build(:type_de_champ_pays) }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue