Skip to content

test: add unit tests for the useDeployments hook - #65

Merged
codxbrexx merged 1 commit into
metacall:masterfrom
mohdTahaRafi:test/use-deployments
Oct 29, 2026
Merged

codxbrexx merged 1 commit into
metacall:masterfrom
mohdTahaRafi:test/use-deployments

Conversation

@mohdTahaRafi

Copy link
Copy Markdown
Contributor

Description

Adds src/tests/unit/use_deployments_test.tsx with 10 tests for useDeployments, using fake timers and a controllable document.hidden:

  • first load, error message, the "Failed to fetch deployments" fallback, and aborted requests being ignored
  • polling on the interval while the tab is visible, and no polling while it's hidden
  • fetching again when the tab becomes visible, and on refetch()
  • keeping the last list when a poll fails, and clearing the error on the next success
  • aborting the request and stopping the timer on unmount

No app code changes. To check the tests actually catch regressions, I broke the hook four ways (polling while hidden, no visibility listener, not resetting the error, no abort on cleanup). Each one made exactly one test fail.

Test results: npm run unit is 152/152 (ran it three times to check the timer tests aren't flaky), and lint, format:check and typecheck pass. npm run test (Playwright) is 96/97. The one failure is dashboard.spec.ts:96, which also fails on master and is fixed in #61.

Fixes #64
Part of #20

Type of Change

  • fix: Bug fix (non-breaking change which fixes an issue)
  • feat: New feature (non-breaking change which adds functionality)
  • refactor: Code refactor (no functional changes, no API changes)
  • docs: Documentation update
  • test: Adding or updating tests
  • chore: Maintenance (CI, dependencies, tooling)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have linked the related issue above.
  • My code follows the coding standards of this project.
  • I have added tests that prove my fix is effective or my feature works.
  • New and existing tests pass locally (npm run unit and npm run test).
  • My changes generate no new lint warnings or errors (npm run lint).
  • My PR title follows Conventional Commits (e.g., fix: resolve login redirect).

Cover the first load, error handling, polling while the tab is visible,
pausing while it's hidden, refetching on visibility change and refetch(),
and cleanup on unmount.
Copilot AI balanced review requested due to automatic review settings October 27, 2026 00:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@codxbrexx
codxbrexx self-requested a review October 29, 2026 15:06
@codxbrexx

Copy link
Copy Markdown
Collaborator

@mohdTahaRafi! Great work on the comprehensive test coverage and regression checks!

Appreciate the effort!

@codxbrexx
codxbrexx merged commit 473d1e8 into metacall:master Oct 29, 2026
1 check passed
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.

[FEATURE] Add unit tests for the useDeployments hook

3 participants