Skip to content

test(query-core/onlineManager): add test for online status updates from window events#10886

Merged
sukvvon merged 1 commit into
mainfrom
test/query-core-online-manager-window-events
Jun 5, 2026
Merged

test(query-core/onlineManager): add test for online status updates from window events#10886
sukvvon merged 1 commit into
mainfrom
test/query-core-online-manager-window-events

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Jun 5, 2026

🎯 Changes

Adds a unit test for OnlineManager covering the default window event listeners: dispatching the browser offline and online events updates the online status accordingly.

The existing tests only assert that the listeners are registered/removed; this covers the listener callbacks actually reacting to the events.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Added a unit test that verifies the online/offline manager detects simulated network state changes.
    • Confirms the manager's reported status updates correctly when connectivity changes.
    • Ensures subscription listeners are properly removed during cleanup to prevent leaks.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7344ce38-798c-4a73-ad42-535adeab30e2

📥 Commits

Reviewing files that changed from the base of the PR and between 48db8fb and e2df09b.

📒 Files selected for processing (1)
  • packages/query-core/src/__tests__/onlineManager.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/query-core/src/tests/onlineManager.test.tsx

📝 Walkthrough

Walkthrough

Adds a unit test that subscribes to OnlineManager, dispatches window 'offline' and 'online' events, asserts isOnline() updates, and verifies unsubscribe() removes the listener.

Changes

OnlineManager Event Handling Test

Layer / File(s) Summary
OnlineManager event handling verification
packages/query-core/src/__tests__/onlineManager.test.tsx
Subscribes to OnlineManager, dispatches window offline and online events, asserts isOnline() reflects the changes, and verifies the subscription is cleaned up with unsubscribe().

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A test hops in, so tiny and neat,
It sends offline then online to feel the beat,
OnlineManager listens, then nods and sees,
The status updates quick with gentle ease,
Unsubscribe closes the loop — hop, complete!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and clearly describes the main change: adding a test for online status updates from window events in the OnlineManager module.
Description check ✅ Passed The description follows the repository template with all required sections completed: Changes section explains the test's purpose, Checklist items are properly marked, and Release Impact correctly identifies this as a dev-only change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 test/query-core-online-manager-window-events

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


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

@sukvvon sukvvon self-assigned this Jun 5, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jun 5, 2026

View your CI Pipeline Execution ↗ for commit 48db8fb

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 4m 42s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-05 13:40:27 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

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 `@packages/query-core/src/__tests__/onlineManager.test.tsx`:
- Around line 160-167: The test currently asserts offline state transition using
onlineManager.isOnline() which can be true even if the manager started offline;
make the assertion transition-based by first forcing a known online precondition
(dispatch a 'online' event and assert onlineManager.isOnline() === true or
assert the subscription listener was called), then subscribe via
onlineManager.subscribe(...) and dispatch 'offline', and finally assert that the
listener was invoked or that onlineManager.isOnline() === false; reference
onlineManager.subscribe and onlineManager.isOnline() to locate and update the
test accordingly.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5009e2fe-6ffc-4e9a-916c-0910c8a1d9e2

📥 Commits

Reviewing files that changed from the base of the PR and between 3270e09 and 48db8fb.

📒 Files selected for processing (1)
  • packages/query-core/src/__tests__/onlineManager.test.tsx

Comment thread packages/query-core/src/__tests__/onlineManager.test.tsx
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 5, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10886

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10886

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10886

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10886

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10886

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10886

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10886

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10886

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10886

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10886

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10886

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10886

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10886

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10886

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10886

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10886

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10886

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10886

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10886

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10886

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10886

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10886

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10886

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10886

commit: e2df09b

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

size-limit report 📦

Path Size
react full 12.11 KB (0%)
react minimal 9.08 KB (0%)

@sukvvon sukvvon force-pushed the test/query-core-online-manager-window-events branch from 48db8fb to e2df09b Compare June 5, 2026 13:34
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 5, 2026

Tip

For best results, initiate chat on the files or code changes.

@sukvvon That reasoning is solid — starting from a confirmed true via an explicit assertion (rather than a redundant setOnline(true)) is cleaner and makes the true → false → true flow self-documenting. The mutation-test verification is a great extra confidence check. Thanks for the thorough explanation!

@sukvvon sukvvon merged commit 92d9e2c into main Jun 5, 2026
9 checks passed
@sukvvon sukvvon deleted the test/query-core-online-manager-window-events branch June 5, 2026 13:46
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.

1 participant