Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
84e9116
feat(entities): add timeline detail drawer
johallar Aug 13, 2026
d5deca5
refactor: use shadcn ui drawer
johallar Aug 13, 2026
a89e4d5
refactor: components for different bits of data, more useful timestamp
johallar Aug 13, 2026
087c296
refactor: consolidate on dataflowbar
johallar Aug 13, 2026
b2749a7
chore: use DataText for numbers/server data
johallar Aug 13, 2026
88aa2c6
refactor: extract positioned tooltip, use in fsmcapacity and timeline…
johallar Aug 13, 2026
a0e7a0c
chore: simplify position tracking
johallar Aug 13, 2026
36ba120
Merge branch 'main' into entities-detail-1
johallar Aug 19, 2026
4049e35
refactor: deselect entities if they are selected again
johallar Aug 19, 2026
b8864a3
Pass percentage instead of ms so bar fills up full width
cmatzenbach Aug 20, 2026
baf344d
generalize cap. chart component to select multiples caps, allow defau…
cmatzenbach Aug 20, 2026
0fd6455
Add unit tests for new fsmcapacitychart component
cmatzenbach Aug 20, 2026
625dec8
Add unit tests for entity details panel
cmatzenbach Aug 20, 2026
b17267a
fix: linting
cmatzenbach Aug 20, 2026
f65d283
fix: QuantitySpec type errors
cmatzenbach Aug 21, 2026
62f0f6f
fix: calculate shift from bigint bit length; update tests accordingly
cmatzenbach Aug 21, 2026
22f7694
fix: store settimeout handle and clear timer
cmatzenbach Aug 21, 2026
5af2cfb
fix: use cn for class generation
cmatzenbach Aug 21, 2026
74cac3d
fix: don't clear selection until gant click runs; add test
cmatzenbach Aug 21, 2026
4c4d1f7
Use shadcn select fields; add testing infra to test these components,…
cmatzenbach Aug 21, 2026
47dc413
Rename DataFlowBar to SegmentedBar and move to own directory, update …
cmatzenbach Aug 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/packages/@quent/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"@quent/client": "workspace:*",
"@quent/hooks": "workspace:*",
"@quent/utils": "workspace:*",
"d3-dag": "^1.2.1"
"d3-dag": "^1.2.1",
"vaul": "^1.1.2"
},
"peerDependencies": {
"@tanstack/react-query": "^5.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,386 @@
// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import type { FsmTransition, QuantitySpec } from '@quent/utils';
import { FsmCapacityChart } from './FsmCapacityChart';

// ECharts renders to canvas and is not testable in jsdom; stub it out.
vi.mock('echarts-for-react/lib/core', () => ({
default: () => <div data-testid="echarts" />,
}));

vi.mock('../lib/echarts', () => ({ echarts: {} }));
vi.mock('../lib/useChartResize', () => ({ useChartResize: () => ({ handleChartReady: vi.fn() }) }));
vi.mock('../timeline/timelineEchartsTheme', () => ({
useTimelineEchartsTheme: () => ({ themeName: 'light' }),
}));

// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------

function transition(
name: string,
timestamp: number,
usages: FsmTransition['usages'] = []
): FsmTransition {
return { name, timestamp, usages, attributes: [], derived_attributes: [] };
}

function usage(resource: string, caps: Record<string, bigint | null>): FsmTransition['usages'][0] {
return { resource, capacities: Object.entries(caps) };
}

const BYTES_SPEC = {
symbol: 'B',
singular: 'byte',
plural: 'bytes',
occupancy_prefix: 'Iec',
rate_prefix: 'Si',
} satisfies QuantitySpec;

const UNIT_SPEC = {
symbol: '',
singular: 'unit',
plural: 'units',
occupancy_prefix: 'None',
rate_prefix: 'None',
} satisfies QuantitySpec;

const RATE_SPEC = {
symbol: 'B/s',
singular: 'byte per second',
plural: 'bytes per second',
occupancy_prefix: 'Iec',
rate_prefix: 'Si',
} satisfies QuantitySpec;

const defaultProps = {
isDark: false,
resourceLabel: (id: string) => id,
quantitySpecs: { bytes: BYTES_SPEC, unit: UNIT_SPEC },
getCapacityDecl: () => undefined,
} as const;

// Two transitions are the minimum for a capacity to appear (≥2 readings).
const TWO_TRANSITIONS = [
transition('running', 0, [usage('mem-1', { capacity_bytes: 1024n })]),
transition('idle', 1, [usage('mem-1', { capacity_bytes: 2048n })]),
];

// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------

describe('FsmCapacityChart', () => {
describe('rendering', () => {
it('renders nothing when there are no transitions', () => {
const { container } = render(<FsmCapacityChart {...defaultProps} transitions={[]} />);
expect(container.firstChild).toBeNull();
});

it('renders nothing when all capacities have fewer than 2 readings', () => {
const transitions = [transition('running', 0, [usage('mem-1', { capacity_bytes: 1024n })])];
const { container } = render(
<FsmCapacityChart {...defaultProps} transitions={transitions} />
);
expect(container.firstChild).toBeNull();
});

it('renders the chart when at least one capacity has ≥2 readings', () => {
render(<FsmCapacityChart {...defaultProps} transitions={TWO_TRANSITIONS} />);
expect(screen.getByTestId('echarts')).toBeInTheDocument();
});

it('shows the capacity stat label in the header', () => {
const getCapacityDecl = (_id: string, name: string) =>
name === 'capacity_bytes'
? { name: 'capacity_bytes', kind: 'Occupancy' as const, quantity: 'bytes' }
: undefined;

render(
<FsmCapacityChart
{...defaultProps}
transitions={TWO_TRANSITIONS}
getCapacityDecl={getCapacityDecl}
/>
);

expect(screen.getByText('capacity_bytes (B)')).toBeInTheDocument();
});

it('shows the bare capacity name when its quantity has no symbol (dimensionless)', () => {
const getCapacityDecl = (_id: string, name: string) =>
name === 'unit'
? { name: 'unit', kind: 'Occupancy' as const, quantity: 'unit' }
: undefined;

const transitions = [
transition('running', 0, [usage('cpu-1', { unit: 1n })]),
transition('idle', 1, [usage('cpu-1', { unit: 1n })]),
];

render(
<FsmCapacityChart
{...defaultProps}
transitions={transitions}
getCapacityDecl={getCapacityDecl}
/>
);

expect(screen.getByText('unit')).toBeInTheDocument();
});
});

describe('resource selector', () => {
it('hides the resource selector when only one resource has data', () => {
render(<FsmCapacityChart {...defaultProps} transitions={TWO_TRANSITIONS} />);
expect(screen.queryByRole('combobox', { name: 'Select resource' })).not.toBeInTheDocument();
});

it('shows the resource selector when multiple resources have data', () => {
const transitions = [
transition('running', 0, [
usage('mem-1', { capacity_bytes: 1024n }),
usage('cpu-1', { unit: 1n }),
]),
transition('idle', 1, [
usage('mem-1', { capacity_bytes: 2048n }),
usage('cpu-1', { unit: 1n }),
]),
];

render(
<FsmCapacityChart
{...defaultProps}
resourceLabel={id => (id === 'mem-1' ? 'Memory' : 'CPU')}
transitions={transitions}
/>
);

expect(screen.getByRole('combobox', { name: 'Select resource' })).toBeInTheDocument();
});

it('lists all resources with data in the resource selector', () => {
const transitions = [
transition('running', 0, [
usage('mem-1', { capacity_bytes: 1024n }),
usage('cpu-1', { unit: 1n }),
]),
transition('idle', 1, [
usage('mem-1', { capacity_bytes: 2048n }),
usage('cpu-1', { unit: 1n }),
]),
];

render(
<FsmCapacityChart
{...defaultProps}
resourceLabel={id => (id === 'mem-1' ? 'Memory' : 'CPU')}
transitions={transitions}
/>
);

const select = screen.getByRole('combobox', { name: 'Select resource' });
const options = Array.from(select.querySelectorAll('option')).map(o => o.textContent);
expect(options).toContain('Memory');
expect(options).toContain('CPU');
});
});

describe('capacity selector', () => {
it('hides the capacity selector when the active resource has only one capacity', () => {
render(<FsmCapacityChart {...defaultProps} transitions={TWO_TRANSITIONS} />);
expect(screen.queryByRole('combobox', { name: 'Select capacity' })).not.toBeInTheDocument();
});

it('shows the capacity selector when the active resource has multiple capacities', () => {
const transitions = [
transition('running', 0, [usage('mem-1', { capacity_bytes: 1024n, unit: 1n })]),
transition('idle', 1, [usage('mem-1', { capacity_bytes: 2048n, unit: 1n })]),
];

render(<FsmCapacityChart {...defaultProps} transitions={transitions} />);

expect(screen.getByRole('combobox', { name: 'Select capacity' })).toBeInTheDocument();
});

it('lists all capacities for the active resource', () => {
const transitions = [
transition('running', 0, [usage('mem-1', { capacity_bytes: 1024n, unit: 1n })]),
transition('idle', 1, [usage('mem-1', { capacity_bytes: 2048n, unit: 1n })]),
];

render(<FsmCapacityChart {...defaultProps} transitions={transitions} />);

const select = screen.getByRole('combobox', { name: 'Select capacity' });
const options = Array.from(select.querySelectorAll('option')).map(o => o.value);
expect(options).toContain('capacity_bytes');
expect(options).toContain('unit');
});

it('resets the capacity selection when the resource changes', () => {
const getCapacityDecl = (_id: string, name: string) => {
if (name === 'capacity_bytes')
return { name: 'capacity_bytes', kind: 'Occupancy' as const, quantity: 'bytes' };
if (name === 'rate_bytes')
return { name: 'rate_bytes', kind: 'Rate' as const, quantity: 'rate' };
return undefined;
};

const transitions = [
transition('running', 0, [
usage('mem-1', { capacity_bytes: 1024n }),
usage('fs-1', { capacity_bytes: 512n, rate_bytes: 100n }),
]),
transition('idle', 1, [
usage('mem-1', { capacity_bytes: 2048n }),
usage('fs-1', { capacity_bytes: 1024n, rate_bytes: 200n }),
]),
];

render(
<FsmCapacityChart
{...defaultProps}
resourceLabel={id => (id === 'mem-1' ? 'Memory' : 'Filesystem')}
quantitySpecs={{ bytes: BYTES_SPEC, rate: RATE_SPEC }}
getCapacityDecl={getCapacityDecl}
transitions={transitions}
/>
);

// Switch to Filesystem and select rate_bytes
const resourceSelect = screen.getByRole('combobox', { name: 'Select resource' });
fireEvent.change(resourceSelect, { target: { value: 'fs-1' } });

const capacitySelect = screen.getByRole('combobox', { name: 'Select capacity' });
fireEvent.change(capacitySelect, { target: { value: 'rate_bytes' } });
expect(screen.getByText('rate_bytes (B/s)')).toBeInTheDocument();

// Switch back to Memory — capacity should reset to its first capacity
fireEvent.change(resourceSelect, { target: { value: 'mem-1' } });
expect(screen.getByText('capacity_bytes (B)')).toBeInTheDocument();
});
});

describe('defaultCapacityPredicate', () => {
it('defaults to the first capacity when no predicate is provided', () => {
// unit appears before capacity_bytes in insertion order
const transitions = [
transition('running', 0, [usage('mem-1', { unit: 1n, capacity_bytes: 1024n })]),
transition('idle', 1, [usage('mem-1', { unit: 1n, capacity_bytes: 2048n })]),
];

render(<FsmCapacityChart {...defaultProps} transitions={transitions} />);

// Without a predicate, insertion order wins — unit is first
expect(screen.getByText('unit', { selector: 'span' })).toBeInTheDocument();
});

it('sorts the preferred capacity to the front when a predicate is provided', () => {
const getCapacityDecl = (_id: string, name: string) =>
name === 'capacity_bytes'
? { name: 'capacity_bytes', kind: 'Occupancy' as const, quantity: 'bytes' }
: undefined;

// unit is inserted before capacity_bytes
const transitions = [
transition('running', 0, [usage('mem-1', { unit: 1n, capacity_bytes: 1024n })]),
transition('idle', 1, [usage('mem-1', { unit: 1n, capacity_bytes: 2048n })]),
];

render(
<FsmCapacityChart
{...defaultProps}
transitions={transitions}
getCapacityDecl={getCapacityDecl}
defaultCapacityPredicate={name => name === 'capacity_bytes'}
/>
);

// Predicate pushes capacity_bytes to front — it becomes the default
expect(screen.getByText('capacity_bytes (B)')).toBeInTheDocument();
});

it('sorts resources with the preferred capacity to the front', () => {
const transitions = [
transition('running', 0, [
usage('cpu-1', { unit: 1n }),
usage('mem-1', { capacity_bytes: 1024n }),
]),
transition('idle', 1, [
usage('cpu-1', { unit: 1n }),
usage('mem-1', { capacity_bytes: 2048n }),
]),
];

render(
<FsmCapacityChart
{...defaultProps}
resourceLabel={id => (id === 'mem-1' ? 'Memory' : 'CPU')}
transitions={transitions}
defaultCapacityPredicate={name => name === 'capacity_bytes'}
/>
);

// Memory (with capacity_bytes) should be the active resource by default
const resourceSelect = screen.getByRole('combobox', { name: 'Select resource' });
expect((resourceSelect as HTMLSelectElement).value).toBe('mem-1');
});
});

describe('entity change', () => {
it('resets selections when transitions change', () => {
const getCapacityDecl = (_id: string, name: string) =>
name === 'capacity_bytes'
? { name: 'capacity_bytes', kind: 'Occupancy' as const, quantity: 'bytes' }
: undefined;

const firstTransitions = [
transition('running', 0, [
usage('mem-1', { capacity_bytes: 1024n }),
usage('mem-2', { capacity_bytes: 512n }),
]),
transition('idle', 1, [
usage('mem-1', { capacity_bytes: 2048n }),
usage('mem-2', { capacity_bytes: 1024n }),
]),
];

const { rerender } = render(
<FsmCapacityChart
{...defaultProps}
resourceLabel={id => id}
getCapacityDecl={getCapacityDecl}
transitions={firstTransitions}
/>
);

// Select the second resource
const resourceSelect = screen.getByRole('combobox', { name: 'Select resource' });
fireEvent.change(resourceSelect, { target: { value: 'mem-2' } });
expect((resourceSelect as HTMLSelectElement).value).toBe('mem-2');

// Simulate opening a different entity (new transitions reference)
const secondTransitions = [
transition('running', 0, [usage('mem-1', { capacity_bytes: 1024n })]),
transition('idle', 1, [usage('mem-1', { capacity_bytes: 2048n })]),
];

rerender(
<FsmCapacityChart
{...defaultProps}
resourceLabel={id => id}
getCapacityDecl={getCapacityDecl}
transitions={secondTransitions}
/>
);

// Resource selector should be gone (only one resource) and mem-1 is active
expect(screen.queryByRole('combobox', { name: 'Select resource' })).not.toBeInTheDocument();
expect(screen.getByText('capacity_bytes (B)')).toBeInTheDocument();
});
});
});
Loading