/**
 * Tests for utils/format-bytes.js — window.formatBytes.
 *
 * Single source of truth for human-readable byte sizes, shared by
 * delete_manager.js and pdf_upload_handler.js. The unit-boundary
 * rounding (1023 -> Bytes, 1024 -> KB) is the interesting part.
 */

import '@js/utils/format-bytes.js';

const formatBytes = window.formatBytes;

describe('formatBytes', () => {
    it('returns "0 Bytes" for 0', () => {
        expect(formatBytes(0)).toBe('0 Bytes');
    });

    it('formats sub-kilobyte values in Bytes', () => {
        expect(formatBytes(500)).toBe('500 Bytes');
        expect(formatBytes(1023)).toContain('Bytes');
    });

    it('formats kilobytes, including fractional', () => {
        expect(formatBytes(1024)).toBe('1 KB');
        expect(formatBytes(1536)).toBe('1.5 KB');
    });

    it('formats megabytes and gigabytes', () => {
        expect(formatBytes(1048576)).toBe('1 MB');
        expect(formatBytes(1073741824)).toBe('1 GB');
    });

    it('rounds to 2 decimal places', () => {
        // 1234567 bytes ≈ 1.18 MB
        expect(formatBytes(1234567)).toBe('1.18 MB');
    });

    it('picks the unit by power-of-1024 boundary (1023->Bytes, 1024->KB)', () => {
        expect(formatBytes(1023)).toContain('Bytes');
        expect(formatBytes(1024)).toContain('KB');
        expect(formatBytes(1024 * 1024 - 1)).toContain('KB');
        expect(formatBytes(1024 * 1024)).toContain('MB');
    });
});
