Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/components/map/LocationMarker/LocationMarker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ vi.mock('leaflet', () => ({
},
}));

// Mock the theme-color hook so the accuracy circle gets a deterministic,
// theme-derived color (issue #37) without needing real DaisyUI CSS in jsdom.
const THEME_COLOR = '#aabbcc';
vi.mock('@/hooks/useEmbedThemeColor', () => ({
useEmbedThemeColor: () => ({
hex: 'aabbcc',
hexWithHash: THEME_COLOR,
isDark: false,
}),
}));

describe('LocationMarker', () => {
const defaultProps: LocationMarkerProps = {
position: [51.505, -0.09],
Expand Down Expand Up @@ -82,6 +93,18 @@ describe('LocationMarker', () => {
expect(circle).toHaveAttribute('data-radius', '10');
});

it('colors the accuracy circle with the theme primary, not a hardcoded blue (#37)', () => {
render(<LocationMarker {...defaultProps} showAccuracy />);

const circle = screen.getByTestId('accuracy-circle');
const options = JSON.parse(circle.getAttribute('data-options') || '{}');
expect(options.color).toBe(THEME_COLOR);
expect(options.fillColor).toBe(THEME_COLOR);
// Guard against regressing to the old hardcoded values.
expect(options.color).not.toBe('blue');
expect(options.fillColor).not.toBe('lightblue');
});

it('should not render accuracy circle when showAccuracy is false', () => {
const props = {
...defaultProps,
Expand Down
10 changes: 8 additions & 2 deletions src/components/map/LocationMarker/LocationMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useEffect } from 'react';
import { Marker, Circle, Popup, useMap } from 'react-leaflet';
import L from 'leaflet';
import type { LatLngTuple } from 'leaflet';
import { useEmbedThemeColor } from '@/hooks/useEmbedThemeColor';

export interface LocationMarkerProps {
position: LatLngTuple;
Expand Down Expand Up @@ -42,6 +43,11 @@ export const LocationMarker: React.FC<LocationMarkerProps> = ({
}) => {
const map = useMap();

// Accuracy circle tracks the active DaisyUI theme's primary color (issue #37),
// matching the marker dot (which uses the `bg-primary` class). The hook
// re-renders on theme switch so the circle recolors live.
const { hexWithHash: themeColor } = useEmbedThemeColor('p');

useEffect(() => {
// Pan to user location when marker updates
map.setView(position, map.getZoom());
Expand All @@ -62,8 +68,8 @@ export const LocationMarker: React.FC<LocationMarkerProps> = ({
center={position}
radius={accuracy}
pathOptions={{
color: 'blue',
fillColor: 'lightblue',
color: themeColor,
fillColor: themeColor,
fillOpacity: 0.2,
weight: 1,
}}
Expand Down
Loading