[scanner] fix: add tests for cluster utility components#19243
Conversation
…Grid.common, DragReorder, TokenRefresh) Signed-off-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+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 |
|
🐝 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. |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
✅ 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/updates Vitest + React Testing Library unit tests intended to cover small cluster utility components (auth badges, token refresh helpers, drag reorder wrapper, and ClusterGrid common utilities) as requested in #19240 / #18599.
Changes:
- Expands
ClusterTokenRefreshtest coverage foruseClusterRefreshSpin,isTokenExpired,getIAMRefreshHint, andCopyCommandButton. - Reworks
ClusterDragReordertests and introduces new@dnd-kitmocks. - Adds a new
ClusterGrid.commonutilities test suite undercomponents/__tests__.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| web/src/components/clusters/components/ClusterTokenRefresh.test.tsx | Updates tests for refresh spin hook, IAM hint helpers, and clipboard copy UI behavior. |
| web/src/components/clusters/components/ClusterDragReorder.test.tsx | Reworks DnD mocking and rendering assertions for drag-reorder wrapper + sortable item. |
| web/src/components/clusters/components/ClusterAuthBadges.test.tsx | Adds/adjusts tests for auth badges and IAM refresh hint rendering paths. |
| web/src/components/clusters/components/tests/ClusterGrid.common.test.tsx | Introduces a new utilities test file for ClusterGrid.common helpers (duplicates an existing adjacent test file). |
| vi.mock('@dnd-kit/core', () => { | ||
| const actualCore = vi.importActual('@dnd-kit/core') | ||
| return { | ||
| ...actualCore, | ||
| DndContext: ({ children, onDragEnd }: { children: React.ReactNode; onDragEnd?: (event: DragEndEvent) => void }) => { | ||
| // Expose onDragEnd for testing via data attribute | ||
| return <div data-testid="dnd-context" data-ondragend={onDragEnd ? 'present' : 'absent'}>{children}</div> | ||
| }, | ||
| useSensor: vi.fn(), | ||
| useSensors: vi.fn(() => []), | ||
| PointerSensor: vi.fn(), | ||
| KeyboardSensor: vi.fn(), | ||
| closestCenter: vi.fn(), | ||
| } | ||
| }) |
| vi.mock('@dnd-kit/sortable', () => { | ||
| const actualSortable = vi.importActual('@dnd-kit/sortable') | ||
| return { | ||
| ...actualSortable, | ||
| SortableContext: ({ children }: { children: React.ReactNode }) => <div data-testid="sortable-context">{children}</div>, |
| it('renders children inside DndContext and SortableContext', () => { | ||
| render( | ||
| <ClusterDragReorder clusters={mockClusters} layoutMode="grid" onReorder={vi.fn()}> | ||
| <div data-testid="child">content</div> | ||
| <ClusterDragReorder clusters={mockClusters} layoutMode="grid" onReorder={mockOnReorder}> | ||
| <div data-testid="test-child">Test Content</div> | ||
| </ClusterDragReorder>, | ||
| ) | ||
|
|
||
| expect(screen.getByTestId('dnd-context')).toBeInTheDocument() | ||
| expect(screen.getByTestId('sortable-context')).toBeInTheDocument() | ||
| expect(screen.getByTestId('child')).toBeInTheDocument() | ||
| expect(lastDragEndHandler).toBeTypeOf('function') | ||
| expect(screen.getByTestId('test-child')).toBeInTheDocument() | ||
| }) |
| import { describe, it, expect, vi } from 'vitest' | ||
| import { render, screen, fireEvent } from '@testing-library/react' | ||
| import { RemoveClusterButton, ActionTooltipWrapper, handleCardKeyDown } from '../ClusterGrid.common' | ||
|
|
||
| vi.mock('react-i18next', () => ({ | ||
| initReactI18next: { type: '3rdParty', init: () => {} }, | ||
| useTranslation: () => ({ t: (key: string) => key }), | ||
| })) |
| const { container } = render( | ||
| <div onClick={parentClick} onKeyDown={handleKeyDown} role="button" tabIndex={0}> | ||
| <CopyCommandButton text="test" /> | ||
| </div>, | ||
| ) |
|
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 Verification: failedCommit: |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
Fixes #19240
Adds test coverage for 4 small cluster utility components that were identified as lacking tests:
Part of #18599