Group similar map tests together

We're about to change some of these tests, and we usually group similar
system tests in order to make the test suite a bit faster.
This commit is contained in:
Javi Martín
2025-11-17 00:31:44 +01:00
parent 2d85bd5351
commit a6908f2017
2 changed files with 16 additions and 78 deletions

View File

@@ -17,7 +17,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
describe "At #{mappable_new_path}" do describe "At #{mappable_new_path}" do
before { set_arguments(arguments, mappable, mappable_path_arguments) } before { set_arguments(arguments, mappable, mappable_path_arguments) }
scenario "Should not show marker by default on create #{mappable_factory_name}" do scenario "Should show marker and create #{mappable_factory_name} with map" do
do_login_for user, management: management do_login_for user, management: management
visit send(mappable_new_path, arguments) visit send(mappable_new_path, arguments)
@@ -26,27 +26,14 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
within ".map-location" do within ".map-location" do
expect(page).not_to have_css(".map-icon") expect(page).not_to have_css(".map-icon")
end end
end
scenario "Should show marker on create #{mappable_factory_name} when click on map" do
do_login_for user, management: management
visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}")
find("#new_map_location").click find("#new_map_location").click
within ".map-location" do within ".map-location" do
expect(page).to have_css ".map-icon" expect(page).to have_css ".map-icon"
expect(page).not_to have_css ".map-icon[aria-label]" expect(page).not_to have_css ".map-icon[aria-label]"
end end
end
scenario "Should create #{mappable_factory_name} with map" do
do_login_for user, management: management
visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}")
find("#new_map_location").click
send("submit_#{mappable_factory_name}_form") send("submit_#{mappable_factory_name}_form")
within ".map-location" do within ".map-location" do
@@ -180,8 +167,9 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
describe "At #{mappable_edit_path}", if: mappable_edit_path.present? do describe "At #{mappable_edit_path}", if: mappable_edit_path.present? do
scenario "Should edit map on #{mappable_factory_name} and contain default values" do scenario "Should edit mappable on #{mappable_factory_name} without changing the map" do
mappable.map_location.update!(latitude: 51.48, longitude: 0.0) mappable.map_location.update!(latitude: 51.48, longitude: 0.0)
do_login_for mappable.author, management: management do_login_for mappable.author, management: management
visit send(mappable_edit_path, id: mappable.id) visit send(mappable_edit_path, id: mappable.id)
@@ -191,6 +179,14 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
with: "51.48" with: "51.48"
expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_longitude", type: :hidden, expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_longitude", type: :hidden,
with: "0.0" with: "0.0"
fill_in "#{mappable_factory_name.camelize} title", with: "New title"
click_button "Save changes"
expect(page).not_to have_button "Save changes"
expect(page).to have_css ".map-location"
expect(page).to have_css ".map-location[data-marker-latitude='51.48']"
expect(page).to have_css ".map-location[data-marker-longitude='0.0']"
end end
scenario "Should edit default values from map on #{mappable_factory_name} edit page" do scenario "Should edit default values from map on #{mappable_factory_name} edit page" do
@@ -219,22 +215,6 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
expect(page).not_to have_css ".map-location[data-marker-longitude='#{original_longitude}']" expect(page).not_to have_css ".map-location[data-marker-longitude='#{original_longitude}']"
end end
scenario "Should edit mappable on #{mappable_factory_name} without change map" do
original_longitude = map_location.longitude
original_latitude = map_location.latitude
do_login_for mappable.author, management: management
visit send(mappable_edit_path, id: mappable.id)
fill_in "#{mappable_factory_name.camelize} title", with: "New title"
click_button "Save changes"
expect(page).not_to have_button "Save changes"
expect(page).to have_css ".map-location"
expect(page).to have_css ".map-location[data-marker-latitude='#{original_latitude}']"
expect(page).to have_css ".map-location[data-marker-longitude='#{original_longitude}']"
end
scenario "Can not display map on #{mappable_factory_name} edit when remove map marker" do scenario "Can not display map on #{mappable_factory_name} edit when remove map marker" do
do_login_for mappable.author, management: management do_login_for mappable.author, management: management
@@ -244,6 +224,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
expect(page).not_to have_button "Save changes" expect(page).not_to have_button "Save changes"
expect(page).not_to have_css ".map-location" expect(page).not_to have_css ".map-location"
expect(page).not_to have_content "Map location can't be blank"
end end
scenario "Can not display map on #{mappable_factory_name} edit when feature.map is disabled" do scenario "Can not display map on #{mappable_factory_name} edit when feature.map is disabled" do
@@ -257,17 +238,6 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
expect(page).not_to have_button "Save changes" expect(page).not_to have_button "Save changes"
expect(page).not_to have_css ".map-location" expect(page).not_to have_css ".map-location"
end end
scenario "No need to skip map on update" do
do_login_for mappable.author, management: management
visit send(mappable_edit_path, id: mappable.id)
click_button "Remove map marker"
click_button "Save changes"
expect(page).not_to have_button "Save changes"
expect(page).not_to have_content "Map location can't be blank"
end
end end
describe "At #{mappable_show_path}" do describe "At #{mappable_show_path}" do

View File

@@ -21,22 +21,16 @@ describe "Admin settings", :admin do
end end
describe "Map settings initialization" do describe "Map settings initialization" do
before do scenario "Map is only initialized when the map settings tab content is shown" do
Setting["feature.map"] = true Setting["feature.map"] = true
end
scenario "When `Map settings` tab content is hidden map should not be initialized" do
visit admin_settings_path visit admin_settings_path
expect(page).not_to have_css("#admin-map.leaflet-container", visible: :all) expect(page).not_to have_css "#admin-map.leaflet-container", visible: :all
end
scenario "When `Map settings` tab content is shown map should be initialized" do
visit admin_settings_path
click_link "Map configuration" click_link "Map configuration"
expect(page).to have_css("#admin-map.leaflet-container") expect(page).to have_css "#admin-map.leaflet-container"
end end
end end
@@ -53,7 +47,7 @@ describe "Admin settings", :admin do
expect(page).not_to have_css("#admin-map") expect(page).not_to have_css("#admin-map")
end end
scenario "Should be able when map feature activated" do scenario "Should update marker" do
Setting["feature.map"] = true Setting["feature.map"] = true
visit admin_settings_path visit admin_settings_path
@@ -63,35 +57,9 @@ describe "Admin settings", :admin do
expect(page).not_to have_content "To show the map to users you must enable " \ expect(page).not_to have_content "To show the map to users you must enable " \
'"Proposals and budget investments geolocation" ' \ '"Proposals and budget investments geolocation" ' \
'on "Features" tab.' 'on "Features" tab.'
end
scenario "Should show successful notice" do
Setting["feature.map"] = true
visit admin_settings_path
click_link "Map configuration"
within "#map-form" do
click_button "Update"
end
expect(page).to have_content "Map configuration updated successfully"
end
scenario "Should display marker by default" do
Setting["feature.map"] = true
visit admin_settings_path
expect(find("#latitude", visible: :hidden).value).to eq "51.48" expect(find("#latitude", visible: :hidden).value).to eq "51.48"
expect(find("#longitude", visible: :hidden).value).to eq "0.0" expect(find("#longitude", visible: :hidden).value).to eq "0.0"
end
scenario "Should update marker" do
Setting["feature.map"] = true
visit admin_settings_path
click_link "Map configuration"
within "#map-form" do within "#map-form" do
find("#admin-map").click find("#admin-map").click