Fix specs for watcher and change z-index for markers and polylines

This commit is contained in:
Eugene Burmakin
2024-12-25 13:05:42 +01:00
parent d9c4c5d16e
commit d9bade8fe5
8 changed files with 38 additions and 38 deletions

View File

@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Imported points will now be reverse geocoded only after import is finished.
### Fixed
- Markers on the map are now being rendered with higher z-index than polylines. #577
# 0.21.1 - 2024-12-24
### Added

View File

@@ -9,7 +9,11 @@ export function createMarkersArray(markersData, userSettings) {
const popupContent = createPopupContent(marker, userSettings.timezone, userSettings.distanceUnit);
let markerColor = marker[5] < 0 ? "orange" : "blue";
return L.circleMarker([lat, lon], { radius: 4, color: markerColor }).bindPopup(popupContent, { autoClose: false });
return L.circleMarker([lat, lon], {
radius: 4,
color: markerColor,
zIndexOffset: 1000
}).bindPopup(popupContent, { autoClose: false });
});
}
}

View File

@@ -122,7 +122,12 @@ export function createPolylinesLayer(markers, map, timezone, routeOpacity, userS
return L.layerGroup(
splitPolylines.map((polylineCoordinates) => {
const latLngs = polylineCoordinates.map((point) => [point[0], point[1]]);
const polyline = L.polyline(latLngs, { color: "blue", opacity: 0.6, weight: 3 });
const polyline = L.polyline(latLngs, {
color: "blue",
opacity: 0.6,
weight: 3,
zIndexOffset: 400
});
addHighlightOnHover(polyline, map, polylineCoordinates, userSettings, distanceUnit);

View File

@@ -4,11 +4,9 @@ class ImportJob < ApplicationJob
queue_as :imports
def perform(user_id, import_id)
user = User.find(user_id)
import = user.imports.find(import_id)
import.process!
end
end

View File

@@ -9,14 +9,13 @@ class Imports::Watcher
def call
user_directories.each do |user_email|
user = User.find_by(email: user_email)
next unless user
puts "Processing directory for user: #{user.email}"
user_directory_path = File.join(WATCHED_DIR_PATH, user_email)
file_names = file_names(user_directory_path)
file_names.each do |file_name|
puts "Processing file: #{file_name}"
process_file(user, user_directory_path, file_name)
end
end
@@ -38,9 +37,7 @@ puts "Processing directory for user: #{user.email}"
end
def file_names(directory_path)
Dir.entries(directory_path).select do |file|
SUPPORTED_FORMATS.include?(File.extname(file))
end
Dir.entries(directory_path).select { |file| SUPPORTED_FORMATS.include?(File.extname(file)) }
end
def process_file(user, directory_path, file_name)
@@ -53,11 +50,8 @@ puts "Processing directory for user: #{user.email}"
import.raw_data = raw_data(file_path, import.source)
import.save!
puts "Import saved for file: #{file_name}"
ImportJob.perform_later(user.id, import.id)
puts "ImportJob enqueued for user_id: #{user.id}, import_id: #{import.id}"
end
def find_or_initialize_import(user, file_name)
@@ -109,4 +103,4 @@ puts "Processing directory for user: #{user.email}"
raise UnsupportedSourceError, "Unsupported source: #{source}"
end
end
end
end

View File

@@ -6,5 +6,5 @@
# Use this to limit dissemination of sensitive information.
# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors.
Rails.application.config.filter_parameters += %i[
passw email secret token _key crypt salt certificate otp ssn cvv cvc latitude longitude lat lng
passw secret token _key crypt salt certificate otp ssn cvv cvc latitude longitude lat lng
]

View File

@@ -67,4 +67,4 @@
}
}
]
}
}

View File

@@ -7,7 +7,6 @@ RSpec.describe Imports::Watcher do
subject(:service) { described_class.new.call }
let(:watched_dir_path) { Rails.root.join('spec/fixtures/files/watched') }
let(:user) { create(:user, email: 'user@domain.com') }
before do
stub_const('Imports::Watcher::WATCHED_DIR_PATH', watched_dir_path)
@@ -16,31 +15,15 @@ RSpec.describe Imports::Watcher do
after { Sidekiq::Testing.fake! }
context 'when there are no files in the watched directory' do
it 'does not call ImportJob' do
expect(ImportJob).not_to receive(:perform_later)
context 'when user exists' do
let!(:user) { create(:user, email: 'user@domain.com') }
service
end
end
context 'when there are files in the watched directory' do
context 'when the file has a valid user email' do
it 'creates an import for the user' do
expect { service }.to change(user.imports, :count).by(6)
end
it 'creates points for the user' do
initial_point_count = Point.count
service
expect(Point.count).to be > initial_point_count
end
it 'creates an import for the user' do
expect { service }.to change(user.imports, :count).by(6)
end
context 'when the file has an invalid user email' do
it 'does not create an import' do
expect { service }.not_to change(Import, :count)
end
it 'enqueues importing jobs for the user' do
expect { service }.to have_enqueued_job(ImportJob).exactly(6).times
end
context 'when the import already exists' do
@@ -56,5 +39,17 @@ RSpec.describe Imports::Watcher do
end
end
end
context 'when user does not exist' do
it 'does not call ImportJob' do
expect(ImportJob).not_to receive(:perform_later)
service
end
it 'does not create an import' do
expect { service }.not_to change(Import, :count)
end
end
end
end