feat: Add Python consistency tests for calculator definitions and refactor QuickConversionTable to explicitly pass calculator configuration to its row builder.

This commit is contained in:
Ben
2026-03-08 13:41:50 -07:00
parent 193affca27
commit 2794835590
3 changed files with 113 additions and 5 deletions

View File

@@ -8,8 +8,8 @@
type Row = { input: number; output: string };
const buildRow = (value: number): Row => {
const formatted = solve(config, 1, value.toString(), '', '');
const buildRow = (value: number, c: CalculatorDef): Row => {
const formatted = solve(c, 1, value.toString(), '', '');
return {
input: value,
output: formatted.val2 || '—',
@@ -22,8 +22,8 @@
let outputLabel = 'target units';
$: supportsTable = ['standard', 'inverse'].includes(config.type);
$: rows = supportsTable
? numericSamples.map(buildRow)
$: rows = (config && supportsTable)
? numericSamples.map(v => buildRow(v, config))
: [];
$: inputLabel = config.labels?.in1 ?? 'source units';
$: outputLabel = config.labels?.in2 ?? 'target units';

View File

@@ -82,7 +82,9 @@
<h1 class="page-title calculator-page-title">{calc.name}</h1>
<Calculator config={calc} showTitle={false} />
{#key calc.slug}
<Calculator config={calc} showTitle={false} />
{/key}
<div class="seo-content">
{#if calc.descriptionHTML}