More tests and fixes on carte champ
This commit is contained in:
parent
e25f84209a
commit
d77a5c9f15
7 changed files with 172 additions and 44 deletions
|
@ -41,7 +41,7 @@ describe Champs::CarteController, type: :controller do
|
|||
expect(assigns(:error)).to eq(nil)
|
||||
expect(champ.reload.value).to eq(nil)
|
||||
expect(champ.reload.geo_areas).to eq([])
|
||||
expect(response.body).to include("DS.drawMapData(\".carte-1\", {\"position\":{\"lon\":\"2.428462\",\"lat\":\"46.538192\",\"zoom\":\"13\"},\"selection\":[],\"quartiersPrioritaires\":[],\"cadastres\":[],\"parcellesAgricoles\":[]});")
|
||||
expect(response.body).to include("DS.drawMapData(\".carte-1\", {\"position\":{\"lon\":\"2.428462\",\"lat\":\"46.538192\",\"zoom\":\"13\"},\"selection\":null,\"quartiersPrioritaires\":[],\"cadastres\":[],\"parcellesAgricoles\":[]});")
|
||||
}
|
||||
end
|
||||
|
||||
|
|
63
spec/models/champs/carte_champ_spec.rb
Normal file
63
spec/models/champs/carte_champ_spec.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Champs::CarteChamp do
|
||||
let(:champ) { Champs::CarteChamp.new(value: value) }
|
||||
let(:value) { '' }
|
||||
let(:geo_json) { GeojsonService.to_json_polygon_for_selection_utilisateur(coordinates) }
|
||||
let(:coordinates) { [[{ "lat" => 48.87442541960633, "lng" => 2.3859214782714844 }, { "lat" => 48.87273183590832, "lng" => 2.3850631713867183 }, { "lat" => 48.87081237174292, "lng" => 2.3809432983398438 }, { "lat" => 48.8712640169951, "lng" => 2.377510070800781 }, { "lat" => 48.87510283703279, "lng" => 2.3778533935546875 }, { "lat" => 48.87544154230615, "lng" => 2.382831573486328 }, { "lat" => 48.87442541960633, "lng" => 2.3859214782714844 }]] }
|
||||
let(:parsed_geo_json) { JSON.parse(geo_json) }
|
||||
|
||||
describe '#to_render_data' do
|
||||
subject { champ.to_render_data }
|
||||
|
||||
let(:render_data) {
|
||||
{
|
||||
position: champ.position,
|
||||
selection: selection,
|
||||
cadastres: [],
|
||||
parcellesAgricoles: [],
|
||||
quartiersPrioritaires: []
|
||||
}
|
||||
}
|
||||
|
||||
context 'when the value is nil' do
|
||||
let(:value) { nil }
|
||||
|
||||
let(:selection) { nil }
|
||||
|
||||
it { is_expected.to eq(render_data) }
|
||||
end
|
||||
|
||||
context 'when the value is blank' do
|
||||
let(:value) { '' }
|
||||
|
||||
let(:selection) { nil }
|
||||
|
||||
it { is_expected.to eq(render_data) }
|
||||
end
|
||||
|
||||
context 'when the value is empty array' do
|
||||
let(:value) { '[]' }
|
||||
|
||||
let(:selection) { nil }
|
||||
|
||||
it { is_expected.to eq(render_data) }
|
||||
end
|
||||
|
||||
context 'when the value is coordinates' do
|
||||
let(:value) { coordinates.to_json }
|
||||
|
||||
let(:selection) { parsed_geo_json }
|
||||
|
||||
it { is_expected.to eq(render_data) }
|
||||
end
|
||||
|
||||
context 'when the value is geojson' do
|
||||
let(:value) { geo_json }
|
||||
|
||||
let(:selection) { parsed_geo_json }
|
||||
|
||||
it { is_expected.to eq(render_data) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -30,23 +30,45 @@ describe ChampSerializer do
|
|||
|
||||
let(:serialized_champ) {
|
||||
{
|
||||
type_de_champ: {
|
||||
description: serialized_description,
|
||||
id: serialized_id,
|
||||
libelle: serialized_libelle,
|
||||
order_place: serialized_order_place,
|
||||
type_champ: serialized_type_champ
|
||||
},
|
||||
geo_areas: serialized_geo_areas,
|
||||
value: geo_json
|
||||
}.compact
|
||||
type_de_champ: serialized_type_de_champ,
|
||||
value: serialized_value
|
||||
}
|
||||
}
|
||||
let(:serialized_type_de_champ) {
|
||||
{
|
||||
description: serialized_description,
|
||||
id: serialized_id,
|
||||
libelle: serialized_libelle,
|
||||
order_place: serialized_order_place,
|
||||
type_champ: serialized_type_champ
|
||||
}
|
||||
}
|
||||
let(:serialized_id) { -1 }
|
||||
let(:serialized_description) { "" }
|
||||
let(:serialized_order_place) { -1 }
|
||||
let(:serialized_geo_areas) { nil }
|
||||
let(:serialized_value) { geo_json }
|
||||
|
||||
context 'and geo_area is selection_utilisateur' do
|
||||
context 'value is empty' do
|
||||
context 'when value is nil' do
|
||||
let(:value) { nil }
|
||||
|
||||
it { expect(champ.user_geo_area).to be_nil }
|
||||
end
|
||||
|
||||
context 'when value is empty array' do
|
||||
let(:value) { '[]' }
|
||||
|
||||
it { expect(champ.user_geo_area).to be_nil }
|
||||
end
|
||||
|
||||
context 'when value is blank' do
|
||||
let(:value) { '' }
|
||||
|
||||
it { expect(champ.user_geo_area).to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
context 'old_api' do
|
||||
let(:serialized_libelle) { "user geometry" }
|
||||
let(:serialized_type_champ) { "user_geometry" }
|
||||
|
@ -68,7 +90,13 @@ describe ChampSerializer do
|
|||
|
||||
context 'new_api' do
|
||||
let(:geo_area) { nil }
|
||||
let(:serialized_geo_areas) { [] }
|
||||
let(:serialized_champ) {
|
||||
{
|
||||
type_de_champ: serialized_type_de_champ,
|
||||
geo_areas: [],
|
||||
value: serialized_value
|
||||
}
|
||||
}
|
||||
let(:serialized_id) { champ.type_de_champ.stable_id }
|
||||
let(:serialized_description) { champ.description }
|
||||
let(:serialized_order_place) { champ.order_place }
|
||||
|
@ -86,6 +114,27 @@ describe ChampSerializer do
|
|||
|
||||
it { expect(subject).to eq(serialized_champ) }
|
||||
end
|
||||
|
||||
context 'when value is nil' do
|
||||
let(:value) { nil }
|
||||
let(:serialized_value) { nil }
|
||||
|
||||
it { expect(subject).to eq(serialized_champ) }
|
||||
end
|
||||
|
||||
context 'when value is empty array' do
|
||||
let(:value) { '[]' }
|
||||
let(:serialized_value) { nil }
|
||||
|
||||
it { expect(subject).to eq(serialized_champ) }
|
||||
end
|
||||
|
||||
context 'when value is blank' do
|
||||
let(:value) { '' }
|
||||
let(:serialized_value) { nil }
|
||||
|
||||
it { expect(subject).to eq(serialized_champ) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue