2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2018-11-30 13:19:19 +01:00
|
|
|
|
describe Champs::CarteChamp do
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:champ) { Champs::CarteChamp.new(geo_areas:) }
|
|
|
|
|
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_carte)) }
|
2018-11-30 13:19:19 +01:00
|
|
|
|
let(:value) { '' }
|
2023-02-14 18:38:01 +01:00
|
|
|
|
let(:coordinates) { [[[2.3859214782714844, 48.87442541960633], [2.3850631713867183, 48.87273183590832], [2.3809432983398438, 48.87081237174292], [2.3859214782714844, 48.87442541960633]]] }
|
2020-04-09 17:32:20 +02:00
|
|
|
|
let(:geo_json) do
|
|
|
|
|
{
|
|
|
|
|
"type" => 'Polygon',
|
|
|
|
|
"coordinates" => coordinates
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
let(:legacy_geo_json) do
|
|
|
|
|
{
|
|
|
|
|
type: 'MultiPolygon',
|
|
|
|
|
coordinates: [coordinates]
|
|
|
|
|
}
|
|
|
|
|
end
|
2018-11-30 13:19:19 +01:00
|
|
|
|
|
2020-04-09 17:32:20 +02:00
|
|
|
|
describe '#to_feature_collection' do
|
|
|
|
|
subject { champ.to_feature_collection }
|
2018-12-03 12:49:03 +01:00
|
|
|
|
|
2020-04-09 17:32:20 +02:00
|
|
|
|
let(:feature_collection) {
|
|
|
|
|
{
|
|
|
|
|
type: 'FeatureCollection',
|
2024-04-02 15:11:09 +02:00
|
|
|
|
id: champ.stable_id,
|
2020-04-09 17:32:20 +02:00
|
|
|
|
bbox: champ.bounding_box,
|
|
|
|
|
features: features
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-03 12:49:03 +01:00
|
|
|
|
|
2020-04-09 17:32:20 +02:00
|
|
|
|
context 'when has no geo_areas' do
|
|
|
|
|
let(:geo_areas) { [] }
|
|
|
|
|
let(:features) { [] }
|
2018-12-03 12:49:03 +01:00
|
|
|
|
|
2020-04-09 17:32:20 +02:00
|
|
|
|
it { is_expected.to eq(feature_collection) }
|
2018-12-03 12:49:03 +01:00
|
|
|
|
end
|
|
|
|
|
|
2020-04-09 17:32:20 +02:00
|
|
|
|
context 'when has one geo_area' do
|
|
|
|
|
let(:geo_areas) { [build(:geo_area, :selection_utilisateur, geometry: geo_json)] }
|
|
|
|
|
let(:features) { geo_areas.map(&:to_feature) }
|
2018-12-03 12:49:03 +01:00
|
|
|
|
|
2020-04-09 17:32:20 +02:00
|
|
|
|
it { is_expected.to eq(feature_collection) }
|
2018-12-03 12:49:03 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2022-08-31 13:09:00 +02:00
|
|
|
|
|
|
|
|
|
describe "#for_export" do
|
|
|
|
|
context "when geo areas is a point" do
|
|
|
|
|
let(:geo_areas) { [build(:geo_area, :selection_utilisateur, :point)] }
|
|
|
|
|
|
|
|
|
|
it "returns point label" do
|
2024-10-21 11:51:34 +02:00
|
|
|
|
expect(champ.type_de_champ.champ_value_for_export(champ)).to eq("Un point situé à 46°32'19\"N 2°25'42\"E")
|
2022-08-31 13:09:00 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when geo area is a cadastre parcelle" do
|
|
|
|
|
let(:geo_areas) { [build(:geo_area, :selection_utilisateur, :cadastre)] }
|
|
|
|
|
|
|
|
|
|
it "returns cadastre parcelle label" do
|
2024-10-21 11:51:34 +02:00
|
|
|
|
expect(champ.type_de_champ.champ_value_for_export(champ)).to match(/Parcelle n° 42/)
|
2022-08-31 13:09:00 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-11-30 13:19:19 +01:00
|
|
|
|
end
|