mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-20 16:12:17 +00:00
fix(properties): harden progress and torrent diagnostics
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { formatDownloadBytes, formatDownloadTotal, resolveDownloadSizeDisplay } from './downloadProgress';
|
||||
import {
|
||||
formatDownloadBytes,
|
||||
formatDownloadTotal,
|
||||
resolveDownloadFraction,
|
||||
resolveDownloadSizeDisplay,
|
||||
} from './downloadProgress';
|
||||
|
||||
describe('download progress size display', () => {
|
||||
it('formats byte counts using the binary units used by the download engines', () => {
|
||||
@@ -44,3 +49,62 @@ describe('download progress size display', () => {
|
||||
expect(formatDownloadTotal(display)).toBe('2.40 GB');
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveDownloadFraction', () => {
|
||||
it('reconstructs paused progress from exact persisted byte counters', () => {
|
||||
expect(resolveDownloadFraction({
|
||||
status: 'paused',
|
||||
downloadedBytes: 662 * 1024 ** 2,
|
||||
totalBytes: 2.94 * 1024 ** 3,
|
||||
})).toBeCloseTo(0.2199, 3);
|
||||
});
|
||||
|
||||
it('uses a live fraction when it is available', () => {
|
||||
expect(resolveDownloadFraction({
|
||||
fraction: 0.37,
|
||||
downloadedBytes: 90,
|
||||
totalBytes: 100,
|
||||
status: 'downloading',
|
||||
})).toBe(0.37);
|
||||
});
|
||||
|
||||
it('does not infer progress from an estimated media total', () => {
|
||||
expect(resolveDownloadFraction({
|
||||
fraction: 0,
|
||||
downloadedBytes: 900,
|
||||
totalBytes: 1000,
|
||||
totalIsEstimate: true,
|
||||
isMedia: true,
|
||||
size: '~1000 B',
|
||||
status: 'paused',
|
||||
})).toBe(0);
|
||||
});
|
||||
|
||||
it('keeps zero at the start and does not divide by an unknown total', () => {
|
||||
expect(resolveDownloadFraction({
|
||||
downloadedBytes: 0,
|
||||
totalBytes: 0,
|
||||
status: 'paused',
|
||||
})).toBe(0);
|
||||
expect(resolveDownloadFraction({
|
||||
downloadedBytes: 500,
|
||||
status: 'paused',
|
||||
})).toBe(0);
|
||||
});
|
||||
|
||||
it('shows completed downloads as complete even when volatile fraction was removed', () => {
|
||||
expect(resolveDownloadFraction({
|
||||
status: 'completed',
|
||||
downloadedBytes: 0,
|
||||
totalBytes: 100,
|
||||
})).toBe(1);
|
||||
});
|
||||
|
||||
it('clamps inconsistent exact byte counters', () => {
|
||||
expect(resolveDownloadFraction({
|
||||
downloadedBytes: 150,
|
||||
totalBytes: 100,
|
||||
status: 'paused',
|
||||
})).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user