59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
|
|
import { describe, test, expect } from 'bun:test';
|
||
|
|
import { formatBytesPerSecond } from '../src/components/transfer/SpeedReadout.js';
|
||
|
|
import { formatEta } from '../src/components/transfer/ETAReadout.js';
|
||
|
|
|
||
|
|
describe('formatBytesPerSecond', () => {
|
||
|
|
test('renders sub-1KB rates in B/s', () => {
|
||
|
|
expect(formatBytesPerSecond(1)).toBe('1 B/s');
|
||
|
|
expect(formatBytesPerSecond(512)).toBe('512 B/s');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('renders KB/s', () => {
|
||
|
|
expect(formatBytesPerSecond(1024)).toBe('1.0 KB/s');
|
||
|
|
expect(formatBytesPerSecond(1536)).toBe('1.5 KB/s');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('renders MB/s', () => {
|
||
|
|
expect(formatBytesPerSecond(1024 * 1024)).toBe('1.00 MB/s');
|
||
|
|
expect(formatBytesPerSecond(2.5 * 1024 * 1024)).toBe('2.50 MB/s');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('renders GB/s', () => {
|
||
|
|
expect(formatBytesPerSecond(1024 * 1024 * 1024)).toBe('1.00 GB/s');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('handles zero / non-finite as em-dash', () => {
|
||
|
|
expect(formatBytesPerSecond(0)).toBe('— B/s');
|
||
|
|
expect(formatBytesPerSecond(-1)).toBe('— B/s');
|
||
|
|
expect(formatBytesPerSecond(Number.NaN)).toBe('— B/s');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('formatEta', () => {
|
||
|
|
test('undefined → em-dash', () => {
|
||
|
|
expect(formatEta(undefined)).toBe('ETA —');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('NaN/Infinity → em-dash', () => {
|
||
|
|
expect(formatEta(Number.NaN)).toBe('ETA —');
|
||
|
|
expect(formatEta(Number.POSITIVE_INFINITY)).toBe('ETA —');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('sub-second', () => {
|
||
|
|
expect(formatEta(0.4)).toBe('ETA <1s');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('seconds', () => {
|
||
|
|
expect(formatEta(45)).toBe('ETA 45s');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('minutes + seconds', () => {
|
||
|
|
expect(formatEta(90)).toBe('ETA 1m 30s');
|
||
|
|
expect(formatEta(125)).toBe('ETA 2m 5s');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('hours + minutes', () => {
|
||
|
|
expect(formatEta(3600 + 30 * 60)).toBe('ETA 1h 30m');
|
||
|
|
});
|
||
|
|
});
|