Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 57 additions & 0 deletions src/components/Inspector.instances.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// @vitest-environment jsdom
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { act } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { Inspector } from './Inspector';
import { makeNode } from '../sim/presets';
import type { NodeKind } from '../sim/types';

/**
* The inspector only renders fields that belong to one of its groups, so a
* field listed for a kind but left out of every group is silently dropped.
* `instances` was, which left scaling out unreachable from the panel even
* though the engine, the canvas badge and the autoscaler all honour it.
*/

let container: HTMLDivElement;
let root: Root;

beforeEach(() => {
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT =
true;
container = document.createElement('div');
document.body.appendChild(container);
root = createRoot(container);
});

afterEach(() => {
act(() => root.unmount());
container.remove();
document.body.innerHTML = '';
});

function fieldLabels(kind: NodeKind): string[] {
act(() =>
root.render(
<Inspector
node={makeNode(kind, 0, 0)}
stats={null}
onChange={() => {}}
onDelete={() => {}}
onRename={() => {}}
/>,
),
);
return [...container.querySelectorAll('label')].map(
(l) => l.textContent?.trim() ?? '',
);
}

describe('the instances field in the inspector', () => {
it.each<NodeKind>(['service', 'db', 'cache', 'lb', 'worker'])(
'is editable on a %s',
(kind) => {
expect(fieldLabels(kind)).toContain('Instances');
},
);
});
8 changes: 7 additions & 1 deletion src/components/Inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,13 @@ const FIELD_GROUPS: { title: string; fields: ReadonlySet<Field> }[] = [
},
{
title: 'How much it can handle',
fields: new Set<Field>(['capacity', 'serviceMs', 'serviceCv', 'queueLimit']),
fields: new Set<Field>([
'instances',
'capacity',
'serviceMs',
'serviceCv',
'queueLimit',
]),
},
{
title: 'When things go wrong',
Expand Down