Merge pull request #2142 from betagouv/frederic/fix_1421-leftovers
Frederic/fix 1421 leftovers
This commit is contained in:
commit
4f9bf73fe5
5 changed files with 110 additions and 0 deletions
|
@ -28,8 +28,24 @@ class Champs::LinkedDropDownListChamp < Champ
|
||||||
:primary_value
|
:primary_value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def for_display
|
||||||
|
string_value
|
||||||
|
end
|
||||||
|
|
||||||
|
def mandatory_and_blank?
|
||||||
|
mandatory? && (primary_value.blank? || secondary_value.blank?)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def string_value
|
||||||
|
[primary_value, secondary_value].compact.join(' / ')
|
||||||
|
end
|
||||||
|
|
||||||
|
def value_for_export
|
||||||
|
"#{primary_value || ''};#{secondary_value || ''}"
|
||||||
|
end
|
||||||
|
|
||||||
def pack_value
|
def pack_value
|
||||||
self.value = JSON.generate([ primary_value, secondary_value ])
|
self.value = JSON.generate([ primary_value, secondary_value ])
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class Champs::LinkedDropDownListChampSerializer < ChampSerializer
|
||||||
|
def value
|
||||||
|
{ primary: object.primary_value, secondary: object.secondary_value }
|
||||||
|
end
|
||||||
|
end
|
|
@ -50,6 +50,8 @@
|
||||||
= render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: champ, user_can_upload: true }
|
= render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: champ, user_can_upload: true }
|
||||||
- elsif champ.type_champ == 'textarea'
|
- elsif champ.type_champ == 'textarea'
|
||||||
= simple_format(champ.decorate.value)
|
= simple_format(champ.decorate.value)
|
||||||
|
- elsif champ.type_champ == 'linked_drop_down_list'
|
||||||
|
= champ.for_display
|
||||||
- else
|
- else
|
||||||
= sanitize(champ.decorate.value)
|
= sanitize(champ.decorate.value)
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
- c.value.split(", ").each do |item|
|
- c.value.split(", ").each do |item|
|
||||||
%li
|
%li
|
||||||
= item
|
= item
|
||||||
|
- when "linked_drop_down_list"
|
||||||
|
%th.libelle
|
||||||
|
= "#{c.libelle} :"
|
||||||
|
%td= c.for_display
|
||||||
- when "dossier_link"
|
- when "dossier_link"
|
||||||
%th.libelle
|
%th.libelle
|
||||||
= "#{c.libelle} :"
|
= "#{c.libelle} :"
|
||||||
|
|
|
@ -15,4 +15,87 @@ describe Champs::LinkedDropDownListChamp do
|
||||||
|
|
||||||
it { expect(champ.value).to eq('["tata","tutu"]') }
|
it { expect(champ.value).to eq('["tata","tutu"]') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#for_display' do
|
||||||
|
let(:champ) { described_class.new(primary_value: primary_value, secondary_value: secondary_value) }
|
||||||
|
let(:primary_value) { nil }
|
||||||
|
let(:secondary_value) { nil }
|
||||||
|
|
||||||
|
subject { champ.for_display }
|
||||||
|
|
||||||
|
context 'with no value' do
|
||||||
|
it { is_expected.to eq('') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with primary value' do
|
||||||
|
let(:primary_value) { 'primary' }
|
||||||
|
|
||||||
|
it { is_expected.to eq('primary') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with secondary value' do
|
||||||
|
let(:primary_value) { 'primary' }
|
||||||
|
let(:secondary_value) { 'secondary' }
|
||||||
|
|
||||||
|
it { is_expected.to eq('primary / secondary') }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'for_export' do
|
||||||
|
subject { champ.for_export }
|
||||||
|
|
||||||
|
context 'with no value' do
|
||||||
|
let(:champ) { described_class.new }
|
||||||
|
|
||||||
|
it { is_expected.to be_nil }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with primary value' do
|
||||||
|
let(:champ) { described_class.new(primary_value: 'primary') }
|
||||||
|
|
||||||
|
it { is_expected.to eq('primary;') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with secondary value' do
|
||||||
|
let(:champ) { described_class.new(primary_value: 'primary', secondary_value: 'secondary') }
|
||||||
|
|
||||||
|
it { is_expected.to eq('primary;secondary') }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#mandatory_and_blank' do
|
||||||
|
let(:drop_down_list) { build(:drop_down_list, 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) }
|
||||||
|
|
||||||
|
it 'blank is fine' do
|
||||||
|
is_expected.not_to be_mandatory_and_blank
|
||||||
|
end
|
||||||
|
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) }
|
||||||
|
|
||||||
|
context 'when there is no value' do
|
||||||
|
it { is_expected.to be_mandatory_and_blank }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when there is a primary value' do
|
||||||
|
before { subject.primary_value = 'Primary' }
|
||||||
|
|
||||||
|
context 'when there is no secondary value' do
|
||||||
|
it { is_expected.to be_mandatory_and_blank }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when there is a secondary value' do
|
||||||
|
before { subject.secondary_value = 'Primary' }
|
||||||
|
|
||||||
|
it { is_expected.not_to be_mandatory_and_blank }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue