Share the one HTTP envelope and the one byte formatter
Both stores carried their own ~28-line request<T>, and formatBytes existed twice – the second copy had lost the "B" branch, so a small sprite would have read as 0 KB had its caller ever passed one under a kilobyte. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
787a19d525
commit
b13b130da7
11 files changed
+80
-78
No files matched your search
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
clamp,
|
||||
centreY,
|
||||
formatBytes,
|
||||
formatNumber,
|
||||
NUMBER_DECIMALS,
|
||||
roundTo,
|
||||
@@ -122,3 +123,16 @@ describe('zoomFactor', () => {
|
||||
expect(1 * zoomFactor(-120) * zoomFactor(120)).toBeCloseTo(1, 12);
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatBytes', () => {
|
||||
it('names a small file in bytes, so a sprite never reads as "0 KB"', () => {
|
||||
expect(formatBytes(400)).toBe('400 B');
|
||||
expect(formatBytes(0)).toBe('0 B');
|
||||
});
|
||||
|
||||
it('switches to KB and MB at the round thresholds', () => {
|
||||
expect(formatBytes(1024)).toBe('1 KB');
|
||||
expect(formatBytes(1024 * 1024)).toBe('1.0 MB');
|
||||
expect(formatBytes(1536 * 1024)).toBe('1.5 MB');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user