Skip to content

test(trayicon): widget tests for TrayIcon's parent-window plumbing#1477

Merged
annejan merged 2 commits into
mainfrom
tests/trayicon
May 13, 2026
Merged

test(trayicon): widget tests for TrayIcon's parent-window plumbing#1477
annejan merged 2 commits into
mainfrom
tests/trayicon

Conversation

@annejan
Copy link
Copy Markdown
Member

@annejan annejan commented May 13, 2026

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:

  • the parent pointer (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

Tests

Case What it asserts
`constructionStoresParent` Construction with a parent doesn't crash; `getIsAllocated()` returns a bool.
`showHideParentTogglesVisibility` `showHideParent()` round-trips shown → hidden → shown.
`iconActivatedTriggerTogglesVisibility` `Trigger` reason toggles parent (single-click / keyboard activation).
`iconActivatedDoubleClickTogglesVisibility` `DoubleClick` reason toggles parent (Windows users typically reach the tray this way).
`iconActivatedMiddleClickIsNoOp` Explicit middle-click branch leaves parent visibility alone.
`iconActivatedUnknownReasonIsNoOp` Default branch also a no-op (`Unknown` + `Context` both checked).
`getIsAllocatedMatchesPlatformTrayAvailability` `getIsAllocated()` mirrors `QSystemTrayIcon::isSystemTrayAvailable()`.

Test plan

  • `qmake6 -r && make -j4` clean
  • `tests/auto/trayicon/tst_trayicon` — 7/7 pass on Linux with system tray available
  • clang-format applied

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

  • Tests
    • Added a new TrayIcon unit test suite covering construction, tray activation behaviors, and parent window visibility toggling.
  • Chores
    • Registered several new automated test modules with the test runner.
    • Added a macOS test bundle template for tray icon tests.
    • Updated ignore rules to exclude the new test executable.

Review Change Stack

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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 710d547c-9b7a-4db6-8090-5cb5b563feab

📥 Commits

Reviewing files that changed from the base of the PR and between de3664d and 8fef587.

📒 Files selected for processing (1)
  • tests/auto/trayicon/tst_trayicon.cpp

📝 Walkthrough

Walkthrough

This 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.

Changes

TrayIcon Test Module Addition

Layer / File(s) Summary
TrayIcon unit tests
tests/auto/trayicon/tst_trayicon.cpp
Test suite covers constructor initialization and getIsAllocated() type validation; showHideParent() toggling parent QMainWindow visibility; iconActivated() toggling parent visibility for Trigger and DoubleClick activation reasons while verifying MiddleClick, Unknown, and Context are no-ops with explicit waits.
Test module build configuration and wiring
tests/auto/auto.pro, tests/auto/trayicon/trayicon.pro, tests/auto/trayicon/qtpass.plist, .gitignore
auto.pro adds trayicon and related test subdirectories to SUBDIRS; trayicon.pro configures qmake to include auto.pri, link libqtpass.a from src build output, set include paths and VPATH mappings, and apply win32-specific resource and linker settings; qtpass.plist provides macOS app bundle metadata template with build-time substitution placeholders; .gitignore excludes the test executable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A tiny test for the tray, all ready to run,
With clicks and toggles and checks one by one,
Fixtures and plist and qmake in tune,
The parent pops in and out like a tune,
Hooray for tests — they make bugs hop away!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: adding widget tests for TrayIcon's parent-window plumbing, which directly matches the test suite introduction and objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tests/trayicon

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
Copy Markdown
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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2b2d6d0 and de3664d.

📒 Files selected for processing (5)
  • .gitignore
  • tests/auto/auto.pro
  • tests/auto/trayicon/qtpass.plist
  • tests/auto/trayicon/trayicon.pro
  • tests/auto/trayicon/tst_trayicon.cpp

Comment thread tests/auto/trayicon/tst_trayicon.cpp Outdated
@coveralls
Copy link
Copy Markdown

coveralls commented May 13, 2026

Coverage Status

coverage: 32.144% (+0.3%) from 31.891% — tests/trayicon into main

… 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>
@annejan annejan merged commit bbc94a5 into main May 13, 2026
23 of 25 checks passed
@annejan annejan deleted the tests/trayicon branch May 13, 2026 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants