-
Notifications
You must be signed in to change notification settings - Fork 1
fix: render SOVD resources for nested entity types #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| // Copyright 2026 bburda | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
| import { render, screen, waitFor } from '@testing-library/react'; | ||
| import { EntityDetailPanel } from './EntityDetailPanel'; | ||
|
|
||
| // Mock heavy child components - we only care about the top-level routing | ||
| // (header + tab bar + tab content selection) for these tests. | ||
| vi.mock('@/components/DataPanel', () => ({ DataPanel: () => <div data-testid="data-panel" /> })); | ||
| vi.mock('@/components/ConfigurationPanel', () => ({ ConfigurationPanel: () => <div data-testid="config-panel" /> })); | ||
| vi.mock('@/components/OperationsPanel', () => ({ OperationsPanel: () => <div data-testid="ops-panel" /> })); | ||
| vi.mock('@/components/AreasPanel', () => ({ AreasPanel: () => <div data-testid="areas-panel" /> })); | ||
| vi.mock('@/components/AppsPanel', () => ({ AppsPanel: () => <div data-testid="apps-panel" /> })); | ||
| vi.mock('@/components/FunctionsPanel', () => ({ FunctionsPanel: () => <div data-testid="functions-panel" /> })); | ||
| vi.mock('@/components/ServerInfoPanel', () => ({ ServerInfoPanel: () => <div data-testid="server-panel" /> })); | ||
| vi.mock('@/components/FaultsDashboard', () => ({ FaultsDashboard: () => <div data-testid="faults-dashboard" /> })); | ||
| vi.mock('@/components/UpdatesDashboard', () => ({ UpdatesDashboard: () => <div data-testid="updates-dashboard" /> })); | ||
| vi.mock('@/components/EmptyState', () => ({ EmptyState: () => <div data-testid="empty-state" /> })); | ||
| vi.mock('@/components/EntityDetailSkeleton', () => ({ EntityDetailSkeleton: () => <div data-testid="skeleton" /> })); | ||
| vi.mock('@/components/ResourceTabs', async () => { | ||
| const actual = await vi.importActual<typeof import('./ResourceTabs')>('@/components/ResourceTabs'); | ||
| return { | ||
| ...actual, | ||
| renderResourceTabContent: (tab: string) => <div data-testid={`tab-content-${tab}`} />, | ||
| }; | ||
| }); | ||
|
|
||
| const mockPrefetchResourceCounts = vi.fn(); | ||
| const mockFetchEntityData = vi.fn(); | ||
| const mockSelectEntity = vi.fn(); | ||
| const mockRefreshSelectedEntity = vi.fn(); | ||
|
|
||
| let storeState: Record<string, unknown> = {}; | ||
|
|
||
| vi.mock('@/lib/store', () => ({ | ||
| useAppStore: vi.fn((selector: (s: Record<string, unknown>) => unknown) => selector(storeState)), | ||
| // The breadcrumb builder resolves segment types via findNode; these tests | ||
| // don't load a tree, so it always falls back to position-based inference. | ||
| findNode: () => null, | ||
| })); | ||
|
|
||
| function setStore(overrides: Record<string, unknown>) { | ||
| storeState = { | ||
| selectedPath: null, | ||
| selectedEntity: null, | ||
| rootEntities: [], | ||
| isLoadingDetails: false, | ||
| isRefreshing: false, | ||
| isConnected: true, | ||
| selectEntity: mockSelectEntity, | ||
| refreshSelectedEntity: mockRefreshSelectedEntity, | ||
| prefetchResourceCounts: mockPrefetchResourceCounts, | ||
| fetchEntityData: mockFetchEntityData, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe('EntityDetailPanel - nested entity types', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mockPrefetchResourceCounts.mockResolvedValue({ data: 0, operations: 0, configurations: 0, faults: 0, logs: 0 }); | ||
| mockFetchEntityData.mockResolvedValue([]); | ||
| }); | ||
|
|
||
| it('renders resource tabs and fetches counts as components for subcomponent entity', async () => { | ||
| setStore({ | ||
| selectedPath: '/server/area1/component1/planning-ecu', | ||
| selectedEntity: { | ||
| id: 'planning-ecu', | ||
| name: 'planning-ecu', | ||
| type: 'subcomponent', | ||
| }, | ||
| }); | ||
|
|
||
| render(<EntityDetailPanel onConnectClick={() => {}} />); | ||
|
|
||
| // Bug repro: subcomponent should fetch resource counts using the | ||
| // 'components' entity type (gateway routes subcomponents through | ||
| // /api/v1/components/{id}/...). | ||
| await waitFor(() => { | ||
| expect(mockPrefetchResourceCounts).toHaveBeenCalledWith('components', 'planning-ecu', expect.anything()); | ||
| }); | ||
|
|
||
| // Bug repro: subcomponent should render the resource tab bar | ||
| // (Data / Operations / Config / Faults / Logs) just like a component. | ||
| expect(screen.getByRole('button', { name: /Data/ })).toBeInTheDocument(); | ||
| expect(screen.getByRole('button', { name: /Operations/ })).toBeInTheDocument(); | ||
| expect(screen.getByRole('button', { name: /Config/ })).toBeInTheDocument(); | ||
| expect(screen.getByRole('button', { name: /Faults/ })).toBeInTheDocument(); | ||
| expect(screen.getByRole('button', { name: /Logs/ })).toBeInTheDocument(); | ||
|
|
||
| // The fallback "No detailed information available" must not appear. | ||
| expect(screen.queryByText(/No detailed information available/i)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders the area panel and fetches counts as areas for subarea entity', async () => { | ||
| setStore({ | ||
| selectedPath: '/server/area1/zone-a', | ||
| selectedEntity: { | ||
| id: 'zone-a', | ||
| name: 'zone-a', | ||
| type: 'subarea', | ||
| }, | ||
| }); | ||
|
|
||
| render(<EntityDetailPanel onConnectClick={() => {}} />); | ||
|
|
||
| // Bug repro: subarea should fetch resource counts using the 'areas' | ||
| // entity type (gateway routes subareas through /api/v1/areas/{id}/...). | ||
| await waitFor(() => { | ||
| expect(mockPrefetchResourceCounts).toHaveBeenCalledWith('areas', 'zone-a', expect.anything()); | ||
| }); | ||
|
|
||
| // Bug repro: subarea should render the area panel just like an area, | ||
| // not the "No detailed information available" fallback. | ||
| expect(screen.getByTestId('areas-panel')).toBeInTheDocument(); | ||
| expect(screen.queryByText(/No detailed information available/i)).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.