Files
gridpilot.gg/apps/website/lib/formatters/MemoryFormatter.test.ts
Marc Mintel 3db2209d2a
Some checks failed
CI / lint-typecheck (push) Failing after 4m52s
CI / tests (push) Has been skipped
CI / contract-tests (push) Has been skipped
CI / e2e-tests (push) Has been skipped
CI / comment-pr (push) Has been skipped
CI / commit-types (push) Has been skipped
formatter tests
2026-01-25 11:17:47 +01:00

47 lines
1.5 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { MemoryFormatter } from './MemoryFormatter';
describe('MemoryFormatter', () => {
describe('formatMB', () => {
it('should format bytes as MB with 1 decimal place', () => {
expect(MemoryFormatter.formatMB(1048576)).toBe('1.0MB');
expect(MemoryFormatter.formatMB(10485760)).toBe('10.0MB');
expect(MemoryFormatter.formatMB(104857600)).toBe('100.0MB');
});
it('should handle zero bytes', () => {
expect(MemoryFormatter.formatMB(0)).toBe('0.0MB');
});
it('should handle small values', () => {
expect(MemoryFormatter.formatMB(1024)).toBe('0.0MB');
expect(MemoryFormatter.formatMB(524288)).toBe('0.5MB');
});
it('should handle large values', () => {
expect(MemoryFormatter.formatMB(1073741824)).toBe('1024.0MB');
});
});
describe('formatKB', () => {
it('should format bytes as KB with 1 decimal place', () => {
expect(MemoryFormatter.formatKB(1024)).toBe('1.0KB');
expect(MemoryFormatter.formatKB(10240)).toBe('10.0KB');
expect(MemoryFormatter.formatKB(102400)).toBe('100.0KB');
});
it('should handle zero bytes', () => {
expect(MemoryFormatter.formatKB(0)).toBe('0.0KB');
});
it('should handle small values', () => {
expect(MemoryFormatter.formatKB(1)).toBe('0.0KB');
expect(MemoryFormatter.formatKB(512)).toBe('0.5KB');
});
it('should handle large values', () => {
expect(MemoryFormatter.formatKB(1048576)).toBe('1024.0KB');
});
});
});