fix(downloads): show total size after completion

This commit is contained in:
NimBold
2026-07-15 21:30:01 +03:30
parent ed54a048ab
commit 9f333618fc
4 changed files with 33 additions and 8 deletions
+11 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { formatDownloadBytes, resolveDownloadSizeDisplay } from './downloadProgress';
import { formatDownloadBytes, formatDownloadTotal, resolveDownloadSizeDisplay } from './downloadProgress';
describe('download progress size display', () => {
it('formats byte counts using the binary units used by the download engines', () => {
@@ -33,4 +33,14 @@ describe('download progress size display', () => {
unit: 'GB'
});
});
it('formats a completed download using only its total size', () => {
const display = resolveDownloadSizeDisplay({
downloadedBytes: 1.2 * 1024 ** 3,
totalBytes: 2.4 * 1024 ** 3,
fallbackSize: '2.4 GB'
});
expect(formatDownloadTotal(display)).toBe('2.40 GB');
});
});
+5
View File
@@ -34,6 +34,11 @@ export const formatDownloadBytes = (bytes: number): string => {
return `${formatDownloadBytesInUnit(bytes, unitIndex)} ${BYTE_UNITS[unitIndex]}`;
};
export const formatDownloadTotal = (display: DownloadSizeDisplay): string =>
display.total && display.unit
? `${display.totalIsEstimate ? '~' : ''}${display.total} ${display.unit}`
: display.fallback;
export const resolveDownloadSizeDisplay = ({
downloadedBytes,
totalBytes,