mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 06:56:18 -05:00
The map's right-click (or long-press) menu gains "Calculate Solar Performance", and each saved pin a sun button; both open the calculator at that location. A button beside Latitude fills in the browser's current location. Locations are rounded to 4 decimals, and longitudes from a map panned around the world are wrapped back to -180..180. The map removed lat/lon/z from the URL when it closed, even after navigating to another page, which stripped the calculator's location from its URL (and from links shared with the Share button). It now only cleans up while the URL is still a map page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
import React from 'react';
|
|
import {renderWithProviders as render} from '../test-utils';
|
|
import MapViewer from './MapViewer';
|
|
|
|
// MapLibre needs WebGL, which jsdom lacks; these tests only cover what the viewer does to the URL.
|
|
jest.mock('maplibre-gl', () => ({
|
|
__esModule: true,
|
|
default: {Map: class {
|
|
}, addProtocol: jest.fn(), Marker: class {
|
|
}, Popup: class {
|
|
}},
|
|
}));
|
|
jest.mock('maplibre-gl/dist/maplibre-gl.css', () => ({}));
|
|
jest.mock('pmtiles', () => ({
|
|
__esModule: true, Protocol: class {
|
|
tile = jest.fn();
|
|
},
|
|
}));
|
|
jest.mock('protomaps-themes-base', () => ({__esModule: true, default: () => []}));
|
|
jest.mock('@acalcutt/maplibre-contour-pmtiles', () => ({__esModule: true, default: {}}));
|
|
jest.mock('../api', () => ({
|
|
...jest.requireActual('../api'),
|
|
// Never resolves: the map never initializes, which these tests do not need.
|
|
getMapFiles: jest.fn(() => new Promise(() => {
|
|
})),
|
|
getMapPins: jest.fn(() => new Promise(() => {
|
|
})),
|
|
}));
|
|
|
|
describe('the map position in the URL', () => {
|
|
test('is removed when the map closes', () => {
|
|
const {unmount} = render(<MapViewer/>, {route: '/map?lat=40&lon=-105&z=8&layer=a'});
|
|
unmount();
|
|
expect(window.location.pathname).toBe('/map');
|
|
expect(window.location.search).toBe('?layer=a');
|
|
});
|
|
|
|
test('is not removed from the page the map navigated to', () => {
|
|
// "Calculate Solar Performance" navigates to a page whose own lat/lon must survive the map closing.
|
|
const {unmount} = render(<MapViewer/>, {route: '/map?lat=40&lon=-105&z=8'});
|
|
window.history.pushState({}, '', '/more/calculators?calc=solar&lat=40.0154&lon=-105.2705');
|
|
unmount();
|
|
expect(window.location.search).toBe('?calc=solar&lat=40.0154&lon=-105.2705');
|
|
});
|
|
});
|