fix(frontend): don't drift a client's byte quota on a no-op save

The quota field shows the total in GB rounded to two decimals; editing a
client and saving converted that display value straight back to bytes. A
byte total not aligned to 0.01 GB — one set via the API or an import — was
therefore rewritten to the rounded value on any save that never touched the
field, losing a few MB each time.

Add resolveTotalBytes: keep the original byte total when the displayed GB
still matches it, and only re-derive from GB when the user actually changed
the field.
This commit is contained in:
MHSanaei
2026-07-15 06:05:37 +02:00
parent 48b60fec54
commit eb669e1d83
2 changed files with 35 additions and 2 deletions
@@ -0,0 +1,20 @@
import { describe, it, expect } from 'vitest';
import { resolveTotalBytes, gbToBytes } from '@/pages/clients/ClientFormModal';
describe('resolveTotalBytes', () => {
it('preserves the original byte total on a no-op save of a non-GB-aligned quota', () => {
const original = 11_505_016_832;
const displayedGB = Math.round((original / 1024 ** 3) * 100) / 100;
expect(resolveTotalBytes(original, displayedGB)).toBe(original);
});
it('re-derives bytes from GB when the user changed the quota', () => {
const original = 11_505_016_832;
expect(resolveTotalBytes(original, 20)).toBe(gbToBytes(20));
});
it('uses the GB value directly when there is no original (add mode)', () => {
expect(resolveTotalBytes(null, 5)).toBe(gbToBytes(5));
});
});