From 38091963c1a45f3590c68cc3934751e83435fd40 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 10 Oct 2018 20:02:17 +0200 Subject: [PATCH] Update carto tests --- .../users/carte_controller_shared_example.rb | 32 +++++++++---------- spec/views/shared/dossiers/_map_spec.rb | 6 ++-- spec/views/users/carte/show.html.haml_spec.rb | 2 +- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/spec/controllers/users/carte_controller_shared_example.rb b/spec/controllers/users/carte_controller_shared_example.rb index 0a0f9495b..3446d6826 100644 --- a/spec/controllers/users/carte_controller_shared_example.rb +++ b/spec/controllers/users/carte_controller_shared_example.rb @@ -64,7 +64,7 @@ shared_examples 'carte_controller_spec' do let(:json_latlngs) { multipolygon.to_json } before do - post :save, params: { dossier_id: dossier.id, json_latlngs: json_latlngs } + post :save, params: { dossier_id: dossier.id, selection: json_latlngs } dossier.reload end @@ -101,7 +101,7 @@ shared_examples 'carte_controller_spec' do context 'En train de modifier la localisation' do let(:dossier) { create(:dossier, state: Dossier.states.fetch(:en_construction)) } before do - post :save, params: { dossier_id: dossier.id, json_latlngs: '' } + post :save, params: { dossier_id: dossier.id, selection: '' } end it 'Redirection vers le formulaire de la procedure' do @@ -117,7 +117,7 @@ shared_examples 'carte_controller_spec' do .to receive(:to_params) .and_return({ "QPCODE1234" => { :code => "QPCODE1234", :nom => "QP de test", :commune => "Paris", :geometry => { :type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } } }) - post :save, params: { dossier_id: dossier.id, json_latlngs: json_latlngs } + post :save, params: { dossier_id: dossier.id, selection: json_latlngs } end context 'when json_latlngs params is empty' do @@ -164,7 +164,7 @@ shared_examples 'carte_controller_spec' do .to receive(:to_params) .and_return([{ :surface_intersection => "0.0006", :surface_parcelle => 11252.692583090324, :numero => "0013", :feuille => 1, :section => "CD", :code_dep => "30", :nom_com => "Le Grau-du-Roi", :code_com => "133", :code_arr => "000", :geometry => { :type => "MultiPolygon", :coordinates => [[[[4.134084, 43.5209193], [4.1346615, 43.5212035], [4.1346984, 43.521189], [4.135096, 43.5213848], [4.1350839, 43.5214122], [4.1352697, 43.521505], [4.1356278, 43.5211065], [4.1357402, 43.5207188], [4.1350935, 43.5203936], [4.135002, 43.5204366], [4.1346051, 43.5202412], [4.134584, 43.5202472], [4.1345572, 43.5202551], [4.134356, 43.5203137], [4.1342488, 43.5203448], [4.134084, 43.5209193]]]] } }]) - post :save, params: { dossier_id: dossier.id, json_latlngs: json_latlngs } + post :save, params: { dossier_id: dossier.id, selection: json_latlngs } end context 'when json_latlngs params is empty' do @@ -210,35 +210,33 @@ shared_examples 'carte_controller_spec' do end end + describe 'POST #zones' do + let(:module_api_carto) { create(:module_api_carto, :with_quartiers_prioritaires) } + render_views - - describe 'POST #get_qp' do before do allow_any_instance_of(CARTO::SGMAP::QuartiersPrioritaires::Adapter) .to receive(:to_params) .and_return({ "QPCODE1234" => { :code => "QPCODE1234", :geometry => { :type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } } }) - post :get_qp, params: { dossier_id: dossier.id, coordinates: coordinates } + post :zones, params: { dossier_id: dossier.id, selection: json_latlngs.to_json }, format: 'js' end context 'when coordinates are empty' do - let(:coordinates) { '[]' } - - subject { JSON.parse(response.body) } + let(:json_latlngs) { [] } it 'Quartier Prioritaire Adapter does not call' do - expect(subject['quartier_prioritaires']).to eq({}) + expect(response.body).to include("DS.cartoDrawZones({\"quartiersPrioritaires\":[]});") end end context 'when coordinates are informed' do - 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(:json_latlngs) { [[{ "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 }]] } - subject { JSON.parse(response.body)['quartier_prioritaires'] } - it { expect(subject).not_to be_nil } - it { expect(subject['QPCODE1234']['code']).to eq('QPCODE1234') } - it { expect(subject['QPCODE1234']['geometry']['type']).to eq('MultiPolygon') } - it { expect(subject['QPCODE1234']['geometry']['coordinates']).to eq([[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]]) } + it { expect(response.body).not_to be_nil } + it { expect(response.body).to include('QPCODE1234') } + it { expect(response.body).to include('MultiPolygon') } + it { expect(response.body).to include('[2.38715792094576,48.8723062632126]') } end end end diff --git a/spec/views/shared/dossiers/_map_spec.rb b/spec/views/shared/dossiers/_map_spec.rb index 9e3d05c48..250a1fb8d 100644 --- a/spec/views/shared/dossiers/_map_spec.rb +++ b/spec/views/shared/dossiers/_map_spec.rb @@ -6,14 +6,14 @@ describe 'shared/dossiers/map.html.haml', type: :view do end describe "javascript variables printing" do - let(:dossier) { create(:dossier, :with_entreprise, json_latlngs: json_latlngs) } + let(:dossier) { create(:dossier, json_latlngs: json_latlngs) } context 'with a correct json' do let(:json_latlngs) { "[[{\"lat\":50.659255436656736,\"lng\":3.080635070800781},{\"lat\":50.659255436656736,\"lng\":3.079690933227539},{\"lat\":50.659962770886516,\"lng\":3.0800342559814453},{\"lat\":50.659962770886516,\"lng\":3.0811500549316406},{\"lat\":50.659255436656736,\"lng\":3.080635070800781}]]" } before { subject } - it { expect(rendered).to have_content('dossierJsonLatLngs: [[{"lat":50.659255436656736,"lng":3.080635070800781},{"lat":50.659255436656736,"lng":3.079690933227539},{"lat":50.659962770886516,"lng":3.0800342559814453},{"lat":50.659962770886516,"lng":3.0811500549316406},{"lat":50.659255436656736,"lng":3.080635070800781}]],') } + it { expect(rendered).to have_content('selection: [[{"lat":50.659255436656736,"lng":3.080635070800781},{"lat":50.659255436656736,"lng":3.079690933227539},{"lat":50.659962770886516,"lng":3.0800342559814453},{"lat":50.659962770886516,"lng":3.0811500549316406},{"lat":50.659255436656736,"lng":3.080635070800781}]],') } end context 'without a correct json' do @@ -21,7 +21,7 @@ describe 'shared/dossiers/map.html.haml', type: :view do before { subject } - it { expect(rendered).to have_content('dossierJsonLatLngs: {},') } + it { expect(rendered).to have_content('selection: {},') } end end end diff --git a/spec/views/users/carte/show.html.haml_spec.rb b/spec/views/users/carte/show.html.haml_spec.rb index d30f8c13c..6aa85457f 100644 --- a/spec/views/users/carte/show.html.haml_spec.rb +++ b/spec/views/users/carte/show.html.haml_spec.rb @@ -23,7 +23,7 @@ describe 'users/carte/show.html.haml', type: :view do context 'présence des inputs hidden' do it 'stockage du json des polygons dessinés' do - expect(rendered).to have_selector('input[type=hidden][id=json_latlngs][name=json_latlngs]', visible: false) + expect(rendered).to have_selector('input[type=hidden][name=selection]', visible: false) end end