test(trayicon): widget tests for TrayIcon's parent-window plumbing#1477
Conversation
TrayIcon wraps QSystemTrayIcon and routes activation events back to its parent QMainWindow. Most of the QSystemTrayIcon side only initialises when the platform reports `isSystemTrayAvailable()` — on a headless CI (offscreen platform) that's typically false, so the menu / icon setup path is largely unreachable in unit tests. What IS reachable regardless of tray availability: - parent pointer is always stored (set in the constructor body before the isSystemTrayAvailable() check); - showHideParent() operates on the parent directly; - iconActivated() dispatches on the enum and only calls showHideParent for Trigger / DoubleClick — other branches must be no-ops. Seven tests covering those paths: - constructionStoresParent: smoke (doesn't crash, returns a bool from getIsAllocated). - showHideParentTogglesVisibility: shown -> hidden -> shown round-trip. - iconActivatedTriggerTogglesVisibility: Trigger toggles parent visibility (single-click / keyboard activation on most platforms). - iconActivatedDoubleClickTogglesVisibility: DoubleClick toggles (Windows users typically reach the tray this way). - iconActivatedMiddleClickIsNoOp: explicit middle-click branch is a no-op. - iconActivatedUnknownReasonIsNoOp: default branch is also a no-op (Unknown + Context). - getIsAllocatedMatchesPlatformTrayAvailability: getIsAllocated() mirrors QSystemTrayIcon::isSystemTrayAvailable(). Build clean, 7/7 tests pass on Linux with system tray available. Wired into tests/auto/auto.pro SUBDIRS and .gitignore. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds a new TrayIcon unit test module to QtPass. The test suite validates TrayIcon initialization, parent window visibility toggling, system tray icon activation behavior, and allocation state consistency. Full qmake build configuration and test fixtures support the new test module integration. ChangesTrayIcon Test Module Addition
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/auto/trayicon/tst_trayicon.cpp`:
- Line 85: Replace the bare QTRY_VERIFY(...) visibility checks with
QTRY_VERIFY2(..., "<descriptive message>") so failures show context;
specifically update the calls that read QTRY_VERIFY(parent.isVisible()) (and the
similar QTRY_VERIFY(...) occurrences at the other three visibility checks) to
use QTRY_VERIFY2(parent.isVisible(), "parent should be visible after <action>")
or an equivalent message describing the expected state and the triggering action
so CI logs are diagnosable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro
Run ID: 623a730c-c631-4118-b8d3-91711c2caa55
📒 Files selected for processing (5)
.gitignoretests/auto/auto.protests/auto/trayicon/qtpass.plisttests/auto/trayicon/trayicon.protests/auto/trayicon/tst_trayicon.cpp
… checks CodeRabbit nit on #1477: the four QTRY_VERIFY(parent.isVisible()) calls inside the iconActivated* tests don't say what they're checking. Switch to QTRY_VERIFY2 with a "parent must be visible after show()" message, matching the existing line-66 style. No behavioural change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
`TrayIcon` had zero test coverage. This is the second new dialog/widget test subdir post-security-review (after #1476 KeygenDialog) — same scaffold, same dir-per-class pattern as `importkeydialog/` and `keygendialog/`.
What's testable here
`TrayIcon` wraps `QSystemTrayIcon` and routes activation events back to its parent `QMainWindow`. Most of the `QSystemTrayIcon` side only initialises when the platform reports `isSystemTrayAvailable()` — on a headless CI (offscreen platform) that's typically false, so the menu / icon setup path is largely unreachable in unit tests.
What IS reachable regardless of tray availability:
Tests
Test plan
Noise
Test output shows `QSystemTrayIcon::setVisible: No Icon set` warnings on platforms where the tray is available. The icon comes from `:/artwork/icon.png` (a qrc resource) which isn't linked into the test binary. Production has the qrc embedded. The warnings are informational, don't fail any test, and would suppress to nothing on headless CI where `isSystemTrayAvailable()` is false. Not addressing in this PR.
🤖 Generated with Claude Code
Summary by CodeRabbit