Update carto tests

This commit is contained in:
Paul Chavard 2018-10-10 20:02:17 +02:00
parent 2bab056613
commit 38091963c1
3 changed files with 19 additions and 21 deletions

View file

@ -64,7 +64,7 @@ shared_examples 'carte_controller_spec' do
let(:json_latlngs) { multipolygon.to_json } let(:json_latlngs) { multipolygon.to_json }
before do 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 dossier.reload
end end
@ -101,7 +101,7 @@ shared_examples 'carte_controller_spec' do
context 'En train de modifier la localisation' do context 'En train de modifier la localisation' do
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:en_construction)) } let(:dossier) { create(:dossier, state: Dossier.states.fetch(:en_construction)) }
before do before do
post :save, params: { dossier_id: dossier.id, json_latlngs: '' } post :save, params: { dossier_id: dossier.id, selection: '' }
end end
it 'Redirection vers le formulaire de la procedure' do it 'Redirection vers le formulaire de la procedure' do
@ -117,7 +117,7 @@ shared_examples 'carte_controller_spec' do
.to receive(:to_params) .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]]]] } } }) .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 end
context 'when json_latlngs params is empty' do context 'when json_latlngs params is empty' do
@ -164,7 +164,7 @@ shared_examples 'carte_controller_spec' do
.to receive(:to_params) .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]]]] } }]) .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 end
context 'when json_latlngs params is empty' do context 'when json_latlngs params is empty' do
@ -210,35 +210,33 @@ shared_examples 'carte_controller_spec' do
end end
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 before do
allow_any_instance_of(CARTO::SGMAP::QuartiersPrioritaires::Adapter) allow_any_instance_of(CARTO::SGMAP::QuartiersPrioritaires::Adapter)
.to receive(:to_params) .to receive(:to_params)
.and_return({ "QPCODE1234" => { :code => "QPCODE1234", :geometry => { :type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } } }) .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 end
context 'when coordinates are empty' do context 'when coordinates are empty' do
let(:coordinates) { '[]' } let(:json_latlngs) { [] }
subject { JSON.parse(response.body) }
it 'Quartier Prioritaire Adapter does not call' do it 'Quartier Prioritaire Adapter does not call' do
expect(subject['quartier_prioritaires']).to eq({}) expect(response.body).to include("DS.cartoDrawZones({\"quartiersPrioritaires\":[]});")
end end
end end
context 'when coordinates are informed' do 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(response.body).not_to be_nil }
it { expect(subject).not_to be_nil } it { expect(response.body).to include('QPCODE1234') }
it { expect(subject['QPCODE1234']['code']).to eq('QPCODE1234') } it { expect(response.body).to include('MultiPolygon') }
it { expect(subject['QPCODE1234']['geometry']['type']).to eq('MultiPolygon') } it { expect(response.body).to include('[2.38715792094576,48.8723062632126]') }
it { expect(subject['QPCODE1234']['geometry']['coordinates']).to eq([[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]]) }
end end
end end
end end

View file

@ -6,14 +6,14 @@ describe 'shared/dossiers/map.html.haml', type: :view do
end end
describe "javascript variables printing" do 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 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}]]" } 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 } 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 end
context 'without a correct json' do context 'without a correct json' do
@ -21,7 +21,7 @@ describe 'shared/dossiers/map.html.haml', type: :view do
before { subject } before { subject }
it { expect(rendered).to have_content('dossierJsonLatLngs: {},') } it { expect(rendered).to have_content('selection: {},') }
end end
end end
end end

View file

@ -23,7 +23,7 @@ describe 'users/carte/show.html.haml', type: :view do
context 'présence des inputs hidden' do context 'présence des inputs hidden' do
it 'stockage du json des polygons dessinés' 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
end end