All files / src/pages/flowsheet-page/economics/cost-curves/model unitOptions.ts

100% Statements 7/7
50% Branches 4/8
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24            117x 117x 127x 87x   24x             16x          
import type { CostCurveDriverSpec, UnitOption } from "@/api/apiStore.gen";
 
export function unitOptionsOrCurrent(
  options: readonly UnitOption[] | undefined,
  currentUnit: string,
) {
  const current = currentUnit.trim();
  if (!current) return [...(options ?? [])];
  if (options?.some((option) => option.value === current)) {
    return [...options];
  }
  return [{ value: current, label: current }, ...(options ?? [])];
}
 
export function unitOptionsForSpec(
  spec: CostCurveDriverSpec,
  fallbackOptions: readonly UnitOption[] = [],
) {
  return unitOptionsOrCurrent(
    spec.unit_options?.length ? spec.unit_options : fallbackOptions,
    spec.unit,
  );
}