From c4d790b4d04c838ad073fcde5f15d57b6179ae8c Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Mon, 22 Oct 2018 15:00:52 +0200 Subject: [PATCH] Test champs carte controller --- .../champs/carte_controller_spec.rb | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 spec/controllers/champs/carte_controller_spec.rb diff --git a/spec/controllers/champs/carte_controller_spec.rb b/spec/controllers/champs/carte_controller_spec.rb new file mode 100644 index 000000000..fadf1fa1a --- /dev/null +++ b/spec/controllers/champs/carte_controller_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +describe Champs::CarteController, type: :controller do + let(:user) { create(:user) } + let(:procedure) { create(:procedure, :published) } + let(:dossier) { create(:dossier, user: user, procedure: procedure) } + let(:params) do + { + dossier: { + champs_attributes: { + '1' => { value: selection.to_json } + } + }, + position: '1', + champ_id: champ.id + } + end + let(:champ) do + create(:type_de_champ_carte, options: { + quartiers_prioritaires: true + }).champ.create(dossier: dossier) + end + + describe 'POST #show' do + render_views + + before { sign_in user } + before do + allow_any_instance_of(ApiCarto::QuartiersPrioritairesAdapter) + .to receive(:results) + .and_return([{ code: "QPCODE1234", geometry: { type: "MultiPolygon", coordinates: [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } }]) + + post :show, params: params, format: 'js' + end + + context 'when coordinates are empty' do + let(:selection) { [] } + + it { expect(response.body).to include("DS.drawMapData(\".carte-1\", {\"position\":{\"lon\":\"2.428462\",\"lat\":\"46.538192\",\"zoom\":\"13\"},\"selection\":[],\"quartiersPrioritaires\":[],\"cadastres\":[]});") } + end + + context 'when coordinates are informed' do + let(:selection) { [[{ "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 }]] } + + 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