dawarich/spec/services/users/safe_settings_spec.rb
Evgenii Burmakin 8934c29fce
0.36.2 (#2007)
* fix: move foreman to global gems to fix startup crash (#1971)

* Update exporting code to stream points data to file in batches to red… (#1980)

* Update exporting code to stream points data to file in batches to reduce memory usage

* Update changelog

* Update changelog

* Feature/maplibre frontend (#1953)

* Add a plan to use MapLibre GL JS for the frontend map rendering, replacing Leaflet

* Implement phase 1

* Phases 1-3 + part of 4

* Fix e2e tests

* Phase 6

* Implement fog of war

* Phase 7

* Next step: fix specs, phase 7 done

* Use our own map tiles

* Extract v2 map logic to separate manager classes

* Update settings panel on v2 map

* Update v2 e2e tests structure

* Reimplement location search in maps v2

* Update speed routes

* Implement visits and places creation in v2

* Fix last failing test

* Implement visits merging

* Fix a routes e2e test and simplify the routes layer styling.

* Extract js to modules from maps_v2_controller.js

* Implement area creation

* Fix spec problem

* Fix some e2e tests

* Implement live mode in v2 map

* Update icons and panel

* Extract some styles

* Remove unused file

* Start adding dark theme to popups on MapLibre maps

* Make popups respect dark theme

* Move v2 maps to maplibre namespace

* Update v2 references to maplibre

* Put place, area and visit info into side panel

* Update API to use safe settings config method

* Fix specs

* Fix method name to config in SafeSettings and update usages accordingly

* Add missing public files

* Add handling for real time points

* Fix remembering enabled/disabled layers of the v2 map

* Fix lots of e2e tests

* Add settings to select map version

* Use maps/v2 as main path for MapLibre maps

* Update routing

* Update live mode

* Update maplibre controller

* Update changelog

* Remove some console.log statements

---------

Co-authored-by: Robin Tuszik <mail@robin.gg>
2025-12-06 20:54:49 +01:00

190 lines
7.7 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Users::SafeSettings do
describe '#config' do
context 'with default values' do
let(:settings) { {} }
let(:safe_settings) { described_class.new(settings) }
it 'returns default configuration' do
expect(safe_settings.config).to eq(
{
fog_of_war_meters: 50,
meters_between_routes: 500,
preferred_map_layer: 'OpenStreetMap',
speed_colored_routes: false,
points_rendering_mode: 'raw',
minutes_between_routes: 30,
time_threshold_minutes: 30,
merge_threshold_minutes: 15,
live_map_enabled: true,
route_opacity: 60,
immich_url: nil,
immich_api_key: nil,
photoprism_url: nil,
photoprism_api_key: nil,
maps: { "distance_unit" => "km" },
distance_unit: 'km',
visits_suggestions_enabled: true,
speed_color_scale: nil,
fog_of_war_threshold: nil,
enabled_map_layers: ['Routes', 'Heatmap'],
maps_maplibre_style: 'light'
}
)
end
end
context 'with custom values' do
let(:settings) do
{
'fog_of_war_meters' => 100,
'meters_between_routes' => 1000,
'preferred_map_layer' => 'Satellite',
'speed_colored_routes' => true,
'points_rendering_mode' => 'simplified',
'minutes_between_routes' => 60,
'time_threshold_minutes' => 45,
'merge_threshold_minutes' => 20,
'live_map_enabled' => false,
'route_opacity' => 80,
'immich_url' => 'https://immich.example.com',
'immich_api_key' => 'immich-key',
'photoprism_url' => 'https://photoprism.example.com',
'photoprism_api_key' => 'photoprism-key',
'maps' => { 'name' => 'custom', 'url' => 'https://custom.example.com' },
'visits_suggestions_enabled' => false,
'enabled_map_layers' => ['Points', 'Routes', 'Areas', 'Photos']
}
end
let(:safe_settings) { described_class.new(settings) }
it 'returns custom configuration' do
expect(safe_settings.settings).to eq(
{
"fog_of_war_meters" => 100,
"meters_between_routes" => 1000,
"preferred_map_layer" => "Satellite",
"speed_colored_routes" => true,
"points_rendering_mode" => "simplified",
"minutes_between_routes" => 60,
"time_threshold_minutes" => 45,
"merge_threshold_minutes" => 20,
"live_map_enabled" => false,
"route_opacity" => 80,
"immich_url" => "https://immich.example.com",
"immich_api_key" => "immich-key",
"photoprism_url" => "https://photoprism.example.com",
"photoprism_api_key" => "photoprism-key",
"maps" => { "name" => "custom", "url" => "https://custom.example.com" },
"visits_suggestions_enabled" => false,
"enabled_map_layers" => ['Points', 'Routes', 'Areas', 'Photos'],
"maps_maplibre_style" => "light"
}
)
end
it 'returns custom config configuration' do
expect(safe_settings.config).to eq(
{
fog_of_war_meters: 100,
meters_between_routes: 1000,
preferred_map_layer: "Satellite",
speed_colored_routes: true,
points_rendering_mode: "simplified",
minutes_between_routes: 60,
time_threshold_minutes: 45,
merge_threshold_minutes: 20,
live_map_enabled: false,
route_opacity: 80,
immich_url: "https://immich.example.com",
immich_api_key: "immich-key",
photoprism_url: "https://photoprism.example.com",
photoprism_api_key: "photoprism-key",
maps: { "name" => "custom", "url" => "https://custom.example.com" },
distance_unit: nil,
visits_suggestions_enabled: false,
speed_color_scale: nil,
fog_of_war_threshold: nil,
enabled_map_layers: ['Points', 'Routes', 'Areas', 'Photos'],
maps_maplibre_style: 'light'
}
)
end
end
end
describe 'individual settings' do
let(:safe_settings) { described_class.new(settings) }
context 'with default values' do
let(:settings) { {} }
it 'returns default values for each setting' do
expect(safe_settings.fog_of_war_meters).to eq(50)
expect(safe_settings.meters_between_routes).to eq(500)
expect(safe_settings.preferred_map_layer).to eq('OpenStreetMap')
expect(safe_settings.speed_colored_routes).to be false
expect(safe_settings.points_rendering_mode).to eq('raw')
expect(safe_settings.minutes_between_routes).to eq(30)
expect(safe_settings.time_threshold_minutes).to eq(30)
expect(safe_settings.merge_threshold_minutes).to eq(15)
expect(safe_settings.live_map_enabled).to be true
expect(safe_settings.route_opacity).to eq(60)
expect(safe_settings.immich_url).to be_nil
expect(safe_settings.immich_api_key).to be_nil
expect(safe_settings.photoprism_url).to be_nil
expect(safe_settings.photoprism_api_key).to be_nil
expect(safe_settings.maps).to eq({ "distance_unit" => "km" })
expect(safe_settings.visits_suggestions_enabled?).to be true
expect(safe_settings.enabled_map_layers).to eq(['Routes', 'Heatmap'])
end
end
context 'with custom values' do
let(:settings) do
{
'fog_of_war_meters' => 100,
'meters_between_routes' => 1000,
'preferred_map_layer' => 'Satellite',
'speed_colored_routes' => true,
'points_rendering_mode' => 'simplified',
'minutes_between_routes' => 60,
'time_threshold_minutes' => 45,
'merge_threshold_minutes' => 20,
'live_map_enabled' => false,
'route_opacity' => 80,
'immich_url' => 'https://immich.example.com',
'immich_api_key' => 'immich-key',
'photoprism_url' => 'https://photoprism.example.com',
'photoprism_api_key' => 'photoprism-key',
'maps' => { 'name' => 'custom', 'url' => 'https://custom.example.com' },
'visits_suggestions_enabled' => false,
'enabled_map_layers' => ['Points', 'Tracks', 'Fog of War', 'Suggested Visits']
}
end
it 'returns custom values for each setting' do
expect(safe_settings.fog_of_war_meters).to eq(100)
expect(safe_settings.meters_between_routes).to eq(1000)
expect(safe_settings.preferred_map_layer).to eq('Satellite')
expect(safe_settings.speed_colored_routes).to be true
expect(safe_settings.points_rendering_mode).to eq('simplified')
expect(safe_settings.minutes_between_routes).to eq(60)
expect(safe_settings.time_threshold_minutes).to eq(45)
expect(safe_settings.merge_threshold_minutes).to eq(20)
expect(safe_settings.live_map_enabled).to be false
expect(safe_settings.route_opacity).to eq(80)
expect(safe_settings.immich_url).to eq('https://immich.example.com')
expect(safe_settings.immich_api_key).to eq('immich-key')
expect(safe_settings.photoprism_url).to eq('https://photoprism.example.com')
expect(safe_settings.photoprism_api_key).to eq('photoprism-key')
expect(safe_settings.maps).to eq({ 'name' => 'custom', 'url' => 'https://custom.example.com' })
expect(safe_settings.visits_suggestions_enabled?).to be false
expect(safe_settings.enabled_map_layers).to eq(['Points', 'Tracks', 'Fog of War', 'Suggested Visits'])
end
end
end
end