Repository navigation
RC-T46 Map Updates for Custom Markers #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // Incident tactical map screen (src/app/command-map/[callId].tsx): the map legend control and sheet. | ||
| import { act, fireEvent, render, screen } from '@testing-library/react-native'; | ||
| import React from 'react'; | ||
|
|
||
| import CommandMapScreen from '@/app/command-map/[callId]'; | ||
|
|
||
| jest.mock('expo-router', () => ({ | ||
| Stack: { Screen: () => null }, | ||
| useLocalSearchParams: () => ({ callId: '101' }), | ||
| })); | ||
| jest.mock('react-i18next', () => ({ | ||
| useTranslation: () => ({ t: (key: string) => key }), | ||
| })); | ||
| jest.mock('@/lib/logging', () => ({ | ||
| logger: { info: jest.fn(), warn: jest.fn(), error: jest.fn(), debug: jest.fn() }, | ||
| })); | ||
| jest.mock('@/components/maps/mapbox', () => { | ||
| const React = require('react'); | ||
| const { View } = require('react-native'); | ||
| const passthrough = (name: string) => (props: any) => React.createElement(View, { testID: props.testID ?? `mock-${name}` }, props.children); | ||
| return { | ||
| __esModule: true, | ||
| default: { | ||
| MapView: passthrough('map-view'), | ||
| Camera: passthrough('camera'), | ||
| ShapeSource: passthrough('shape-source'), | ||
| LineLayer: passthrough('line-layer'), | ||
| FillLayer: passthrough('fill-layer'), | ||
| MarkerView: passthrough('marker-view'), | ||
| }, | ||
| }; | ||
| }); | ||
| jest.mock('@/components/command/incident-map-layers', () => ({ | ||
| AnnotationLayers: () => null, | ||
| IncidentLocationMarkers: () => null, | ||
| })); | ||
| jest.mock('@/components/maps/map-pins', () => ({ __esModule: true, default: () => null })); | ||
| jest.mock('@/api/mapping/mapping', () => ({ | ||
| getMapDataAndMarkers: jest.fn(() => Promise.resolve({ Data: { MapMakerInfos: [] } })), | ||
| })); | ||
| jest.mock('@/hooks/use-map-signalr-updates', () => ({ useMapSignalRUpdates: jest.fn(() => jest.fn()) })); | ||
| jest.mock('@/hooks/use-map-geolocation-updates', () => ({ | ||
| useMapGeolocationUpdates: jest.fn(), | ||
| withLiveLocationsSince: (pins: unknown[]) => pins, | ||
| })); | ||
| jest.mock('@/hooks/use-command-map-overlay', () => ({ useCommandMapOverlay: () => ({}) })); | ||
| jest.mock('@/lib/map-center', () => ({ useDepartmentMapCenter: () => ({ latitude: 39.5, longitude: -119.8 }) })); | ||
| jest.mock('@/lib/map-style', () => ({ useDepartmentMapStyle: () => 'mapbox://styles/mapbox/streets-v12' })); | ||
| jest.mock('@/stores/toast/store', () => { | ||
| const state = { showToast: jest.fn() }; | ||
| return { useToastStore: (selector: any) => selector(state) }; | ||
| }); | ||
| jest.mock('@/stores/command/store', () => { | ||
| const state = { | ||
| boards: { | ||
| '101': { | ||
| board: { | ||
| Command: { IncidentCommandId: 'ic-1', CallId: 101, MapCenterLatitude: '39.5', MapCenterLongitude: '-119.8', MapZoomLevel: '14' }, | ||
| Maps: [], | ||
| Annotations: [], | ||
| }, | ||
| }, | ||
| }, | ||
| updateMapViewEntry: jest.fn(), | ||
| saveIncidentMapEntry: jest.fn(), | ||
| saveMapAnnotationEntry: jest.fn(), | ||
| deleteMapAnnotationEntry: jest.fn(), | ||
| }; | ||
| return { useCommandStore: (selector: any) => selector(state) }; | ||
| }); | ||
| jest.mock('@/components/ui/bottom-sheet', () => ({ | ||
| CustomBottomSheet: ({ children, isOpen }: any) => (isOpen ? children : null), | ||
| })); | ||
| jest.mock('@/components/ui/focus-aware-status-bar', () => ({ FocusAwareStatusBar: () => null })); | ||
|
|
||
| const mockLegendProps: { current: { isOpen: boolean; onClose: () => void; showHydrant?: boolean } | null } = { current: null }; | ||
| jest.mock('@/components/maps/map-legend-sheet', () => { | ||
| const React = require('react'); | ||
| const { View } = require('react-native'); | ||
| return { | ||
| MapLegendSheet: (props: { isOpen: boolean; onClose: () => void; showHydrant?: boolean }) => { | ||
| mockLegendProps.current = props; | ||
| return props.isOpen ? React.createElement(View, { testID: 'mock-map-legend-sheet' }) : null; | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| describe('Command map: map legend', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockLegendProps.current = null; | ||
| }); | ||
|
|
||
| it('shows a labelled legend button on the tactical map', async () => { | ||
| render(<CommandMapScreen />); | ||
|
|
||
| const button = await screen.findByTestId('map-legend-button'); | ||
| expect(screen.getByTestId('command-map-screen')).toBeTruthy(); | ||
| expect(button.props.accessibilityLabel).toBe('maps.legend.title'); | ||
| expect(button).toHaveStyle({ position: 'absolute', right: 20, width: 48, height: 48 }); | ||
| expect(mockLegendProps.current?.isOpen).toBe(false); | ||
| }); | ||
|
|
||
| it('opens the legend sheet from the button and closes it again', async () => { | ||
| render(<CommandMapScreen />); | ||
|
|
||
| fireEvent.press(await screen.findByTestId('map-legend-button')); | ||
|
|
||
| expect(screen.getByTestId('mock-map-legend-sheet')).toBeTruthy(); | ||
| expect(mockLegendProps.current?.isOpen).toBe(true); | ||
| // The tactical map draws only the incident's units and personnel, never hydrants. | ||
| expect(mockLegendProps.current?.showHydrant).toBeFalsy(); | ||
|
|
||
| act(() => { | ||
| mockLegendProps.current?.onClose(); | ||
| }); | ||
| expect(screen.queryByTestId('mock-map-legend-sheet')).toBeNull(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| // Main map screen (src/app/(app)/index.tsx): the map legend control and sheet. | ||
| jest.mock('nativewind', () => ({ | ||
| styled: jest.fn((Component: any) => Component), | ||
| cssInterop: jest.fn((Component: any) => Component), | ||
| useColorScheme: jest.fn(() => ({ | ||
| colorScheme: 'light', | ||
| get: jest.fn(() => 'light'), | ||
| setColorScheme: jest.fn(), | ||
| toggleColorScheme: jest.fn(), | ||
| })), | ||
| __esModule: true, | ||
| })); | ||
|
|
||
| import { act, fireEvent, render, screen, waitFor } from '@testing-library/react-native'; | ||
| import React from 'react'; | ||
|
|
||
| import Map from '@/app/(app)/index'; | ||
| import { useAppLifecycle } from '@/hooks/use-app-lifecycle'; | ||
| import { locationService } from '@/services/location'; | ||
| import { useLocationStore } from '@/stores/app/location-store'; | ||
|
|
||
| jest.mock('react-native-safe-area-context', () => ({ | ||
| SafeAreaProvider: ({ children }: { children: React.ReactNode }) => children, | ||
| useSafeAreaInsets: () => ({ top: 44, bottom: 34, left: 0, right: 0 }), | ||
| })); | ||
| jest.mock('@/hooks/use-app-lifecycle'); | ||
| jest.mock('@/stores/app/location-store'); | ||
| jest.mock('@/services/location'); | ||
| jest.mock('@/hooks/use-map-signalr-updates', () => ({ | ||
| useMapSignalRUpdates: jest.fn(), | ||
| })); | ||
| jest.mock('@/hooks/use-map-geolocation-updates', () => ({ | ||
| useMapGeolocationUpdates: jest.fn(), | ||
| withLiveLocationsSince: (pins: unknown[]) => pins, | ||
| })); | ||
| const mockGetMapDataAndMarkers = jest.fn(); | ||
| jest.mock('@/api/mapping/mapping', () => ({ | ||
| getMapDataAndMarkers: (...args: unknown[]) => mockGetMapDataAndMarkers(...args), | ||
| })); | ||
| jest.mock('@rnmapbox/maps', () => ({ | ||
| setAccessToken: jest.fn(), | ||
| MapView: 'MapView', | ||
| Camera: 'Camera', | ||
| PointAnnotation: 'PointAnnotation', | ||
| ShapeSource: 'ShapeSource', | ||
| FillLayer: 'FillLayer', | ||
| LineLayer: 'LineLayer', | ||
| MarkerView: 'MarkerView', | ||
| StyleURL: { Street: 'mapbox://styles/mapbox/streets-v11' }, | ||
| UserTrackingMode: { Follow: 'follow', FollowWithHeading: 'followWithHeading' }, | ||
| })); | ||
| jest.mock('expo-router', () => ({ | ||
| router: { push: jest.fn() }, | ||
| Stack: { Screen: () => null }, | ||
| useFocusEffect: jest.fn(), | ||
| })); | ||
| jest.mock('react-i18next', () => ({ | ||
| useTranslation: () => ({ t: (key: string) => key }), | ||
| })); | ||
| jest.mock('@/stores/toast/store', () => { | ||
| const state = { showToast: jest.fn() }; | ||
| const useToastStore = (selector: any) => (typeof selector === 'function' ? selector(state) : state); | ||
| useToastStore.getState = () => state; | ||
| return { useToastStore }; | ||
| }); | ||
| jest.mock('@/stores/app/core-store', () => { | ||
| const storeState = { setActiveCall: jest.fn(), isInitialized: true, config: null }; | ||
| const mockFn = jest.fn((selector) => (typeof selector === 'function' ? selector(storeState) : storeState)) as jest.Mock & { getState: () => typeof storeState }; | ||
| mockFn.getState = () => storeState; | ||
| return { useCoreStore: mockFn }; | ||
| }); | ||
| jest.mock('@/components/maps/map-pins', () => ({ __esModule: true, default: () => null })); | ||
| jest.mock('@/components/maps/pin-detail-modal', () => ({ __esModule: true, default: () => null })); | ||
| jest.mock('@/components/maps/map-layers-sheet', () => ({ MapLayersSheet: () => null })); | ||
| jest.mock('@/components/weather-alerts/weather-alert-banner', () => ({ WeatherAlertBanner: () => null })); | ||
| jest.mock('@/hooks/use-analytics', () => ({ useAnalytics: () => ({ trackEvent: jest.fn() }) })); | ||
| jest.mock('@/components/ui/focus-aware-status-bar', () => ({ FocusAwareStatusBar: () => null })); | ||
|
|
||
| // The legend sheet itself is covered by map-legend-sheet.test.tsx: here, only what the screen hands it. | ||
| const mockLegendProps: { current: { isOpen: boolean; onClose: () => void; showHydrant?: boolean } | null } = { current: null }; | ||
| jest.mock('@/components/maps/map-legend-sheet', () => { | ||
| const React = require('react'); | ||
| const { View } = require('react-native'); | ||
| return { | ||
| MapLegendSheet: (props: { isOpen: boolean; onClose: () => void; showHydrant?: boolean }) => { | ||
| mockLegendProps.current = props; | ||
| return props.isOpen ? React.createElement(View, { testID: 'mock-map-legend-sheet' }) : null; | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| const locationState = { latitude: 40.7128, longitude: -74.006, heading: 0, isMapLocked: false }; | ||
|
|
||
| describe('Main map: map legend', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockLegendProps.current = null; | ||
| (useLocationStore as unknown as jest.Mock).mockImplementation((selector: any) => (typeof selector === 'function' ? selector(locationState) : locationState)); | ||
| (useAppLifecycle as jest.Mock).mockReturnValue({ isActive: true, appState: 'active', isBackground: false, lastActiveTimestamp: Date.now() }); | ||
| (locationService.startLocationUpdates as jest.Mock) = jest.fn().mockResolvedValue(undefined); | ||
| (locationService.stopLocationUpdates as jest.Mock) = jest.fn(); | ||
| mockGetMapDataAndMarkers.mockResolvedValue({ Data: { MapMakerInfos: [] } }); | ||
| }); | ||
|
|
||
| it('shows a labelled legend button stacked above the layers button', async () => { | ||
| render(<Map />); | ||
|
|
||
| const button = await screen.findByTestId('map-legend-button'); | ||
| expect(button.props.accessibilityLabel).toBe('maps.legend.title'); | ||
| expect(button.props.accessibilityRole).toBe('button'); | ||
| // 132 above the bottom safe-area inset (34): the slot above the layers control. | ||
| expect(button).toHaveStyle({ position: 'absolute', right: 20, bottom: 166, width: 48, height: 48 }); | ||
| expect(screen.getByTestId('layers-button')).toBeTruthy(); | ||
| expect(screen.queryByTestId('mock-map-legend-sheet')).toBeNull(); | ||
| expect(mockLegendProps.current?.isOpen).toBe(false); | ||
| }); | ||
|
|
||
| it('stacks recenter, layers and legend in their own slots, so none covers another', async () => { | ||
| render(<Map />); | ||
| await screen.findByTestId('map-legend-button'); | ||
| expect(screen.queryByTestId('recenter-button')).toBeNull(); | ||
|
|
||
| // The user pans the map: the recenter control appears in the bottom slot. | ||
| act(() => { | ||
| screen.UNSAFE_getByType('MapView' as any).props.onCameraChanged({ properties: { isUserInteraction: true } }); | ||
| }); | ||
|
|
||
| // Above the bottom safe-area inset (34): recenter 20, layers 76, legend 132. | ||
| expect(screen.getByTestId('recenter-button')).toHaveStyle({ bottom: 54 }); | ||
| expect(screen.getByTestId('layers-button')).toHaveStyle({ bottom: 110 }); | ||
| expect(screen.getByTestId('map-legend-button')).toHaveStyle({ bottom: 166 }); | ||
| }); | ||
|
|
||
| it('opens the legend sheet from the button and closes it again', async () => { | ||
| render(<Map />); | ||
|
|
||
| fireEvent.press(await screen.findByTestId('map-legend-button')); | ||
|
|
||
| expect(screen.getByTestId('mock-map-legend-sheet')).toBeTruthy(); | ||
| expect(mockLegendProps.current?.isOpen).toBe(true); | ||
| expect(mockLegendProps.current?.showHydrant).toBe(false); | ||
|
|
||
| act(() => { | ||
| mockLegendProps.current?.onClose(); | ||
| }); | ||
| expect(screen.queryByTestId('mock-map-legend-sheet')).toBeNull(); | ||
| }); | ||
|
|
||
| it('asks the legend to list hydrants only when the map is drawing hydrant markers', async () => { | ||
| mockGetMapDataAndMarkers.mockResolvedValue({ | ||
| Data: { | ||
| MapMakerInfos: [ | ||
| { Id: 'u1', Type: 1, Title: 'Engine 1', Latitude: 40, Longitude: -74, ImagePath: 'Engine_Available' }, | ||
| { Id: 'hydrant-9', Type: 5, Title: 'H-9', Latitude: 40, Longitude: -74, ImagePath: 'hydrant' }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| render(<Map />); | ||
|
|
||
| await waitFor(() => expect(mockLegendProps.current?.showHydrant).toBe(true)); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unhandled asynchronous query rejections can obscure the operation that failed and provide insufficient test context. Guard awaited queries such as screen.findByTestId('map-legend-button') with try/catch and rethrow an error with operation context at src/tests/map-screen-legend.test.tsx:120-120, src/tests/command-map-legend.test.tsx:107-107, src/components/command/tests/incident-map-card.test.tsx:193-193, src/tests/map-screen-legend.test.tsx:161-161, src/api/mapping/tests/mapIconLegend.test.ts:70-70, src/components/maps/tests/map-legend-sheet.test.tsx:141-141, src/components/maps/tests/map-legend-sheet.test.tsx:363-363, src/components/maps/tests/map-legend-sheet.test.tsx:369-369, src/components/maps/tests/map-legend-sheet.test.tsx:386-386, src/api/mapping/mapping.ts:84-84, src/tests/map-screen-legend.test.tsx:137-137, src/tests/command-map-legend.test.tsx:97-97, src/components/maps/tests/map-legend-sheet.test.tsx:307-307, src/components/maps/tests/map-legend-sheet.test.tsx:375-375, src/api/mapping/tests/mapIconLegend.test.ts:83-83, src/components/maps/tests/map-legend-sheet.test.tsx:351-353, src/components/maps/tests/map-legend-sheet.test.tsx:160-160, src/components/maps/tests/map-legend-sheet.test.tsx:178-178, src/components/maps/tests/map-legend-sheet.test.tsx:187-187, src/components/maps/tests/map-legend-sheet.test.tsx:195-195, src/components/maps/tests/map-legend-sheet.test.tsx:205-205, src/components/maps/tests/map-legend-sheet.test.tsx:213-213, src/components/maps/tests/map-legend-sheet.test.tsx:224-224, src/components/maps/tests/map-legend-sheet.test.tsx:234-234, src/components/maps/tests/map-legend-sheet.test.tsx:249-249, src/components/maps/tests/map-legend-sheet.test.tsx:266-266, src/components/maps/tests/map-legend-sheet.test.tsx:274-274, src/components/maps/tests/map-legend-sheet.test.tsx:285-285, src/components/maps/tests/map-legend-sheet.test.tsx:297-297, src/components/maps/tests/map-legend-sheet.test.tsx:315-315, src/components/maps/tests/map-legend-sheet.test.tsx:323-323, src/components/maps/tests/map-legend-sheet.test.tsx:336-336, and src/components/maps/tests/map-legend-sheet.test.tsx:403-403.
Kody rule violation: Handle async operations with proper error handling
Prompt for LLM
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.