fix chicken counting accuracy to not round up

This commit is contained in:
Alberto-Audrix committed 2026-10-21 10:37:47 +07:00
1 parent 31ab4e4780
commit c24ffe3a7c
2 files changed
+62 -2

No files matched your search

+9 -2
View File
@@ -207,7 +207,7 @@ const DataManagementPage: React.FC<{ onSettings: () => void }> = ({ onSettings }
beratPanen,
stockAkhir,
chickenCount,
persentase: Math.round(persentase * 10) / 10,
persentase,
mortalityTotal: kpi?.mortality_total ?? cumulativeMortality,
harvestTotal: kpi?.harvest_total ?? cumulativeHarvest,
harvestWeightTotal:
@@ -315,9 +315,16 @@ const DataManagementPage: React.FC<{ onSettings: () => void }> = ({ onSettings }
? 'bg-yellow-100 text-yellow-700'
: 'bg-red-100 text-red-700';
const formatted =
persentase >= 100
? '100%'
: persentase.toFixed(2) === '100.00'
? '99.99%'
: `${persentase.toFixed(2)}%`;
return (
<span className={`px-2 py-1 rounded-full text-xs font-medium ${colorClass}`}>
{persentase.toFixed(1)}%
{formatted}
</span>
);
};
@@ -188,4 +188,57 @@ describe('DataManagementPage', () => {
expect(within(alert).getByText(/IoT lebih rendah dari stock/i)).toBeInTheDocument();
expect(within(alert).getByText(/Hari 2/i)).toBeInTheDocument();
});
it('displays 2 decimals accuracy without rounding up to 100% when there is a slight difference', async () => {
vi.mocked(api.kpis.list).mockResolvedValue([
{
id: 1,
cycle: 1,
kandang: 1,
flock_id: 1,
date: '2026-08-10',
age: 0,
mortality: 0,
mortality_total: 0,
feed: 0,
feed_total: 0,
harvest: 0,
harvest_total: 0,
harvest_weight: 0,
harvest_weight_total: 0,
chicken_life: 24359,
chicken_life_percentage: 100,
iot_weight: 0,
average_harvest_day: 0,
average_harvest_weight: 0,
fcr: 0,
eef: 0,
cc: 0,
cw: 0,
fs: 0,
manual: 0,
created_at: '',
updated_at: '',
},
]);
vi.mocked(api.countings.list).mockResolvedValue([
{
id: 1,
cycle: 1,
kandang: 1,
flock_id: 1,
date: '2026-08-10',
total_count: 24354,
mortality_count: 0,
created_at: '',
updated_at: '',
},
]);
render(<DataManagementPage onSettings={() => undefined} />);
await screen.findByRole('heading', { name: 'Hitung Ayam' });
// 24354 / 24359 * 100 = 99.979...% -> displays 99.98%
expect(screen.getAllByText('99.98%').length).toBeGreaterThan(0);
});
});