Expose selection utilisateur size on champ carte

This commit is contained in:
Paul Chavard 2018-12-03 12:49:03 +01:00
parent 6043e59937
commit e873b6a9c4
3 changed files with 45 additions and 3 deletions

View file

@ -62,6 +62,14 @@ class Champs::CarteChamp < Champ
end
end
def selection_utilisateur_size
if geo_json.present?
geo_json['coordinates'].size
else
0
end
end
def to_render_data
{
position: position,

View file

@ -6,7 +6,7 @@
- elsif champ.value.blank?
Aucune zone tracée
- elsif champ.quartiers_prioritaires.blank?
= t('errors.messages.quartiers_prioritaires_empty', count: champ.geo_json.size)
= t('errors.messages.quartiers_prioritaires_empty', count: champ.selection_utilisateur_size)
- else
%ul
- champ.quartiers_prioritaires.each do |qp|
@ -20,7 +20,7 @@
- elsif champ.value.blank?
Aucune zone tracée
- elsif champ.cadastres.blank?
= t('errors.messages.cadastres_empty', count: champ.geo_json.size)
= t('errors.messages.cadastres_empty', count: champ.selection_utilisateur_size)
- else
%ul
- champ.cadastres.each do |pc|
@ -34,7 +34,7 @@
- elsif champ.value.blank?
Aucune zone tracée
- elsif champ.parcelles_agricoles.blank?
= t('errors.messages.parcelles_agricoles_empty', count: champ.geo_json.size)
= t('errors.messages.parcelles_agricoles_empty', count: champ.selection_utilisateur_size)
- else
%ul
- champ.parcelles_agricoles.each do |pa|

View file

@ -60,4 +60,38 @@ describe Champs::CarteChamp do
it { is_expected.to eq(render_data) }
end
end
describe '#selection_utilisateur_size' do
subject { champ.selection_utilisateur_size }
context 'when the value is nil' do
let(:value) { nil }
it { is_expected.to eq(0) }
end
context 'when the value is blank' do
let(:value) { '' }
it { is_expected.to eq(0) }
end
context 'when the value is empty array' do
let(:value) { '[]' }
it { is_expected.to eq(0) }
end
context 'when the value is coordinates' do
let(:value) { coordinates.to_json }
it { is_expected.to eq(1) }
end
context 'when the value is geojson' do
let(:value) { geo_json }
it { is_expected.to eq(1) }
end
end
end