diff --git a/src/components/EnhancedMap/ImageMarkerLayer/ImageMarkerLayer.test.js b/src/components/EnhancedMap/ImageMarkerLayer/ImageMarkerLayer.test.js index f904f9a44..593d0785e 100644 --- a/src/components/EnhancedMap/ImageMarkerLayer/ImageMarkerLayer.test.js +++ b/src/components/EnhancedMap/ImageMarkerLayer/ImageMarkerLayer.test.js @@ -4,25 +4,25 @@ import { MapContainer } from 'react-leaflet' import ImageMarkerLayer from './ImageMarkerLayer' describe('ImageMarkerLayer Component', () => { - beforeAll(() => { - jest.spyOn(console, 'error').mockImplementation(() => {}) - }) + beforeAll(() => { + jest.spyOn(console, 'error').mockImplementation(() => {}) + }) - afterAll(() => { - console.error.mockRestore() - }) + afterAll(() => { + console.error.mockRestore() + }) - const mockImages = [ - { key: 'image1', url: 'http://example.com/image1.jpg', position: { lat: 1, lon: 1 } }, - { key: 'image2', url: 'http://example.com/image2.jpg', position: { lat: 2, lon: 2 } }, - ] + const mockImages = [ + { key: 'image1', url: 'http://example.com/image1.jpg', position: { lat: 1, lon: 1 } }, + { key: 'image2', url: 'http://example.com/image2.jpg', position: { lat: 2, lon: 2 } }, + ] - it('renders without crashing', () => { - const { container } = render( - - - - ) - expect(container).toBeInTheDocument() - }) + it('renders without crashing', () => { + const { container } = render( + + + + ) + expect(container).toBeInTheDocument() + }) }) diff --git a/src/components/MapillaryViewer/MapillaryViewer.test.js b/src/components/MapillaryViewer/MapillaryViewer.test.js index 3c4c16198..6dab5db5b 100644 --- a/src/components/MapillaryViewer/MapillaryViewer.test.js +++ b/src/components/MapillaryViewer/MapillaryViewer.test.js @@ -2,26 +2,26 @@ import React from 'react' import { render } from '@testing-library/react' import MapillaryViewer from './MapillaryViewer' -jest.mock('mapillary-js', () => { - return { - Viewer: jest.fn().mockImplementation(() => ({ - setImageId: jest.fn(), - remove: jest.fn(), - })), - } +jest.mock('mapillary-js', () => { + return { + Viewer: jest.fn().mockImplementation(() => ({ + setImageId: jest.fn(), + remove: jest.fn(), + })), + } }) describe('MapillaryViewer Component', () => { - beforeAll(() => { - jest.spyOn(console, 'error').mockImplementation(() => {}) - }) + beforeAll(() => { + jest.spyOn(console, 'error').mockImplementation(() => {}) + }) - afterAll(() => { - console.error.mockRestore() - }) + afterAll(() => { + console.error.mockRestore() + }) - it('renders without crashing', () => { - const { container } = render() - expect(container).toBeInTheDocument() - }) + it('renders without crashing', () => { + const { container } = render() + expect(container).toBeInTheDocument() + }) }) diff --git a/src/components/Modal/Modal.test.js b/src/components/Modal/Modal.test.js index 17be926c1..1485a8482 100644 --- a/src/components/Modal/Modal.test.js +++ b/src/components/Modal/Modal.test.js @@ -3,21 +3,21 @@ import { render } from '@testing-library/react' import Modal from './Modal' describe('Modal Component', () => { - beforeAll(() => { - jest.spyOn(console, 'error').mockImplementation(() => {}) - }) + beforeAll(() => { + jest.spyOn(console, 'error').mockImplementation(() => {}) + }) - afterAll(() => { - console.error.mockRestore() - }) + afterAll(() => { + console.error.mockRestore() + }) - it('renders without crashing', () => { - const { container } = render( {}} />) - expect(container).toBeInTheDocument() - }) + it('renders without crashing', () => { + const { container } = render( {}} />) + expect(container).toBeInTheDocument() + }) - it('displays the modal content', () => { - const { getByText } = render( {}}>Modal Content) - expect(getByText(/modal content/i)).toBeInTheDocument() - }) + it('displays the modal content', () => { + const { getByText } = render( {}}>Modal Content) + expect(getByText(/modal content/i)).toBeInTheDocument() + }) }) diff --git a/src/components/OpenStreetCamViewer/OpenStreetCamViewer.jsx b/src/components/OpenStreetCamViewer/OpenStreetCamViewer.jsx index 6dea8e5f7..d4770b386 100644 --- a/src/components/OpenStreetCamViewer/OpenStreetCamViewer.jsx +++ b/src/components/OpenStreetCamViewer/OpenStreetCamViewer.jsx @@ -13,98 +13,98 @@ import BusySpinner from '../BusySpinner/BusySpinner' * @author [Neil Rotstan](https://github.com/nrotstan) */ const OpenStreetCamViewer = ({ images, initialImageKey, onClose }) => { - const [currentIndex, setCurrentIndex] = useState(-1) - const [imageLoaded, setImageLoaded] = useState(false) + const [currentIndex, setCurrentIndex] = useState(-1) + const [imageLoaded, setImageLoaded] = useState(false) - useEffect(() => { - setCurrentIndex(_findIndex(images, { key: initialImageKey })) - }, [images, initialImageKey]) + useEffect(() => { + setCurrentIndex(_findIndex(images, { key: initialImageKey })) + }, [images, initialImageKey]) - const hasNextImage = () => currentIndex !== -1 && currentIndex < images.length - 1 - const hasPriorImage = () => currentIndex !== -1 && currentIndex > 0 + const hasNextImage = () => currentIndex !== -1 && currentIndex < images.length - 1 + const hasPriorImage = () => currentIndex !== -1 && currentIndex > 0 - const nextImage = () => { - if (hasNextImage()) { - setCurrentIndex(currentIndex + 1) - setImageLoaded(false) - } - } + const nextImage = () => { + if (hasNextImage()) { + setCurrentIndex(currentIndex + 1) + setImageLoaded(false) + } + } - const priorImage = () => { - if (hasPriorImage()) { - setCurrentIndex(currentIndex - 1) - setImageLoaded(false) - } - } + const priorImage = () => { + if (hasPriorImage()) { + setCurrentIndex(currentIndex - 1) + setImageLoaded(false) + } + } - const currentImage = currentIndex === -1 ? null : images[currentIndex] + const currentImage = currentIndex === -1 ? null : images[currentIndex] - return ( - - - - - - - {hasPriorImage() && - - - - } - + return ( + + + + + + + {hasPriorImage() && + + + + } + - + - - {hasNextImage() && - - - - } - - - + + {hasNextImage() && + + + + } + + + - - {currentImage && - setImageLoaded(true)} - alt="" - className="mr-w-full mr-h-auto mr-rounded mr-shadow" - /> - } - - - {!imageLoaded ? - : - - - @{currentImage.username} - - - {format(parseISO(currentImage.shotDate), 'yyyy-MM-dd')} - - - } - - - - - ) + + {currentImage && + setImageLoaded(true)} + alt="" + className="mr-w-full mr-h-auto mr-rounded mr-shadow" + /> + } + + + {!imageLoaded ? + : + + + @{currentImage.username} + + + {format(parseISO(currentImage.shotDate), 'yyyy-MM-dd')} + + + } + + + + + ) } OpenStreetCamViewer.propTypes = { - images: PropTypes.array.isRequired, - onClose: PropTypes.func, + images: PropTypes.array.isRequired, + onClose: PropTypes.func, } export default OpenStreetCamViewer diff --git a/src/components/OpenStreetCamViewer/OpenStreetCamViewer.test.js b/src/components/OpenStreetCamViewer/OpenStreetCamViewer.test.js index 55013dbb6..fef0aa753 100644 --- a/src/components/OpenStreetCamViewer/OpenStreetCamViewer.test.js +++ b/src/components/OpenStreetCamViewer/OpenStreetCamViewer.test.js @@ -3,16 +3,16 @@ import { render } from '@testing-library/react' import OpenStreetCamViewer from './OpenStreetCamViewer' describe('OpenStreetCamViewer Component', () => { - beforeAll(() => { - jest.spyOn(console, 'error').mockImplementation(() => {}) - }) + beforeAll(() => { + jest.spyOn(console, 'error').mockImplementation(() => {}) + }) - afterAll(() => { - console.error.mockRestore() - }) + afterAll(() => { + console.error.mockRestore() + }) - it('renders without crashing', () => { - const { container } = render() - expect(container).toBeInTheDocument() - }) + it('renders without crashing', () => { + const { container } = render() + expect(container).toBeInTheDocument() + }) }) diff --git a/src/components/TaskPane/TaskMap/TaskMap.jsx b/src/components/TaskPane/TaskMap/TaskMap.jsx index c79da3537..bfabc1e9d 100644 --- a/src/components/TaskPane/TaskMap/TaskMap.jsx +++ b/src/components/TaskPane/TaskMap/TaskMap.jsx @@ -321,7 +321,7 @@ export const TaskMapContent = (props) => { } } } - + /** * Invoked by LayerToggle when the user wishes to toggle visibility of * OpenStreetCam markers on or off. diff --git a/src/services/Mapillary/Mapillary.test.js b/src/services/Mapillary/Mapillary.test.js index 29b98e89b..1c0ce8f64 100644 --- a/src/services/Mapillary/Mapillary.test.js +++ b/src/services/Mapillary/Mapillary.test.js @@ -12,72 +12,72 @@ const mockFetch = jest.fn() global.fetch = mockFetch describe('Mapillary Service Functions', () => { - beforeAll(() => { - jest.spyOn(console, 'error').mockImplementation(() => {}) - }) + beforeAll(() => { + jest.spyOn(console, 'error').mockImplementation(() => {}) + }) - afterAll(() => { - console.error.mockRestore() - }) + afterAll(() => { + console.error.mockRestore() + }) - beforeEach(() => { - jest.clearAllMocks() - process.env.REACT_APP_MAPILLARY_CLIENT_TOKEN = 'mockToken' - }) + beforeEach(() => { + jest.clearAllMocks() + process.env.REACT_APP_MAPILLARY_CLIENT_TOKEN = 'mockToken' + }) - afterEach(() => { - delete process.env.REACT_APP_MAPILLARY_CLIENT_TOKEN - imageCache.clear() - }) + afterEach(() => { + delete process.env.REACT_APP_MAPILLARY_CLIENT_TOKEN + imageCache.clear() + }) - describe('isMapillaryEnabled', () => { - it('should return true if the Mapillary client token is set', () => { - expect(isMapillaryEnabled()).toBe(true) - }) + describe('isMapillaryEnabled', () => { + it('should return true if the Mapillary client token is set', () => { + expect(isMapillaryEnabled()).toBe(true) + }) - it('should return false if the Mapillary client token is not set', () => { - delete process.env.REACT_APP_MAPILLARY_CLIENT_TOKEN - expect(isMapillaryEnabled()).toBe(false) - }) + it('should return false if the Mapillary client token is not set', () => { + delete process.env.REACT_APP_MAPILLARY_CLIENT_TOKEN + expect(isMapillaryEnabled()).toBe(false) }) + }) - describe('fetchMapillaryImages', () => { - it('should throw an error if Mapillary is not enabled', async () => { - delete process.env.REACT_APP_MAPILLARY_CLIENT_TOKEN - await expect(fetchMapillaryImages('0,0,1,1')).rejects.toThrow("Missing Mapillary client token") - }) + describe('fetchMapillaryImages', () => { + it('should throw an error if Mapillary is not enabled', async () => { + delete process.env.REACT_APP_MAPILLARY_CLIENT_TOKEN + await expect(fetchMapillaryImages('0,0,1,1')).rejects.toThrow("Missing Mapillary client token") + }) - it('should handle invalid bbox input gracefully', async () => { - await expect(fetchMapillaryImages(null)).rejects.toThrow('Unable to fetch Mapillary images. Please try again.') - }) + it('should handle invalid bbox input gracefully', async () => { + await expect(fetchMapillaryImages(null)).rejects.toThrow('Unable to fetch Mapillary images. Please try again.') }) + }) - describe('hasMoreMapillaryResults', () => { - it('should return false if there is no next page', () => { - const resultContext = { link: '' } - expect(hasMoreMapillaryResults(resultContext)).toBe(false) - }) + describe('hasMoreMapillaryResults', () => { + it('should return false if there is no next page', () => { + const resultContext = { link: '' } + expect(hasMoreMapillaryResults(resultContext)).toBe(false) }) + }) - describe('nextMapillaryPage', () => { - it('should return null if there is no next page', async () => { - const resultContext = { link: '' } - const result = await nextMapillaryPage(resultContext) - expect(result).toBeNull() - }) + describe('nextMapillaryPage', () => { + it('should return null if there is no next page', async () => { + const resultContext = { link: '' } + const result = await nextMapillaryPage(resultContext) + expect(result).toBeNull() }) + }) - describe('mapillaryImageUrl', () => { - it('should generate the correct Mapillary image URL', () => { - const imageId = 'abc123' - const expectedUrl = `https://www.mapillary.com/embed?image_key=${imageId}` - expect(mapillaryImageUrl(imageId)).toBe(expectedUrl) - }) + describe('mapillaryImageUrl', () => { + it('should generate the correct Mapillary image URL', () => { + const imageId = 'abc123' + const expectedUrl = `https://www.mapillary.com/embed?image_key=${imageId}` + expect(mapillaryImageUrl(imageId)).toBe(expectedUrl) }) + }) - describe('getAccessToken', () => { - it('should return the access token', () => { - expect(getAccessToken()).toBe(process.env.REACT_APP_MAPILLARY_CLIENT_TOKEN) - }) + describe('getAccessToken', () => { + it('should return the access token', () => { + expect(getAccessToken()).toBe(process.env.REACT_APP_MAPILLARY_CLIENT_TOKEN) }) + }) }) diff --git a/src/services/OpenStreetCam/OpenStreetCam.test.js b/src/services/OpenStreetCam/OpenStreetCam.test.js index 550ca06a1..97baf1cb2 100644 --- a/src/services/OpenStreetCam/OpenStreetCam.test.js +++ b/src/services/OpenStreetCam/OpenStreetCam.test.js @@ -1,23 +1,23 @@ import { fetchOpenStreetCamImages } from './OpenStreetCam' describe('OpenStreetCam Service Functions', () => { - beforeEach(() => { - jest.clearAllMocks() - process.env.REACT_APP_IMAGERY_OPENSTREETCAM = 'enabled' - }) + beforeEach(() => { + jest.clearAllMocks() + process.env.REACT_APP_IMAGERY_OPENSTREETCAM = 'enabled' + }) - it('should throw an error if OpenStreetCam is not enabled', async () => { - process.env.REACT_APP_IMAGERY_OPENSTREETCAM = 'disabled' - await expect(fetchOpenStreetCamImages('0,0,1,1')).rejects.toThrow("OpenStreetCam is not enabled") - }) + it('should throw an error if OpenStreetCam is not enabled', async () => { + process.env.REACT_APP_IMAGERY_OPENSTREETCAM = 'disabled' + await expect(fetchOpenStreetCamImages('0,0,1,1')).rejects.toThrow("OpenStreetCam is not enabled") + }) - it('should fetch OpenStreetCam images correctly', async () => { - const mockResponse = { currentPageItems: [], totalFilteredItems: [0] } - const mockFetch = jest.fn().mockResolvedValueOnce({ ok: true, json: jest.fn().mockResolvedValue(mockResponse) }) - global.fetch = mockFetch + it('should fetch OpenStreetCam images correctly', async () => { + const mockResponse = { currentPageItems: [], totalFilteredItems: [0] } + const mockFetch = jest.fn().mockResolvedValueOnce({ ok: true, json: jest.fn().mockResolvedValue(mockResponse) }) + global.fetch = mockFetch - const result = await fetchOpenStreetCamImages('0,0,1,1') - expect(result.currentPageItems).toEqual([]) - expect(mockFetch).toHaveBeenCalled() - }) + const result = await fetchOpenStreetCamImages('0,0,1,1') + expect(result.currentPageItems).toEqual([]) + expect(mockFetch).toHaveBeenCalled() + }) })