51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { deriveCantidades } from '@/budget/derive';
|
|
import type { BudgetInputs, PricingConfig } from '@/budget/types';
|
|
|
|
const config: PricingConfig = {
|
|
alturaTechoDefault: 2.5,
|
|
factorZona: {},
|
|
manoObra: { demolicion: 0, fontaneria: 0, electricidad: 0, mano_de_obra: 0 },
|
|
};
|
|
|
|
function inputs(partial: Partial<BudgetInputs>): BudgetInputs {
|
|
return {
|
|
tipoReforma: 'cocina',
|
|
m2Suelo: null,
|
|
alturaTecho: null,
|
|
calidadGlobal: 'media',
|
|
estructural: false,
|
|
provincia: null,
|
|
materialSelections: {},
|
|
...partial,
|
|
};
|
|
}
|
|
|
|
describe('deriveCantidades', () => {
|
|
it('usa m² aportados y deriva perímetro y paredes con números limpios', () => {
|
|
// m2Suelo=16 -> sqrt=4 -> perimetro=16 -> pared=16*2.5=40 -> mobiliario=16*0.5=8 (cocina)
|
|
const c = deriveCantidades(inputs({ m2Suelo: 16 }), config);
|
|
expect(c.m2Suelo).toBe(16);
|
|
expect(c.perimetro).toBe(16);
|
|
expect(c.m2Pared).toBe(40);
|
|
expect(c.mlMobiliario).toBe(8);
|
|
expect(c.alturaTecho).toBe(2.5);
|
|
});
|
|
|
|
it('cae a la mediana por tipo cuando no hay m²', () => {
|
|
const c = deriveCantidades(inputs({ tipoReforma: 'bano', m2Suelo: null }), config);
|
|
expect(c.m2Suelo).toBe(5); // mediana baño
|
|
});
|
|
|
|
it('usa la altura aportada por encima del default', () => {
|
|
const c = deriveCantidades(inputs({ m2Suelo: 16, alturaTecho: 3 }), config);
|
|
expect(c.alturaTecho).toBe(3);
|
|
expect(c.m2Pared).toBe(48); // 16 * 3
|
|
});
|
|
|
|
it('no calcula mobiliario para tipos sin cocina/baño', () => {
|
|
const c = deriveCantidades(inputs({ tipoReforma: 'salon', m2Suelo: 16 }), config);
|
|
expect(c.mlMobiliario).toBe(0);
|
|
});
|
|
});
|