From b26a7528df1282c3af7011dce08e008d70a3cdc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 31 Mar 2022 11:21:58 +0200 Subject: [PATCH] Move mappable helper methods to a new common actions module So we can use the same customization technique overriding the methods we need. --- spec/shared/system/mappable.rb | 58 --------------------------- spec/support/common_actions.rb | 1 + spec/support/common_actions/maps.rb | 61 +++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 58 deletions(-) create mode 100644 spec/support/common_actions/maps.rb diff --git a/spec/shared/system/mappable.rb b/spec/shared/system/mappable.rb index 78bfbb897..f0ab2d1b1 100644 --- a/spec/shared/system/mappable.rb +++ b/spec/shared/system/mappable.rb @@ -292,61 +292,3 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end end end - -def do_login_for(user) - common_do_login_for(user, management: management) -end - -def fill_in_proposal_form - fill_in_new_proposal_title with: "Help refugees" - fill_in "Proposal summary", with: "In summary, what we want is..." -end - -def submit_proposal_form - check :proposal_terms_of_service - click_button "Create proposal" - - if page.has_content?("Not now, go to my proposal") - click_link "Not now, go to my proposal" - end -end - -def validate_latitude_longitude(mappable_factory_name) - expect(find("##{mappable_factory_name}_map_location_attributes_latitude", visible: false).value).to eq "51.48" - expect(find("##{mappable_factory_name}_map_location_attributes_longitude", visible: false).value).to eq "0.0" - expect(mappable.map_location.latitude).to eq 51.48 - expect(mappable.map_location.longitude).to eq 0.0 -end - -def fill_in_budget_investment_form - fill_in_new_investment_title with: "Budget investment title" - fill_in_ckeditor "Description", with: "Budget investment description" - check :budget_investment_terms_of_service -end - -def submit_budget_investment_form - check :budget_investment_terms_of_service - click_button "Create Investment" -end - -def set_arguments(arguments, mappable, mappable_path_arguments) - mappable_path_arguments&.each do |argument_name, path_to_value| - arguments.merge!("#{argument_name}": mappable.send(path_to_value)) - end -end - -def map_zoom_in - initial_zoom = page.execute_script("return App.Map.maps[0].getZoom();") - find(".leaflet-control-zoom-in").click - until page.execute_script("return App.Map.maps[0].getZoom() === #{initial_zoom + 1};") do - sleep 0.01 - end -end - -def place_map_at(latitude, longitude) - page.execute_script("App.Map.maps[0].setView(new L.LatLng(#{latitude}, #{longitude}))") - - until page.execute_script("return App.Map.maps[0].getCenter().lat === #{latitude};") do - sleep 0.01 - end -end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index cc7144328..7207c5c57 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -5,6 +5,7 @@ module CommonActions include Comments include Debates include Emails + include Maps include Notifications include Polls include Proposals diff --git a/spec/support/common_actions/maps.rb b/spec/support/common_actions/maps.rb new file mode 100644 index 000000000..1efa539d4 --- /dev/null +++ b/spec/support/common_actions/maps.rb @@ -0,0 +1,61 @@ +module Maps + def do_login_for(user) + common_do_login_for(user, management: management) + end + + def fill_in_proposal_form + fill_in_new_proposal_title with: "Help refugees" + fill_in "Proposal summary", with: "In summary, what we want is..." + end + + def submit_proposal_form + check :proposal_terms_of_service + click_button "Create proposal" + + if page.has_content?("Not now, go to my proposal") + click_link "Not now, go to my proposal" + end + end + + def validate_latitude_longitude(mappable_factory_name) + latitude_attribute = "##{mappable_factory_name}_map_location_attributes_latitude" + longitude_attribute = "##{mappable_factory_name}_map_location_attributes_longitude" + expect(find(latitude_attribute, visible: false).value).to eq "51.48" + expect(find(longitude_attribute, visible: false).value).to eq "0.0" + expect(mappable.map_location.latitude).to eq 51.48 + expect(mappable.map_location.longitude).to eq 0.0 + end + + def fill_in_budget_investment_form + fill_in_new_investment_title with: "Budget investment title" + fill_in_ckeditor "Description", with: "Budget investment description" + check :budget_investment_terms_of_service + end + + def submit_budget_investment_form + check :budget_investment_terms_of_service + click_button "Create Investment" + end + + def set_arguments(arguments, mappable, mappable_path_arguments) + mappable_path_arguments&.each do |argument_name, path_to_value| + arguments.merge!("#{argument_name}": mappable.send(path_to_value)) + end + end + + def map_zoom_in + initial_zoom = page.execute_script("return App.Map.maps[0].getZoom();") + find(".leaflet-control-zoom-in").click + until page.execute_script("return App.Map.maps[0].getZoom() === #{initial_zoom + 1};") do + sleep 0.01 + end + end + + def place_map_at(latitude, longitude) + page.execute_script("App.Map.maps[0].setView(new L.LatLng(#{latitude}, #{longitude}))") + + until page.execute_script("return App.Map.maps[0].getCenter().lat === #{latitude};") do + sleep 0.01 + end + end +end