7a0da7932b
Backwards Compatibility / Verify Encryption Constants (push) Waiting to run
Backwards Compatibility / PyPI Version Compatibility (push) Waiting to run
Backwards Compatibility / Database Migration Tests (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Blocked by required conditions
Docker Tests (Consolidated) / detect-changes (push) Waiting to run
Docker Tests (Consolidated) / Build Test Image (push) Waiting to run
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Blocked by required conditions
Docker Tests (Consolidated) / Accessibility Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Unit Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Example Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / Production Image Smoke Test (push) Blocked by required conditions
Docker Tests (Consolidated) / Infrastructure Tests (push) Blocked by required conditions
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Waiting to run
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
/**
|
|
* 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');
|
|
});
|
|
|
|
it('formats terabyte-and-larger sizes without "undefined"', () => {
|
|
// Regression: sizes only went up to GB, so i>=4 yielded "N undefined".
|
|
expect(formatBytes(1024 ** 4)).toBe('1 TB');
|
|
expect(formatBytes(5 * 1024 ** 4)).toBe('5 TB');
|
|
expect(formatBytes(1024 ** 5)).toBe('1 PB');
|
|
expect(formatBytes(1024 ** 6)).toBe('1 EB');
|
|
// Beyond the largest unit, clamp to EB rather than emit undefined.
|
|
expect(formatBytes(1024 ** 7)).toBe('1024 EB');
|
|
});
|
|
|
|
it('handles sub-1-byte values without a negative index (lower-bound clamp)', () => {
|
|
// log(bytes) < 0 for bytes < 1 would give a negative index -> undefined.
|
|
expect(formatBytes(0.5)).toBe('0.5 Bytes');
|
|
});
|
|
});
|