fix particle analysis table units and load image missing channels

This commit is contained in:
2026-03-27 20:37:06 -07:00
parent bc0c25085d
commit 160f714bad
10 changed files with 510 additions and 183 deletions

View File

@@ -0,0 +1,40 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
beginTrackedNodeRequest,
isTrackedNodeRequestCurrent,
resolveLoadNodeChannelPath,
} from '../src/loadNodeOutputs.js';
test('resolveLoadNodeChannelPath can resolve a new ImageDemo node from its explicit selection before mount', () => {
const resolvedPath = resolveLoadNodeChannelPath({
explicitPath: 'APL_Figure4.ibw',
className: '',
widgetValues: {},
});
assert.equal(resolvedPath, 'APL_Figure4.ibw');
});
test('resolveLoadNodeChannelPath falls back to the current widget value for load nodes', () => {
assert.equal(resolveLoadNodeChannelPath({
className: 'Image',
widgetValues: { filename: 'scan.ibw' },
}), 'scan.ibw');
assert.equal(resolveLoadNodeChannelPath({
className: 'ImageDemo',
widgetValues: { name: 'demo.ibw' },
}), 'demo.ibw');
});
test('tracked load-node requests ignore stale async responses', () => {
const requestVersions = new Map();
const first = beginTrackedNodeRequest(requestVersions, '42');
const second = beginTrackedNodeRequest(requestVersions, '42');
assert.equal(isTrackedNodeRequestCurrent(requestVersions, '42', first), false);
assert.equal(isTrackedNodeRequestCurrent(requestVersions, '42', second), true);
});

View File

@@ -0,0 +1,52 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
buildCombinedInputNameByWidgetName,
getWidgetCombinedInputName,
} from '../src/nodeWidgetLayout.js';
test('getWidgetCombinedInputName pairs same-label hide_when_input_connected widgets with their matching input', () => {
const dataInputByName = new Map([
['colormap_map', { name: 'colormap_map', type: 'COLORMAP', label: 'colormap' }],
]);
const combinedInputName = getWidgetCombinedInputName({
name: 'colormap',
opts: { hide_when_input_connected: 'colormap_map' },
}, dataInputByName);
assert.equal(combinedInputName, 'colormap_map');
});
test('getWidgetCombinedInputName leaves unrelated hidden inputs as standalone rows', () => {
const dataInputByName = new Map([
['path', { name: 'path', type: 'FILE_PATH', label: 'path' }],
]);
const combinedInputName = getWidgetCombinedInputName({
name: 'filename',
opts: { hide_when_input_connected: 'path' },
}, dataInputByName);
assert.equal(combinedInputName, null);
});
test('buildCombinedInputNameByWidgetName preserves explicit top_socket_input pairings', () => {
const combinedInputNameByWidgetName = buildCombinedInputNameByWidgetName(
[
{
name: 'directory',
opts: {
top_socket_input: 'directory',
hide_when_input_connected: 'directory',
},
},
],
[
{ name: 'directory', type: 'STRING', label: 'directory' },
],
);
assert.equal(combinedInputNameByWidgetName.get('directory'), 'directory');
});

View File

@@ -0,0 +1,47 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
applySIPrefix,
formatDisplayUnit,
formatTableRowCell,
getTableColumns,
} from '../src/valueFormatting.js';
test('getTableColumns hides companion record-table unit columns', () => {
const columns = getTableColumns([
{
particle_id: 1,
area_m2: 2.5e-12,
area_m2_unit: 'm^2',
mean_height: 1.5e-9,
mean_height_unit: 'm',
bbox: '(0,0)-(2,2)',
},
]);
assert.deepEqual(columns, ['particle_id', 'area_m2', 'mean_height', 'bbox']);
});
test('formatTableRowCell appends companion units inline for record-table values', () => {
const row = {
area_m2: 2.5e-12,
area_m2_unit: 'm^2',
mean_height: 1.5e-9,
mean_height_unit: 'm',
};
assert.equal(formatTableRowCell(row, 'area_m2'), '2.5 um²');
assert.equal(formatTableRowCell(row, 'mean_height'), '1.5 nm');
});
test('formatDisplayUnit renders exponent markers as superscripts', () => {
assert.equal(formatDisplayUnit('px^2'), 'px²');
assert.equal(formatDisplayUnit('(V)^2 m^2'), '(V)² m²');
});
test('applySIPrefix scales squared units using squared SI prefixes', () => {
assert.deepEqual(applySIPrefix(3e-18, 'm^2'), { valueText: '3', unitText: 'nm²' });
assert.deepEqual(applySIPrefix(3e-9, 'm^2'), { valueText: '3000', unitText: 'um²' });
assert.deepEqual(applySIPrefix(144, 'px^2'), { valueText: '144', unitText: 'px²' });
});