Skip to content

Comments

hide map controls by default#2947

Merged
kasya merged 4 commits intoOWASP:mainfrom
Shofikul-Isl4m:fix/hide-map-controls-by-default
Dec 18, 2025
Merged

hide map controls by default#2947
kasya merged 4 commits intoOWASP:mainfrom
Shofikul-Isl4m:fix/hide-map-controls-by-default

Conversation

@Shofikul-Isl4m
Copy link
Contributor

Resolves #2896

This PR hides map controls (zoom buttons and share location button) by default and only displays them after the user explicitly clicks the "Unlock map" button.
image
image

Checklist

  • Required: I read and followed the contributing guidelines
  • Required: I ran make check-test locally and all tests passed
  • I used AI for code, documentation, or tests in this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 17, 2025

Summary by CodeRabbit

  • Tests

    • Added tests confirming zoom controls and the share-location button are hidden by default and become visible after unlocking the map.
  • Bug Fixes

    • Zoom controls now remain hidden until the map is unlocked and attach correctly when activated.
    • Share-location button only appears when the map is active and is omitted when not applicable.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Map controls and share-location UI are hidden by default and only enabled after the user unlocks/activates the map. Tests and a Leaflet mock were updated to support creating/removing a custom zoom control; the component manages a zoomControlRef and conditionally renders location-sharing UI based on isMapActive.

Changes

Cohort / File(s) Summary
Unit tests & Leaflet mock
frontend/__tests__/unit/components/ChapterMap.test.tsx
Added a mockZoomControl and registered it via a control.zoom factory in the Leaflet mock; map init now sets zoomControl: false. New tests verify zoom control is hidden initially, attaches at 'topleft' after unlocking, and that the share-location button appears only when map is active and onShareLocation is provided.
E2E test
frontend/__tests__/e2e/pages/ChapterDetails.spec.ts
Added an explicit step to click the Unlock map button before asserting visibility of zoom in/out and marker controls.
Component
frontend/src/components/ChapterMap.tsx
Introduced zoomControlRef; disabled built-in zoom control (zoomControl: false) on map init; added effects to create/add the custom zoom control when isMapActive is true and remove it when false, with cleanup on unmount. Share-location UI rendering now conditioned on isMapActive.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Inspect Leaflet mock control.zoom registration and test assertions for add/remove and position.
  • Verify zoomControlRef lifecycle: creation, addition/removal, dependencies in effects, and unmount cleanup.
  • Confirm conditional rendering of share-location UI preserves handlers and ARIA attributes.
  • Check E2E unlock step for selector reliability and flakiness.

Possibly related PRs

Suggested reviewers

  • arkid15r
  • kasya

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: hiding map controls by default, which is the primary objective of this PR.
Description check ✅ Passed The description is clearly related to the changeset, explaining that map controls are hidden by default and displayed after the 'Unlock map' button is clicked, which matches the code changes.
Linked Issues check ✅ Passed The PR successfully implements the requirement from issue #2896 by hiding map controls (zoom and share location buttons) until the user clicks the 'Unlock map' button.
Out of Scope Changes check ✅ Passed All changes are directly related to the objective of hiding map controls by default; no out-of-scope modifications are present in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bdff238 and 5fb834d.

📒 Files selected for processing (1)
  • frontend/src/components/ChapterMap.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/ChapterMap.tsx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
frontend/__tests__/unit/components/ChapterMap.test.tsx (1)

412-436: Good test coverage for zoom control visibility.

The tests properly verify that the zoom control is hidden initially and appears when the map is unlocked.

Consider adding a test to verify cleanup when the component unmounts while the map is active:

it('removes zoom control when component unmounts while active', () => {
  const { getByText, unmount } = render(<ChapterMap {...defaultProps} />)

  const overlay = getByText('Unlock map').closest('button')
  fireEvent.click(overlay)

  expect(mockZoomControl.addTo).toHaveBeenCalledWith(mockMap)

  unmount()

  expect(mockZoomControl.remove).toHaveBeenCalled()
})
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a34b8b6 and 893122a.

📒 Files selected for processing (2)
  • frontend/__tests__/unit/components/ChapterMap.test.tsx (4 hunks)
  • frontend/src/components/ChapterMap.tsx (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-12T17:36:57.255Z
Learnt from: Rajgupta36
Repo: OWASP/Nest PR: 1717
File: frontend/__tests__/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.

Applied to files:

  • frontend/__tests__/unit/components/ChapterMap.test.tsx
🧬 Code graph analysis (1)
frontend/src/components/ChapterMap.tsx (1)
frontend/src/types/button.ts (1)
  • Button (4-9)
🔇 Additional comments (6)
frontend/src/components/ChapterMap.tsx (3)

32-32: LGTM!

The zoomControlRef is properly typed and follows the same pattern as other refs in the component.


46-46: LGTM!

Disabling the default zoom control is correct. The custom zoom control is properly managed via the new useEffect hook based on map interaction state.


241-266: LGTM!

The share location button is now correctly hidden by default and only appears when the map is active. The conditional rendering logic properly checks both isMapActive and onShareLocation, ensuring the button displays only when appropriate.

frontend/__tests__/unit/components/ChapterMap.test.tsx (3)

41-57: LGTM!

The zoom control mock is properly structured with addTo and remove methods, correctly simulating the Leaflet zoom control API for testing.


146-146: LGTM!

The test correctly verifies that the map is initialized with zoomControl: false, matching the implementation change.


438-470: LGTM!

The test suite comprehensively verifies share location button visibility across all scenarios: hidden by default, displayed when the map is unlocked, and absent when no callback is provided.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
frontend/__tests__/e2e/pages/ChapterDetails.spec.ts (1)

38-39: LGTM! Test correctly validates the unlock flow.

The test properly clicks the "Unlock map" button before asserting control visibility, aligning with the PR objective to hide controls until explicit user interaction.

Optional enhancement: Consider asserting that controls are NOT visible before unlocking to make the test more robust:

 await expect(page.locator('#chapter-map').locator('img').nth(1)).toBeVisible()

+await expect(page.getByRole('button', { name: 'Zoom in' })).not.toBeVisible()
+await expect(page.getByRole('button', { name: 'Zoom out' })).not.toBeVisible()
+await expect(page.getByRole('button', { name: 'Marker' })).not.toBeVisible()
+
 await page.getByRole('button', { name: 'Unlock map' }).click()
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 893122a and bdff238.

📒 Files selected for processing (1)
  • frontend/__tests__/e2e/pages/ChapterDetails.spec.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-17T17:30:42.139Z
Learnt from: anurag2787
Repo: OWASP/Nest PR: 2671
File: frontend/__tests__/unit/components/MultiSearch.test.tsx:169-171
Timestamp: 2025-11-17T17:30:42.139Z
Learning: In the OWASP/Nest frontend tests (PR #2671 context), wrapper functions like `expectChaptersCountEqualsThree` that simply call another helper with a fixed parameter (e.g., `expectChaptersCountEquals(3)`) are intentionally used to avoid arrow function callbacks in `waitFor` calls. This pattern prevents adding nesting depth that would trigger rule typescript:S2004. Example: `await waitFor(expectChaptersCountEqualsThree)` avoids the extra nesting from `await waitFor(() => expectChaptersCountEquals(3))`.

Applied to files:

  • frontend/__tests__/e2e/pages/ChapterDetails.spec.ts

@sonarqubecloud
Copy link

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shofikul-Isl4m works great 👍🏼
Thanks!

@kasya kasya added this pull request to the merge queue Dec 18, 2025
Merged via the queue into OWASP:main with commit 7a08db7 Dec 18, 2025
26 checks passed
Mr-Rahul-Paul pushed a commit to Mr-Rahul-Paul/Nest that referenced this pull request Jan 2, 2026
* hide map controls by default

* update e2e test

* add cleanup func and solve sonarcloud issue

* run make check-test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hide map controls by default

2 participants