Skip to content

test(query-devtools/utils): add tests for 'getQueryStatusLabel'#10671

Merged
sukvvon merged 1 commit intomainfrom
test/query-devtools-get-query-status-label
May 9, 2026
Merged

test(query-devtools/utils): add tests for 'getQueryStatusLabel'#10671
sukvvon merged 1 commit intomainfrom
test/query-devtools-get-query-status-label

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented May 9, 2026

🎯 Changes

Add unit tests for the getQueryStatusLabel helper in query-devtools/utils.tsx.

The helper maps a Query to one of five status labels (fetching, inactive, paused, stale, fresh) used to summarize each entry in the devtools panel.

Cases:

  • 'fetching' when fetchStatus is 'fetching'
  • 'inactive' when there are no observers
  • 'paused' when fetchStatus is 'paused' and there are observers
  • 'paused' even when stale if fetchStatus is 'paused' (guards the 'paused'-over-isStale precedence)
  • 'stale' when the query is idle, has observers, and is stale
  • 'fresh' when the query is idle, has observers, and is not stale

For the stale-driven cases the test attaches an enabled: true QueryObserver with staleTime: 0, then forces fetchStatus and dataUpdatedAt: 0 via setState so query.isStale() resolves to true. Each test uses real Query and QueryObserver instances, mirroring the pattern used by the existing sortFns suite. queryClient.clear() runs in afterEach to keep tests isolated.

✅ 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 comprehensive test coverage for the query-status labeling utility, validating outputs across fetch states (fetching, inactive, paused, stale, fresh) and observer scenarios (with and without observers).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 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: b7e6e3e7-f7c7-47de-8183-15b93b3e20d6

📥 Commits

Reviewing files that changed from the base of the PR and between d1a5c70 and 6e36ef5.

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

📝 Walkthrough

Walkthrough

The PR adds test coverage for the getQueryStatusLabel utility in query-devtools: imports updated to include the function and QueryKey, helpers to construct Query instances and observers, and a test suite asserting labels across fetching, paused/inactive, stale, and fresh states.

Changes

Query Status Label Test Coverage

Layer / File(s) Summary
Import Updates
packages/query-devtools/src/__tests__/utils.test.ts
Added getQueryStatusLabel to the import from ../utils and QueryKey type from @tanstack/query-core.
Test Helpers / Setup
packages/query-devtools/src/__tests__/utils.test.ts
Local helpers to build Query instances, optionally attach QueryObserver, and QueryClient setup/cleanup.
Test Cases
packages/query-devtools/src/__tests__/utils.test.ts
New test suite with cases for "fetching", observer-dependent "inactive" vs "paused", paused-stale behavior, and "stale" vs "fresh" when idle with observers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

package: query-devtools

Poem

🐰 Hops through the tests with fervent glee,
Status labels now verified with care,
Query states dance from A to Z,
Each fetch, each pause, we declare—
Coverage blooms, the tests all fair! 🌸

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding tests for the getQueryStatusLabel function in query-devtools utilities.
Description check ✅ Passed The description provides comprehensive details about the changes, test cases covered, implementation approach, and completes all checklist items appropriately.
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-devtools-get-query-status-label

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 9, 2026

View your CI Pipeline Execution ↗ for commit d1a5c70

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

☁️ Nx Cloud last updated this comment at 2026-05-09 04:23:18 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 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-devtools/src/__tests__/utils.test.ts`:
- Around line 1304-1371: Add a test covering the missing "stale" branch in
getQueryStatusLabel: create a Query via buildQuery with fetchStatus: 'idle',
some data, an old dataUpdatedAt (or explicitly set isStale: true) to mark it
stale, subscribe an observer using addObserver, and assert
expect(getQueryStatusLabel(query)).toBe('stale'); ensure you unsubscribe in a
finally block exactly like the other observer-based tests (use
QueryClient/QueryObserver helpers already in the file).
🪄 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: 900deedd-77fe-45d7-a4f4-02c7ba4b6b90

📥 Commits

Reviewing files that changed from the base of the PR and between abad6f0 and d1a5c70.

📒 Files selected for processing (1)
  • packages/query-devtools/src/__tests__/utils.test.ts

Comment thread packages/query-devtools/src/__tests__/utils.test.ts
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 9, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 6e36ef5

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

size-limit report 📦

Path Size
react full 12.1 KB (0%)
react minimal 9.07 KB (0%)

@sukvvon sukvvon force-pushed the test/query-devtools-get-query-status-label branch from d1a5c70 to 6e36ef5 Compare May 9, 2026 04:18
@sukvvon sukvvon merged commit 64d0b89 into main May 9, 2026
8 checks passed
@sukvvon sukvvon deleted the test/query-devtools-get-query-status-label branch May 9, 2026 04:23
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.

1 participant