Skip to content

Comments

Add tests for NavMenusViewModel#22577

Merged
nbradbury merged 45 commits intotrunkfrom
issue/menu-tests
Feb 12, 2026
Merged

Add tests for NavMenusViewModel#22577
nbradbury merged 45 commits intotrunkfrom
issue/menu-tests

Conversation

@nbradbury
Copy link
Contributor

@nbradbury nbradbury commented Feb 10, 2026

Summary

  • Add unit tests for NavMenusViewModel covering menu loading, pagination, navigation with cache lookups, reorder with cache sync, save/delete flows, linkable items, hierarchical sorting, and input sanitization
  • Add verify() calls to save/delete/reorder/linkable item tests to confirm correct REST client methods are invoked
  • Add tests for save/delete without selected site

Test plan

  • All NavMenusViewModelTest tests pass: ./gradlew :WordPress:testWordPressVanillaDebugUnitTest --tests "org.wordpress.android.ui.navmenus.NavMenusViewModelTest"

nbradbury and others added 30 commits February 5, 2026 06:12
Implements infinite scroll pagination for menu list, menu item list, and
linkable items dropdown with page size of 20. Shows loading spinner when
fetching more items.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix pagination not triggering after second page by properly tracking
  state changes in LaunchedEffect keys
- Remove inaccurate menu item count from menu list
- Remove unused fetchAllMenuItems function
- Move Edit Items button to end of menu card, centered vertically
- Fix detekt warnings: swallowed exceptions, unused imports, complexity
- Extract MenuItemListContent and sibling helper functions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The ExposedDropdownMenu doesn't support LazyColumn (SubcomposeLayout
intrinsic measurement issue), causing crashes when opening the dropdown.
This replaces it with a ModalBottomSheet which properly supports
pagination with LazyColumn.

Also restores PAGE_SIZE to 20 (was 5 for testing).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This resource was left over after removing the menu item count feature.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract duplicate type selection label logic to helper function
- Simplify parseErrorMessage by consolidating redundant cases
- Consolidate findPreviousSiblingIndex/findNextSiblingIndex into single function

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Prevents race conditions when multiple pagination requests occur in
rapid succession. Each pagination function now uses a mutex to ensure
atomic read-check-update operations, preventing duplicate items or
incorrect pagination state.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Ensure canLoadMore remains true when pagination fails, allowing users
to retry after transient errors (network issues, timeouts, etc.).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Prevents stale data from overwriting state when user rapidly switches
between menu item types.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Support all 22 protocols from wp_allowed_protocols(): http, https, ftp,
ftps, mailto, news, irc, irc6, ircs, gopher, nntp, feed, telnet, mms,
rtsp, sms, svn, tel, fax, xmpp, webcal, urn. Also adds support for
anchor links (#section) and protocol-relative URLs (//).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Derive offset from UI state instead of cache variables to avoid race
  conditions between initial load and pagination
- Set canLoadMore=true on initial load errors to allow retry

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Pre-compute parent-to-children mapping to reduce child lookup from O(n)
to O(1) per item, improving overall complexity from O(n²) to O(n log n).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use when expression to reduce return statements from 4 to 2.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add light and dark mode previews for MenuListScreen, MenuDetailScreen,
MenuItemListScreen, and MenuItemDetailScreen showing various states
including loading, empty, error, and populated views.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…-Android into issue/menus-compose-previews

Conflicts:
	WordPress/src/main/java/org/wordpress/android/ui/navmenus/screens/MenuItemDetailScreen.kt
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Restore onDismissRequest and reset showBottomSheet after hiding,
so users can dismiss by tapping the scrim or swiping down, and
the sheet is properly removed from composition after item selection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Sync currentMenuItems cache after successful reorder to prevent stale data
- Show error to user instead of silently returning on cache misses in navigation
- Add navigateTo() helper with null-check logging for navController
- Log JSON parsing failures in parseJsonStringArray() instead of silently swallowing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Sync currentMenuItems cache after successful reorder to prevent stale data
- Show error to user instead of silently returning on cache misses in navigation
- Add navigateTo() helper with null-check logging for navController
- Log JSON parsing failures in parseJsonStringArray() instead of silently swallowing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

� Conflicts:
�	WordPress/src/main/java/org/wordpress/android/ui/navmenus/NavMenusViewModel.kt
nbradbury and others added 2 commits February 10, 2026 08:10
Add 31 new tests covering menu loading, pagination, navigation cache
miss/hit, reorder with cache sync, save/delete success paths, linkable
items, hierarchical sorting, URL validation, and input sanitization.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add verify() calls to save/delete/reorder/linkable tests, fix fragile
loading state test, remove stale @Suppress, add missing-site tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nbradbury nbradbury changed the title Add comprehensive tests for NavMenusViewModel Add tests for NavMenusViewModel Feb 10, 2026
@dangermattic
Copy link
Collaborator

dangermattic commented Feb 10, 2026

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 10, 2026

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
FlavorJalapeno
Build TypeDebug
Versionpr22577-d6e831d
Build Number1484
Application IDcom.jetpack.android.prealpha
Commitd6e831d
Installation URL0eu2ntg87rgto
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 10, 2026

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
FlavorJalapeno
Build TypeDebug
Versionpr22577-d6e831d
Build Number1484
Application IDorg.wordpress.android.prealpha
Commitd6e831d
Installation URL7drg59cf9nu5o
Note: Google Login is not supported on these builds.

@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.50%. Comparing base (ea428b5) to head (d6e831d).
⚠️ Report is 1 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #22577      +/-   ##
==========================================
+ Coverage   38.17%   38.50%   +0.33%     
==========================================
  Files        2238     2238              
  Lines      111808   111808              
  Branches    15591    15591              
==========================================
+ Hits        42680    43051     +371     
+ Misses      65588    65174     -414     
- Partials     3540     3583      +43     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

nbradbury and others added 12 commits February 10, 2026 09:54
Merge title assertion into objectId test, remove duplicate https URL
validation test already covered by saveMenuItem succeeds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add navMenuItemType to buildMenuItemCreateParams and
buildMenuItemUpdateParams so the API receives the correct
item type (custom, post_type, taxonomy, post_type_archive).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous approach used mapTypeLabelToType() which matched against
hardcoded English display strings (e.g. "Page", "Post"). These labels
are localized by the WordPress API, so on non-English sites all items
would incorrectly map to TYPE_CUSTOM. Now uses the NavMenuItemType
enum from the API response directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace URL validation tests with normalization tests that verify
bare domains get https:// prepended while anchor links, relative
paths, and recognized protocols are preserved as-is.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nbradbury nbradbury marked this pull request as ready for review February 12, 2026 12:23
@nbradbury nbradbury requested a review from adalpari February 12, 2026 12:23
Copy link
Contributor

@adalpari adalpari left a comment

Choose a reason for hiding this comment

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

LGTM!

@sonarqubecloud
Copy link

@nbradbury nbradbury enabled auto-merge (squash) February 12, 2026 18:48
@nbradbury nbradbury merged commit 38fd782 into trunk Feb 12, 2026
24 checks passed
@nbradbury nbradbury deleted the issue/menu-tests branch February 12, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants