[scanner] fix: add hook tests for web/src/hooks/mcp#19656
Conversation
Adds comprehensive test coverage for three previously untested hook files: - sharedImpl.types.test.ts: Tests for DATA_FIELDS, UI_FIELDS, and utility functions updatesTouchData() and updatesTouchUI() - kagent_crds.test.ts: Tests for useKagentCRDAgents, useKagentCRDTools, useKagentCRDModels, and useKagentCRDMemories hooks - kagenti.test.ts: Tests for useKagentiAgents, useKagentiBuilds, useKagentiCards, useKagentiTools, and useKagentiSummary hooks All tests follow established patterns from existing test files, using vitest and @testing-library/react-hooks for React hook testing. Fixes #19648 Signed-off-by: Copilot <copilot@users.noreply.github.com>
✅ Deploy Preview for kubestellarconsole ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
|
🐝 Hi @clubanderson! I'm Trusted users — org members and contributors with write access — can mention Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies. |
✅ Test Coverage CheckAll new source files in this PR have corresponding test files. Checked |
There was a problem hiding this comment.
Pull request overview
Adds unit test coverage for MCP-related hooks under web/src/hooks/mcp/, targeting previously untested modules and validating key behaviors (constants/utility helpers and useCache hook configuration) using Vitest and @testing-library/react.
Changes:
- Added tests for
sharedImpl.types.tsconstants and slice-detection helpers (updatesTouchData,updatesTouchUI). - Added tests for Kagenti hooks (
useKagenti*) including summary aggregation behavior. - Added tests for Kagent CRD hooks (
useKagentCRD*) validating cache keys, demo data wiring, enabled state, and return values.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| web/src/hooks/mcp/tests/sharedImpl.types.test.ts | Adds coverage for sharedImpl.types.ts field partitions and update-touch helpers. |
| web/src/hooks/mcp/tests/kagenti.test.ts | Adds coverage for Kagenti resource hooks and useKagentiSummary aggregation/refetch behavior. |
| web/src/hooks/mcp/tests/kagent_crds.test.ts | Adds coverage for Kagent CRD hooks and their useCache configuration. |
| * Covers the hooks for fetching Kagenti resources (agents, builds, cards, tools, summary). | ||
| */ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
| import { renderHook, waitFor } from '@testing-library/react' |
| * Covers the hooks for fetching Kagent CRD resources (agents, tools, models, memories). | ||
| */ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
| import { renderHook, waitFor } from '@testing-library/react' |
| import { | ||
| useKagentiAgents, | ||
| useKagentiBuilds, | ||
| useKagentiCards, | ||
| useKagentiTools, | ||
| useKagentiSummary, | ||
| type KagentiAgent, | ||
| type KagentiBuild, | ||
| type KagentiCard, | ||
| type KagentiTool, | ||
| type KagentiSummary, | ||
| } from '../kagenti' |
| // --------------------------------------------------------------------------- | ||
| // Guard against undefined arrays (issue #15569) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe('Array safety (issue #15569)', () => { | ||
| it('updatesTouchData guards against undefined DATA_FIELDS', () => { | ||
| // Even if DATA_FIELDS is somehow undefined, function should not crash | ||
| expect(() => updatesTouchData({ clusters: [] })).not.toThrow() | ||
| }) | ||
|
|
||
| it('updatesTouchUI guards against undefined UI_FIELDS', () => { | ||
| // Even if UI_FIELDS is somehow undefined, function should not crash | ||
| expect(() => updatesTouchUI({ isLoading: true })).not.toThrow() | ||
| }) | ||
| }) |
| * Covers the hooks for fetching Kagent CRD resources (agents, tools, models, memories). | ||
| */ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
| import { renderHook, waitFor } from '@testing-library/react' |
| * Covers the hooks for fetching Kagenti resources (agents, builds, cards, tools, summary). | ||
| */ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
| import { renderHook, waitFor } from '@testing-library/react' |
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
Fixes #19648
Adds comprehensive test coverage for three previously untested hook files in web/src/hooks/mcp:
Test Files Added
1. sharedImpl.types.test.ts
Tests for type definitions and utility functions:
2. kagent_crds.test.ts
Tests for Kagent CRD hooks:
3. kagenti.test.ts
Tests for Kagenti hooks:
Test Coverage
All tests follow established patterns from existing test files:
CI Validation
Build and lint validation will be handled by CI on this PR.