tests / ci (push) Waiting to run
As despesas de arranque passam a oferecer as categorias habituais de uma empresa nova (constituição e despesas legais, mobiliário, seguros, rendas, computadores, outras despesas de início de actividade), acrescentadas só quando o investidor o pede e sem alterar as linhas que já escreveu, e mostram o total, ou o que falta para o calcular. Cada produto ou serviço mostra a margem por unidade (preço menos custo variável, em valor e em percentagem do preço) e avisa quando o custo excede o preço. Os testes que carregam os editores passam a usar um resolvedor comum para o campo decimal e as bibliotecas de totais e margens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
// The real DecimalInput, compiled for the harnesses that load components with
|
|
// their own `require`, plus helpers to type into it from a walked element tree.
|
|
import fs from 'node:fs';
|
|
import { compileFunction } from 'node:vm';
|
|
import { createRequire } from 'node:module';
|
|
import React from 'react';
|
|
import ts from 'typescript';
|
|
import * as decimal from '../../../resources/js/lib/decimal-input.ts';
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const module = { exports: {} };
|
|
compileFunction(
|
|
ts.transpileModule(
|
|
fs.readFileSync(
|
|
new URL(
|
|
'../../../resources/js/components/decimal-input.tsx',
|
|
import.meta.url,
|
|
),
|
|
'utf8',
|
|
),
|
|
{
|
|
compilerOptions: {
|
|
module: ts.ModuleKind.CommonJS,
|
|
jsx: ts.JsxEmit.ReactJSX,
|
|
},
|
|
},
|
|
).outputText,
|
|
['require', 'module', 'exports'],
|
|
)(
|
|
(id) =>
|
|
id === 'react'
|
|
? React
|
|
: id === '@/lib/decimal-input'
|
|
? decimal
|
|
: require(id),
|
|
module,
|
|
module.exports,
|
|
);
|
|
|
|
export const decimalInputModule = module.exports;
|
|
export const DecimalInput = module.exports.DecimalInput;
|
|
|
|
/** A number field in a walked tree: the decimal field or a plain number input. */
|
|
export const isNumberField = (node) =>
|
|
node?.type === DecimalInput ||
|
|
(node?.type === 'input' && node.props?.type === 'number');
|
|
|
|
/** Types `value` as the investor would, through whichever field the tree holds. */
|
|
export function typeNumber(node, value) {
|
|
const text = String(value);
|
|
if (node.type === DecimalInput) {
|
|
const normalized = decimal.normalizeDecimalInput(text);
|
|
node.props.onValueChange(normalized === null ? text : normalized);
|
|
return;
|
|
}
|
|
node.props.onChange({ target: { value: text } });
|
|
}
|
|
|
|
const sharedLibs = [
|
|
'decimal-input',
|
|
'product-margin',
|
|
'startup-asset-requirements',
|
|
];
|
|
|
|
/**
|
|
* Modules every simulator harness can load as they are: the decimal field and
|
|
* the small pure libraries the editors use for totals and margins.
|
|
*/
|
|
export function sharedModule(id) {
|
|
if (id === '@/components/decimal-input') return decimalInputModule;
|
|
const lib = sharedLibs.find((name) => id === `@/lib/${name}`);
|
|
return lib ? require(`../../../resources/js/lib/${lib}.ts`) : undefined;
|
|
}
|