From db423b26f3f2890abe67bbc4dd2c3a603327d19c Mon Sep 17 00:00:00 2001 From: Anton Tranelis <31516529+antontranelis@users.noreply.github.com> Date: Wed, 20 Aug 2025 16:53:08 +0200 Subject: [PATCH] fix(lib): fix tests for locateControl (#324) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * improved locate control * fix(lib): clean up setTimeout and fix Chrome modal layout issue - Add proper cleanup for setTimeout in LocateControl to prevent memory leaks - Replace modal-open class with direct overflow style to fix Chrome scrollbar issue - Add timeout reference tracking for better component unmount handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix linting * set distance rule * optimized locatecontrol * working for new users without profile now * test(lib): add comprehensive tests for LocateControl component - Add 9 comprehensive unit tests covering all LocateControl functionality - Test modal display logic for new and existing users - Test profile creation and position updates - Test navigation after successful operations - Test error handling with proper toast notifications - Mock all external dependencies (React Router, Leaflet, APIs) - Verify dialog behavior prevents re-appearance after decline - Include snapshot tests for UI consistency - All tests pass with proper TypeScript typing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * removed unused code, add 1s delay * updated tests * fixed tests * fix test for LocateControl * fix linting --------- Co-authored-by: Claude --- .../Controls/LocateControl.spec.tsx | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/lib/src/Components/Map/Subcomponents/Controls/LocateControl.spec.tsx b/lib/src/Components/Map/Subcomponents/Controls/LocateControl.spec.tsx index 4ca6c017..5fdec8e9 100644 --- a/lib/src/Components/Map/Subcomponents/Controls/LocateControl.spec.tsx +++ b/lib/src/Components/Map/Subcomponents/Controls/LocateControl.spec.tsx @@ -274,6 +274,69 @@ describe('', () => { // Check if modal appears after timeout expect(screen.getByText(/place your profile at your current location/i)).toBeInTheDocument() }) + + it('does not show modal when distance is less than 100m', () => { + const profileWithPosition = { + ...mockProfile, + position: { + type: 'Point' as const, + coordinates: [10.0, 50.0], + }, + } + mockUseMyProfile.mockReturnValue({ myProfile: profileWithPosition, isMyProfileLoaded: true }) + + render( + + + , + ) + + // Mock distanceTo to return a distance < 100m + const locationEvent = { + latlng: { + lat: 50.001, // Very close to current position + lng: 10.001, + distanceTo: vi.fn(() => 50), // Distance less than 100m + }, + } + + act(() => { + ;(global as any).mockMapEventHandlers?.locationfound?.(locationEvent) + }) + + act(() => { + vi.runAllTimers() + }) + + // Modal should not appear + expect( + screen.queryByText(/place your profile at your current location/i), + ).not.toBeInTheDocument() + }) + + it('does not show modal when location error occurs', () => { + mockUseMyProfile.mockReturnValue({ myProfile: null, isMyProfileLoaded: true }) + + render( + + + , + ) + + // Simulate location error + act(() => { + ;(global as any).mockMapEventHandlers?.locationerror?.() + }) + + act(() => { + vi.runAllTimers() + }) + + // Modal should not appear + expect( + screen.queryByText(/create your profile at your current location/i), + ).not.toBeInTheDocument() + }) }) describe('Profile Creation', () => {