From ceef7702fac7fdc1de993361bb2bbee28af624b1 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 9 Jul 2025 21:51:48 +0200 Subject: [PATCH] Add data migration to recalculate trips distance. --- ...250709195003_recalculate_trips_distance.rb | 13 ++++ db/data_schema.rb | 2 +- spec/system/map_interaction_spec.rb | 62 ++++++++++++++++--- 3 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 db/data/20250709195003_recalculate_trips_distance.rb diff --git a/db/data/20250709195003_recalculate_trips_distance.rb b/db/data/20250709195003_recalculate_trips_distance.rb new file mode 100644 index 00000000..6c02bd3a --- /dev/null +++ b/db/data/20250709195003_recalculate_trips_distance.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class RecalculateTripsDistance < ActiveRecord::Migration[8.0] + def up + Trip.find_each do |trip| + trip.enqueue_calculation_jobs + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/data_schema.rb b/db/data_schema.rb index e96ded10..0fac2063 100644 --- a/db/data_schema.rb +++ b/db/data_schema.rb @@ -1 +1 @@ -DataMigrate::Data.define(version: 20250704185707) +DataMigrate::Data.define(version: 20250709195003) diff --git a/spec/system/map_interaction_spec.rb b/spec/system/map_interaction_spec.rb index b256899c..3d426725 100644 --- a/spec/system/map_interaction_spec.rb +++ b/spec/system/map_interaction_spec.rb @@ -687,8 +687,15 @@ RSpec.describe 'Map Interaction', type: :system do include_context 'authenticated map user' it 'opens and displays calendar navigation' do + # Wait for the map controller to fully initialize and create the toggle button + expect(page).to have_css('#map', wait: 10) + expect(page).to have_css('.leaflet-container', wait: 10) + + # Additional wait for the controller to finish initializing all controls + sleep 2 + # Click calendar button - calendar_button = find('.toggle-panel-button', wait: 10) + calendar_button = find('.toggle-panel-button', wait: 15) expect(calendar_button).to be_visible # Verify button is clickable @@ -713,24 +720,59 @@ RSpec.describe 'Map Interaction', type: :system do end it 'persists panel state in localStorage' do - # Open panel - calendar_button = find('.toggle-panel-button', wait: 10) + # Wait for the map controller to fully initialize and create the toggle button + # The button is created dynamically by the JavaScript controller + expect(page).to have_css('#map', wait: 10) + expect(page).to have_css('.leaflet-container', wait: 10) + + # Additional wait for the controller to finish initializing all controls + # The toggle-panel-button is created by the addTogglePanelButton() method + # which is called after the map and all other controls are set up + sleep 2 + + # Now try to find the calendar button + calendar_button = nil + begin + calendar_button = find('.toggle-panel-button', wait: 15) + rescue Capybara::ElementNotFound + # If button still not found, check if map controller loaded properly + map_element = find('#map') + controller_data = map_element['data-controller'] + + # Log debug info for troubleshooting + puts "Map controller data: #{controller_data}" + puts "Map element classes: #{map_element[:class]}" + + # Try one more time with extended wait + calendar_button = find('.toggle-panel-button', wait: 20) + end + + # Verify button exists and is functional + expect(calendar_button).to be_present calendar_button.click - expect(page).to have_css('.leaflet-right-panel', visible: true) + + # Wait for panel to appear + expect(page).to have_css('.leaflet-right-panel', visible: true, wait: 10) # Close panel calendar_button.click - expect(page).not_to have_css('.leaflet-right-panel', visible: true) + + # Wait for panel to disappear + expect(page).not_to have_css('.leaflet-right-panel', visible: true, wait: 10) # Refresh page (user should still be signed in due to session) page.refresh expect(page).to have_css('#map', wait: 10) + expect(page).to have_css('.leaflet-container', wait: 10) + + # Wait for controller to reinitialize after refresh + sleep 2 # Panel should remember its state (though this is hard to test reliably in system tests) # At minimum, verify the panel can be toggled after refresh - calendar_button = find('.toggle-panel-button', wait: 10) + calendar_button = find('.toggle-panel-button', wait: 15) calendar_button.click - expect(page).to have_css('.leaflet-right-panel') + expect(page).to have_css('.leaflet-right-panel', wait: 10) end end @@ -836,9 +878,9 @@ RSpec.describe 'Map Interaction', type: :system do expect(page).to have_css('.leaflet-control-scale') expect(page).to have_css('.leaflet-control-stats') - # Verify custom controls - expect(page).to have_css('.map-settings-button') - expect(page).to have_css('.toggle-panel-button') + # Verify custom controls (these are created dynamically by JavaScript) + expect(page).to have_css('.map-settings-button', wait: 10) + expect(page).to have_css('.toggle-panel-button', wait: 15) end end