From 6aa7808e5741e5bf9efee512f0fafaa3a5f4acfe Mon Sep 17 00:00:00 2001 From: Joonas Date: Tue, 26 Nov 2024 15:31:58 +0200 Subject: [PATCH] Fix specs / Fix lint --- Gemfile | 7 ++- Gemfile.lock | 16 ++---- app/cells/decidim/locations/map_cell.rb | 2 +- .../decidim/locations/locations_command.rb | 2 +- .../decidim/locations/locatable_form.rb | 2 +- app/forms/decidim/locations/location_form.rb | 2 +- app/packs/src/decidim/map/provider/default.js | 15 ++++++ config/assets.rb | 1 - .../cells/decidim/locations/form_cell_spec.rb | 4 +- .../decidim/locations/locations_cell_spec.rb | 14 ++--- spec/cells/decidim/locations/map_cell_spec.rb | 6 +-- .../locations/locations_command_spec.rb | 4 +- .../locations/locations_helper_spec.rb | 24 ++++----- spec/shared/map_cell_render_examples.rb | 2 +- spec/shared/reverse_geocoding_examples.rb | 24 ++++----- spec/shared/type_locations_examples.rb | 44 ++++++++-------- spec/system/map_spec.rb | 52 ++++--------------- spec/types/component_type_spec.rb | 12 ++--- 18 files changed, 107 insertions(+), 126 deletions(-) create mode 100644 app/packs/src/decidim/map/provider/default.js diff --git a/Gemfile b/Gemfile index 34feaa3..6332eb6 100644 --- a/Gemfile +++ b/Gemfile @@ -23,8 +23,13 @@ gem "uglifier", "~> 4.1" group :development, :test do gem "byebug", "~> 11.0", platform: :mri gem "decidim-dev", DECIDIM_VERSION + + # rubocop & rubocop-rspec are set to the following versions because of a change where FactoryBot/CreateList + # must be a boolean instead of contextual. These version locks can be removed when this problem is handled + # through decidim-dev. + gem "rubocop", "~>1.28" gem "rubocop-faker" - gem "rubocop-performance", "~> 1.15.0" # ? + gem "rubocop-rspec", "2.20" end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index ae17e2c..84e9de8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -665,26 +665,17 @@ GEM parser (>= 3.3.1.0) rubocop-capybara (2.21.0) rubocop (~> 1.41) - rubocop-factory_bot (2.26.0) - rubocop (~> 1.41) rubocop-faker (1.2.0) faker (>= 2.12.0) rubocop (>= 1.13.0) - rubocop-performance (1.15.2) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) rubocop-rails (2.25.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rspec (2.31.0) - rubocop (~> 1.40) + rubocop-rspec (2.20.0) + rubocop (~> 1.33) rubocop-capybara (~> 2.17) - rubocop-factory_bot (~> 2.22) - rubocop-rspec_rails (~> 2.28) - rubocop-rspec_rails (2.29.0) - rubocop (~> 1.40) ruby-progressbar (1.13.0) ruby-vips (2.2.2) ffi (~> 1.12) @@ -804,8 +795,9 @@ DEPENDENCIES listen (~> 3.1) puma (>= 6.4.2) rgeo-geojson (~> 2.1, >= 2.1.1) + rubocop (~> 1.28) rubocop-faker - rubocop-performance (~> 1.15.0) + rubocop-rspec (= 2.20) spring (~> 2.0) spring-watcher-listen (~> 2.0) uglifier (~> 4.1) diff --git a/app/cells/decidim/locations/map_cell.rb b/app/cells/decidim/locations/map_cell.rb index bbfe45f..8de0754 100644 --- a/app/cells/decidim/locations/map_cell.rb +++ b/app/cells/decidim/locations/map_cell.rb @@ -100,7 +100,7 @@ def markers_data_for_map { id: data[0], title: data[1], - body: body, + body:, address: data[4], latitude: data[5], longitude: data[6], diff --git a/app/commands/concerns/decidim/locations/locations_command.rb b/app/commands/concerns/decidim/locations/locations_command.rb index d8d36ff..301d12c 100644 --- a/app/commands/concerns/decidim/locations/locations_command.rb +++ b/app/commands/concerns/decidim/locations/locations_command.rb @@ -41,7 +41,7 @@ def update_locations(locatable, form) Decidim::Locations::Location.new(attributes) end end.compact - locatable.update!(locations: locations) + locatable.update!(locations:) end end end diff --git a/app/forms/concerns/decidim/locations/locatable_form.rb b/app/forms/concerns/decidim/locations/locatable_form.rb index 31d0bd8..7a75c0d 100644 --- a/app/forms/concerns/decidim/locations/locatable_form.rb +++ b/app/forms/concerns/decidim/locations/locatable_form.rb @@ -40,7 +40,7 @@ def validate_locations return end - record = self.class.locations_record_class.find_by(id: id) + record = self.class.locations_record_class.find_by(id:) return unless record unexisting_ids = provided_ids.map(&:to_i) - record.locations.pluck(:id) diff --git a/app/forms/decidim/locations/location_form.rb b/app/forms/decidim/locations/location_form.rb index 83d00c9..cb68108 100644 --- a/app/forms/decidim/locations/location_form.rb +++ b/app/forms/decidim/locations/location_form.rb @@ -49,7 +49,7 @@ def json_validation # check if GeoJSON is valid begin geo_factory = RGeo::Geographic.spherical_factory - RGeo::GeoJSON.decode(geojson, geo_factory: geo_factory) + RGeo::GeoJSON.decode(geojson, geo_factory:) coord_validation rescue JSON::ParserError diff --git a/app/packs/src/decidim/map/provider/default.js b/app/packs/src/decidim/map/provider/default.js new file mode 100644 index 0000000..5aa34a1 --- /dev/null +++ b/app/packs/src/decidim/map/provider/default.js @@ -0,0 +1,15 @@ +import "leaflet" +import "src/decidim/geoman/leaflet-geoman.min.js"; + +/** + * NOTE: + * This has to load before decidim/map in order for it to apply correctly when + * the map is initialized. The document.ready handler set by this script has to + * be registered before decidim/map registers its own. + */ +$(() => { + $("[data-decidim-map]").on("configure.decidim", (_ev, map, mapConfig) => { + const tilesConfig = mapConfig.tileLayer; + L.tileLayer(tilesConfig.url, tilesConfig.options).addTo(map); + }); +}); diff --git a/config/assets.rb b/config/assets.rb index f2e82b6..f80b308 100644 --- a/config/assets.rb +++ b/config/assets.rb @@ -13,4 +13,3 @@ Decidim::Webpacker.register_stylesheet_import("src/decidim/geoman/leaflet-geoman") Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/locations/locations", group: :admin) Decidim::Webpacker.register_stylesheet_import("src/decidim/geoman/leaflet-geoman", group: :admin) - diff --git a/spec/cells/decidim/locations/form_cell_spec.rb b/spec/cells/decidim/locations/form_cell_spec.rb index d9d787e..1ee1f6f 100644 --- a/spec/cells/decidim/locations/form_cell_spec.rb +++ b/spec/cells/decidim/locations/form_cell_spec.rb @@ -7,10 +7,10 @@ let(:my_cell) { cell("decidim/locations/form", form_builder) } let!(:organization) { create(:organization) } - let(:user) { create(:user, :confirmed, organization: organization) } + let(:user) { create(:user, :confirmed, organization:) } let(:template_class) do Class.new(ActionView::Base) do - include ::Cell::RailsExtensions::ActionView + include Cell::RailsExtensions::ActionView delegate :snippets, to: :controller diff --git a/spec/cells/decidim/locations/locations_cell_spec.rb b/spec/cells/decidim/locations/locations_cell_spec.rb index 5b91503..d6ad915 100644 --- a/spec/cells/decidim/locations/locations_cell_spec.rb +++ b/spec/cells/decidim/locations/locations_cell_spec.rb @@ -5,14 +5,14 @@ describe Decidim::Locations::LocationsCell, type: :cell do subject { my_cell.call } - let(:my_cell) { cell("decidim/locations/locations", dummy, form: form, map_configuration: "single", coords: [1, 2]) } + let(:my_cell) { cell("decidim/locations/locations", dummy, form:, map_configuration: "single", coords: [1, 2]) } let(:dummy_form) { Decidim::Dev::DummyResourceForm.from_model(dummy) } let(:form) { Decidim::FormBuilder.new("dummy", dummy_form, template, {}) } let!(:organization) { create(:organization) } - let(:user) { create(:user, :confirmed, organization: organization) } + let(:user) { create(:user, :confirmed, organization:) } let(:template_class) do Class.new(ActionView::Base) do - include ::Cell::RailsExtensions::ActionView + include Cell::RailsExtensions::ActionView delegate :snippets, :current_organization, to: :controller end @@ -30,8 +30,8 @@ context "when cell called" do before do - utility = Decidim::Map.autocomplete(organization: organization) - allow(Decidim::Map).to receive(:autocomplete).with(organization: organization).and_return(utility) + utility = Decidim::Map.autocomplete(organization:) + allow(Decidim::Map).to receive(:autocomplete).with(organization:).and_return(utility) allow(utility).to receive(:builder_options).and_return( api_key: "key1234" ) @@ -39,8 +39,8 @@ end it "renders the view" do - expect(subject).to have_css("input[name=\"dummy[address]\"]") - expect(subject).to have_selector("#example") + expect(subject).to have_field("dummy[address]") + expect(subject).to have_css("#example") expect(subject).to have_content( <<~TXT.squish The following element is a map which presents the items on this page as map points. diff --git a/spec/cells/decidim/locations/map_cell_spec.rb b/spec/cells/decidim/locations/map_cell_spec.rb index dfb43a7..79f5cda 100644 --- a/spec/cells/decidim/locations/map_cell_spec.rb +++ b/spec/cells/decidim/locations/map_cell_spec.rb @@ -7,10 +7,10 @@ let(:my_cell) { cell("decidim/locations/map", dummy) } let!(:organization) { create(:organization) } - let(:user) { create(:user, :confirmed, organization: organization) } + let(:user) { create(:user, :confirmed, organization:) } let(:template_class) do Class.new(ActionView::Base) do - include ::Cell::RailsExtensions::ActionView + include Cell::RailsExtensions::ActionView delegate :snippets, to: :controller end @@ -34,7 +34,7 @@ The element can be used with a screen reader but it may be hard to understand. TXT ) - expect(subject).to have_css(".map__help") + expect(subject).to have_css(".map__skip") expect(subject).to have_css("[id$='_bottom']") end end diff --git a/spec/commands/decidim/locations/locations_command_spec.rb b/spec/commands/decidim/locations/locations_command_spec.rb index 2a5af8b..94cb1f2 100644 --- a/spec/commands/decidim/locations/locations_command_spec.rb +++ b/spec/commands/decidim/locations/locations_command_spec.rb @@ -6,14 +6,14 @@ module Decidim module Locations describe LocationsCommand do let!(:organization) { create(:organization) } - let(:user) { create(:user, :admin, :confirmed, organization: organization) } + let(:user) { create(:user, :admin, :confirmed, organization:) } let(:dummy) { create(:dummy_resource) } let!(:form_klass) { Decidim::Dev::DummyResourceForm } let(:form_params) do { title: "This title has to be at least 15 chars", body: "This body has to be at least 15 chars", - locations: locations + locations: } end diff --git a/spec/helpers/decidim/locations/locations_helper_spec.rb b/spec/helpers/decidim/locations/locations_helper_spec.rb index f953c74..073dd23 100644 --- a/spec/helpers/decidim/locations/locations_helper_spec.rb +++ b/spec/helpers/decidim/locations/locations_helper_spec.rb @@ -6,10 +6,10 @@ module Decidim module Locations describe LocationsHelper do let!(:organization) { create(:organization) } - let!(:dummy1) { create(:dummy_resource, body: "A reasonable body") } - let!(:dummy2) { create(:dummy_resource, body: "Another reasonable body") } - let!(:loc1) { create(:location, locatable: dummy1, address: "Speed street", latitude: 50.231241, longitude: 39.394056, shape: "Marker", geojson: { "lat" => 50.231241, "lng" => 39.394056 }) } - let!(:loc2) { create(:location, locatable: dummy2, address: "Brain boulevard", latitude: 14.284756, longitude: 43.182746, shape: "Marker", geojson: { "lat" => 14.284756, "lng" => 43.182746 }) } + let!(:dummy_one) { create(:dummy_resource, body: "A reasonable body") } + let!(:dummy_two) { create(:dummy_resource, body: "Another reasonable body") } + let!(:loc_one) { create(:location, locatable: dummy_one, address: "Speed street", latitude: 50.231241, longitude: 39.394056, shape: "Marker", geojson: { "lat" => 50.231241, "lng" => 39.394056 }) } + let!(:loc_two) { create(:location, locatable: dummy_two, address: "Brain boulevard", latitude: 14.284756, longitude: 43.182746, shape: "Marker", geojson: { "lat" => 14.284756, "lng" => 43.182746 }) } let(:helper) do Class.new(ActionView::Base) do include TranslatableAttributes @@ -18,29 +18,29 @@ module Locations end describe "#format_map_locations - single" do - subject { helper.format_map_locations(dummy1) } + subject { helper.format_map_locations(dummy_one) } it "returns an array of a single model locations" do - expect(subject).to eq([[dummy1.id, dummy1.title["en"], nil, dummy1.body, loc1.address, loc1.latitude, loc1.longitude, "Marker", { "lat" => 50.231241, "lng" => 39.394056 }]]) + expect(subject).to eq([[dummy_one.id, dummy_one.title["en"], nil, dummy_one.body, loc_one.address, loc_one.latitude, loc_one.longitude, "Marker", { "lat" => 50.231241, "lng" => 39.394056 }]]) end end describe "#format_map_locations - multiple" do - let(:dummies) { Decidim::Dev::DummyResource.where(id: [dummy1.id, dummy2.id]) } + let(:dummies) { Decidim::Dev::DummyResource.where(id: [dummy_one.id, dummy_two.id]) } subject { helper.format_map_locations(dummies) } it "returns an array of multiple model locations" do expect(subject).to include( - [dummy1.id, dummy1.title["en"], nil, dummy1.body, loc1.address, loc1.latitude, loc1.longitude, "Marker", { "lat" => 50.231241, "lng" => 39.394056 }], - [dummy2.id, dummy2.title["en"], nil, dummy2.body, loc2.address, loc2.latitude, loc2.longitude, "Marker", { "lat" => 14.284756, "lng" => 43.182746 }] + [dummy_one.id, dummy_one.title["en"], nil, dummy_one.body, loc_one.address, loc_one.latitude, loc_one.longitude, "Marker", { "lat" => 50.231241, "lng" => 39.394056 }], + [dummy_two.id, dummy_two.title["en"], nil, dummy_two.body, loc_two.address, loc_two.latitude, loc_two.longitude, "Marker", { "lat" => 14.284756, "lng" => 43.182746 }] ) end end describe "#model_has_address?" do context "when model has address" do - subject { model_has_address?(dummy1) } + subject { model_has_address?(dummy_one) } it "returns true" do expect(subject).to be(true) @@ -48,9 +48,9 @@ module Locations end context "when model has no address" do - let(:dummy3) { create(:dummy_resource) } + let(:dummy_three) { create(:dummy_resource) } - subject { model_has_address?(dummy3) } + subject { model_has_address?(dummy_three) } it "returns false" do expect(subject).to be(false) diff --git a/spec/shared/map_cell_render_examples.rb b/spec/shared/map_cell_render_examples.rb index 1110c04..73b57ca 100644 --- a/spec/shared/map_cell_render_examples.rb +++ b/spec/shared/map_cell_render_examples.rb @@ -72,7 +72,7 @@ it "renders the map with 3 shapes" do expect(page).to have_css(".leaflet-marker-icon", count: 1) - expect(page).to have_selector('img[title="Title of the marker"]') + expect(page).to have_css('img[title="Title of the marker"]') expect(page).to have_css("path.leaflet-interactive", count: 2) end diff --git a/spec/shared/reverse_geocoding_examples.rb b/spec/shared/reverse_geocoding_examples.rb index 024ddfc..705c110 100644 --- a/spec/shared/reverse_geocoding_examples.rb +++ b/spec/shared/reverse_geocoding_examples.rb @@ -170,8 +170,8 @@ add_marker expect(page).to have_css(".leaflet-marker-icon", visible: :all) find(".leaflet-marker-icon").click - click_button "Delete shape" - expect(page).not_to have_css(".leaflet-marker-icon") + click_on "Delete shape" + expect(page).to have_no_css(".leaflet-marker-icon") end end @@ -181,8 +181,8 @@ add_line expect(page).to have_css(".leaflet-interactive") find(".leaflet-interactive").click - click_button "Delete shape" - expect(page).not_to have_css(".leaflet-interactive") + click_on "Delete shape" + expect(page).to have_no_css(".leaflet-interactive") end end @@ -192,8 +192,8 @@ add_polygon expect(page).to have_css(".leaflet-interactive") find(".leaflet-interactive").click - click_button "Delete shape" - expect(page).not_to have_css(".leaflet-interactive") + click_on "Delete shape" + expect(page).to have_no_css(".leaflet-interactive") end end end @@ -206,7 +206,7 @@ expect(page).to have_css(".leaflet-marker-icon", visible: :all) find('div[title="Remove Layers"] a').click find(".leaflet-marker-icon").click - expect(page).not_to have_css(".leaflet-marker-icon") + expect(page).to have_no_css(".leaflet-marker-icon") end end @@ -217,7 +217,7 @@ expect(page).to have_css(".leaflet-interactive") find('div[title="Remove Layers"] a').click find(".leaflet-interactive").click - expect(page).not_to have_css(".leaflet-interactive") + expect(page).to have_no_css(".leaflet-interactive") end end @@ -228,7 +228,7 @@ expect(page).to have_css(".leaflet-interactive") find('div[title="Remove Layers"] a').click find(".leaflet-interactive").click - expect(page).not_to have_css(".leaflet-interactive") + expect(page).to have_no_css(".leaflet-interactive") end end end @@ -241,7 +241,7 @@ add_marker(latitude: 11.523, longitude: 5.523) expect(page).to have_css(".leaflet-marker-icon", count: 2) find(".leaflet-marker-icon", match: :first).click - click_button "Delete shape" + click_on "Delete shape" expect(page).to have_css(".leaflet-marker-icon", count: 1) end end @@ -253,7 +253,7 @@ add_line(latitude: [60.25240524264372, 60.25116980538645], longitude: [25.10409421539333, 25.104342109680122]) expect(page).to have_css(".leaflet-interactive", count: 2) find(".leaflet-interactive", match: :first).click - click_button "Delete shape" + click_on "Delete shape" expect(page).to have_css(".leaflet-interactive", count: 1) end end @@ -265,7 +265,7 @@ add_polygon(latitude: [85.05109772344434, 85.05101347805167, 85.05106165693364], longitude: [24.741211170645243, 24.7438833903077, 24.74355157804477]) expect(page).to have_css(".leaflet-interactive", count: 2) find(".leaflet-interactive", match: :first).click - click_button "Delete shape" + click_on "Delete shape" expect(page).to have_css(".leaflet-interactive", count: 1) end end diff --git a/spec/shared/type_locations_examples.rb b/spec/shared/type_locations_examples.rb index 9f858b6..bfd3f18 100644 --- a/spec/shared/type_locations_examples.rb +++ b/spec/shared/type_locations_examples.rb @@ -5,12 +5,12 @@ it "adds marker" do expect(page).to have_css(".type-loc-field") sleep 1 - find("#dummy_address").set("veneen") + find_by_id("dummy_address").set("veneen") expect(page).to have_content( "Veneentekijäntie 4, Finland\nVeneentekijäntie 6, Finland\nVeneentekijäntie 7, Finland" ) - find("#autoComplete_result_0").click - click_button "Add" + find_by_id("autoComplete_result_0").click + click_on "Add" expect(page).to have_css(".leaflet-marker-draggable") end end @@ -19,22 +19,22 @@ it "adds multiple if configured accordingly" do expect(page).to have_css(".type-loc-field") sleep 1 - find("#dummy_address").set("veneen") + find_by_id("dummy_address").set("veneen") expect(page).to have_content( "Veneentekijäntie 4, Finland\nVeneentekijäntie 6, Finland\nVeneentekijäntie 7, Finland" ) - find("#autoComplete_result_0").click - click_button "Add" + find_by_id("autoComplete_result_0").click + click_on "Add" expect(page).to have_css(".leaflet-marker-draggable") expect(page).to have_css(".leaflet-marker-draggable", count: 1) - find("#dummy_address").set("veneen") + find_by_id("dummy_address").set("veneen") expect(page).to have_content( "Veneentekijäntie 4, Finland\nVeneentekijäntie 6, Finland\nVeneentekijäntie 7, Finland" ) - find("#autoComplete_result_1").click - click_button "Add" + find_by_id("autoComplete_result_1").click + click_on "Add" expect(page).to have_css(".leaflet-marker-draggable") - expect(page).not_to have_css(".leaflet-marker-draggable", count: 1) + expect(page).to have_no_css(".leaflet-marker-draggable", count: 1) expect(page).to have_css(".leaflet-marker-draggable", count: 2, visible: :all) end end @@ -44,21 +44,21 @@ it "adds a single location" do expect(page).to have_css(".type-loc-field") - find("#dummy_address").set("veneen") + find_by_id("dummy_address").set("veneen") expect(page).to have_content( "Veneentekijäntie 4, Finland\nVeneentekijäntie 6, Finland\nVeneentekijäntie 7, Finland" ) - find("#autoComplete_result_0").click - click_button "Add" + find_by_id("autoComplete_result_0").click + click_on "Add" expect(page).to have_css(".shape-field") expect(page).to have_css(".leaflet-marker-draggable", count: 1) expect(page).to have_field("dummy_locations__index__address", type: :hidden, with: "Veneentekijäntie 4, Finland") - find("#dummy_address").set("veneen") + find_by_id("dummy_address").set("veneen") expect(page).to have_content( "Veneentekijäntie 4, Finland\nVeneentekijäntie 6, Finland\nVeneentekijäntie 7, Finland" ) - find("#autoComplete_result_1").click - click_button "Add" + find_by_id("autoComplete_result_1").click + click_on "Add" expect(page).to have_field("dummy_locations__index__address", type: :hidden, with: "Veneentekijäntie 6, Finland") expect(page).to have_css(".leaflet-marker-draggable", count: 1) end @@ -68,17 +68,17 @@ it "changes the address field to the form" do expect(page).to have_css(".type-loc-field") sleep 1 - find("#dummy_address").set("veneen") + find_by_id("dummy_address").set("veneen") expect(page).to have_content( "Veneentekijäntie 4, Finland\nVeneentekijäntie 6, Finland\nVeneentekijäntie 7, Finland" ) - find("#autoComplete_result_0").click - click_button "Add" - expect(page).to have_selector("input[value=\"Veneentekijäntie 4, Finland\"]", visible: :hidden) + find_by_id("autoComplete_result_0").click + click_on "Add" + expect(page).to have_css("input[value=\"Veneentekijäntie 4, Finland\"]", visible: :hidden) find(".leaflet-marker-draggable").click find("input[name=\"address\"]").fill_in with: "Example street" - click_button "Save" - expect(page).to have_selector("input[value=\"Example street\"]", visible: :hidden) + click_on "Save" + expect(page).to have_css("input[value=\"Example street\"]", visible: :hidden) end end end diff --git a/spec/system/map_spec.rb b/spec/system/map_spec.rb index 503b8fb..fdd2558 100644 --- a/spec/system/map_spec.rb +++ b/spec/system/map_spec.rb @@ -2,12 +2,12 @@ require "spec_helper" -describe "Map", type: :system do +describe "Map" do let!(:organization) { create(:organization) } let(:template_class) do Class.new(ActionView::Base) do - include ::Cell::RailsExtensions::ActionView + include Cell::RailsExtensions::ActionView delegate :snippets, :current_organization, to: :controller @@ -183,11 +183,10 @@ def cell(name, model, options = {}, &) end before do - allow(Decidim).to receive(:maps).and_return({provider: :here}) if use_revgeo # Autocomplete utility override - utility = Decidim::Map.autocomplete(organization: organization) - allow(Decidim::Map).to receive(:autocomplete).with(organization: organization).and_return(utility) + utility = Decidim::Map.autocomplete(organization:) + allow(Decidim::Map).to receive(:autocomplete).with(organization:).and_return(utility) allow(utility).to receive(:builder_options).and_return( api_key: "key1234" ) @@ -341,12 +340,10 @@ def drag_polygon let(:form) { Decidim::FormBuilder.new("dummy", dummy_form, template, {}) } let(:map_configuration) { "multiple" } - let(:cell) { template.cell("decidim/locations/locations", dummy, form: form, map_configuration: map_configuration, coords: [12, 2]) } + let(:cell) { template.cell("decidim/locations/locations", dummy, form:, map_configuration:, coords: [12, 2]) } let(:styles) { nil } context "when geocoding" do - # Console.warn print tool - # puts page.driver.browser.manage.logs.get(:browser).map(&:message).join("\n") let(:geocode_response) do { type: "FeatureCollection", @@ -446,8 +443,8 @@ def drag_polygon let(:dummy) { create(:dummy_resource, body: "A reasonable body") } let(:dummy_form) { Decidim::Dev::DummyResourceForm.from_model(dummy) } let(:form) { Decidim::FormBuilder.new("dummy", dummy_form, template, {}) } - let(:cell) { template.cell("decidim/locations/locations", dummy, form: form, map_configuration: "single", coords: [12, 2]) } - let(:cell_two) { template.cell("decidim/locations/locations", dummy, form: form, map_configuration: "multiple", coords: [12, 2]) } + let(:cell) { template.cell("decidim/locations/locations", dummy, form:, map_configuration: "single", coords: [12, 2]) } + let(:cell_two) { template.cell("decidim/locations/locations", dummy, form:, map_configuration: "multiple", coords: [12, 2]) } let(:use_dummy_random_ids) { true } let(:html_document) do @@ -488,7 +485,6 @@ def drag_polygon visit "/test_map" # Wait for the map to be rendered - driver.browser.logs.get(:browser) expect(page).to have_css("[data-decidim-map] .leaflet-map-pane img") # Wait for all map tile images to be loaded @@ -501,7 +497,7 @@ def drag_polygon it "renders multiple maps" do expect(page).to have_css(".type-loc-field", count: 2) - expect(page).to have_selector("div[data-shape-field]", count: 2) + expect(page).to have_css("div[data-shape-field]", count: 2) end context "when adding markers" do @@ -517,43 +513,17 @@ def drag_polygon expect(page).to have_css(".leaflet-marker-icon", count: 1) end - page.execute_script("window.scrollBy(0, 800)") + page.execute_script("window.scrollBy(0, 1100)") within "#pick_model_locations_map-exampletwo" do find('div[title="Draw Marker"] a').click - find("[data-decidim-map]").click(x: 15, y: 5) - find("[data-decidim-map]").click(x: 20, y: 10) - find("div.leaflet-pm-actions-container a.leaflet-pm-action.action-cancel").click + find("[data-decidim-map]").click(x: 6, y: 2) + find("[data-decidim-map]").click(x: 6, y: 2) expect(page).to have_css("img.leaflet-marker-icon", count: 2) end end end end - - context "when cell has 'has location' -checkbox" do - let(:dummy) { create(:dummy_resource, body: "A reasonable body") } - let(:dummy_form) { Decidim::Dev::DummyResourceForm.from_model(dummy) } - let(:form) { Decidim::FormBuilder.new("dummy", dummy_form, template, {}) } - let(:map_configuration) { "multiple" } - let(:cell) { template.cell("decidim/locations/locations", dummy, form: form, map_configuration: map_configuration, coords: [12, 2], checkbox: true) } - let(:styles) { nil } - - before do - visit "/test_map" - end - - it "checks the box if text is clicked" do - expect(page).to have_content("Has location") - find('label[for="dummy_has_location"]').click - expect(page).to have_css("[data-decidim-map] .leaflet-map-pane img") - - loop do - break if page.all("[data-decidim-map] .leaflet-map-pane img").all? { |img| img["complete"] == "true" } - - sleep 0.1 - end - end - end end end diff --git a/spec/types/component_type_spec.rb b/spec/types/component_type_spec.rb index feb5466..1d00185 100644 --- a/spec/types/component_type_spec.rb +++ b/spec/types/component_type_spec.rb @@ -11,36 +11,36 @@ module Core Decidim::Core::ComponentType.implements Decidim::Locations::LocationsInterface include_context "with a graphql class type" - let!(:location1) { create(:location, locatable: model, skip_injection: true) } - let!(:location2) { create(:location, locatable: model, skip_injection: true) } + let!(:location_one) { create(:location, locatable: model, skip_injection: true) } + let!(:location_two) { create(:location, locatable: model, skip_injection: true) } let(:model) { create(:dummy_component) } let(:query) { "{ locations { id address longitude latitude } }" } describe "locations" do it "returns the location fields" do addresses = response["locations"].map { |location| location["address"] } - expect(addresses).to match_array([location1.address, location2.address]) + expect(addresses).to contain_exactly(location_one.address, location_two.address) end end describe "longitudes" do it "returns the location fields" do addresses = response["locations"].map { |location| location["longitude"] } - expect(addresses).to match_array([location1.longitude, location2.longitude]) + expect(addresses).to contain_exactly(location_one.longitude, location_two.longitude) end end describe "latitudes" do it "returns the location fields" do addresses = response["locations"].map { |location| location["latitude"] } - expect(addresses).to match_array([location1.latitude, location2.latitude]) + expect(addresses).to contain_exactly(location_one.latitude, location_two.latitude) end end describe "ids" do it "returns the location fields" do addresses = response["locations"].map { |location| location["id"] } - expect(addresses).to match_array([location1.id.to_s, location2.id.to_s]) + expect(addresses).to contain_exactly(location_one.id.to_s, location_two.id.to_s) end end end