From f8919d55a1df32d1a4badca37ca38ea9c12f5355 Mon Sep 17 00:00:00 2001 From: EL GABOURI Saad Date: Mon, 30 Jun 2025 19:36:56 +0100 Subject: [PATCH] Update buffer capacity display to MiB --- src/test/components/MenuButtons.test.js | 2 +- .../__snapshots__/MenuButtons.test.js.snap | 22 +++++----- src/test/unit/format-numbers.test.js | 44 ++++++++++--------- src/test/unit/marker-schema.test.js | 6 +-- src/utils/format-numbers.js | 14 +++--- 5 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/test/components/MenuButtons.test.js b/src/test/components/MenuButtons.test.js index 8053d3a19a..e99b707940 100644 --- a/src/test/components/MenuButtons.test.js +++ b/src/test/components/MenuButtons.test.js @@ -484,7 +484,7 @@ describe('app/MenuButtons', function () { * code, and this triggers * https://github.com/testing-library/jest-dom/issues/306 */ /* eslint-disable-next-line jest-dom/prefer-to-have-text-content */ - expect(renderedCapacity.textContent).toBe('1GB'); + expect(renderedCapacity.textContent).toBe('1 GiB'); expect(getMetaInfoPanel()).toMatchSnapshot(); }); diff --git a/src/test/components/__snapshots__/MenuButtons.test.js.snap b/src/test/components/__snapshots__/MenuButtons.test.js.snap index ad9cbb4190..99c4f25ed9 100644 --- a/src/test/components/__snapshots__/MenuButtons.test.js.snap +++ b/src/test/components/__snapshots__/MenuButtons.test.js.snap @@ -447,7 +447,7 @@ exports[`app/MenuButtons matches the snapshot 1`] = ` > Buffer capacity: - 1GB + 1 GiB
matches the snapshot with device inform > Buffer capacity: - 8MB + 8 MiB
matches the snapshot with uptime 1`] = > Buffer capacity: - 8MB + 8 MiB
with no statistics object should not ma > Buffer capacity: - 8MB + 8 MiB
matches the snapshot for a compression error class="menuButtonsPublishInfoDescription" > Upload your profile and make it accessible to anyone with the link. - + By default, your personal data is removed.

matches the snapshot for the menu buttons and class="menuButtonsPublishInfoDescription" > Upload your profile and make it accessible to anyone with the link. - + By default, your personal data is removed.

matches the snapshot for the menu buttons and class="menuButtonsPublishButtonsSvg menuButtonsPublishButtonsSvgDownload" /> Download - + @@ -2245,7 +2245,7 @@ exports[`app/MenuButtons matches the snapshot for the opened panel for class="menuButtonsPublishInfoDescription" > Upload your profile and make it accessible to anyone with the link. - + This profile is from ⁨Firefox Nightly⁩, so by default most information is included.

matches the snapshot for the opened panel for class="menuButtonsPublishButtonsSvg menuButtonsPublishButtonsSvgDownload" /> Download - + @@ -2363,7 +2363,7 @@ exports[`app/MenuButtons matches the snapshot for the opened panel for class="menuButtonsPublishInfoDescription" > Upload your profile and make it accessible to anyone with the link. - + By default, your personal data is removed.

matches the snapshot for the opened panel for class="menuButtonsPublishButtonsSvg menuButtonsPublishButtonsSvgDownload" /> Download - + diff --git a/src/test/unit/format-numbers.test.js b/src/test/unit/format-numbers.test.js index 1141009822..d890929147 100644 --- a/src/test/unit/format-numbers.test.js +++ b/src/test/unit/format-numbers.test.js @@ -38,67 +38,71 @@ describe('formatGigaBytes', () => { }); it('can return values with byte precision', () => { - expect(formatGigaBytes(1234567890, 3, 2, 1)).toBe('1GB 153MB 384KB 722B'); + expect(formatGigaBytes(1234567890, 3, 2, 1)).toBe( + '1 GiB 153 MiB 384 KiB 722 B' + ); }); it('can return values with kilobyte precision', () => { - expect(formatGigaBytes(1234567890, 3, 2, 1024)).toBe('1GB 153MB 385KB'); + expect(formatGigaBytes(1234567890, 3, 2, 1024)).toBe( + '1 GiB 153 MiB 385 KiB' + ); }); it('can return values with megabyte precision', () => { - expect(formatGigaBytes(1234567890, 3, 2, 1024 ** 2)).toBe('1GB 153MB'); + expect(formatGigaBytes(1234567890, 3, 2, 1024 ** 2)).toBe('1 GiB 153 MiB'); }); it('can return values with gigabyte precision', () => { - expect(formatGigaBytes(1234567890, 3, 2, 1024 ** 3)).toBe('1GB'); + expect(formatGigaBytes(1234567890, 3, 2, 1024 ** 3)).toBe('1 GiB'); }); }); describe('formatMegaBytes', () => { it('returns 0 without fractional digits when called with 0', () => { - expect(formatMegaBytes(0)).toBe('0MB'); + expect(formatMegaBytes(0)).toBe('0 MiB'); }); it('returns large values without fractional digits by default', () => { - expect(formatMegaBytes(1234567890)).toBe('1,177MB'); + expect(formatMegaBytes(1234567890)).toBe('1,177 MiB'); }); it('returns values with 2 fractional digits by default', () => { - expect(formatMegaBytes(1234567)).toBe('1.18MB'); + expect(formatMegaBytes(1234567)).toBe('1.18 MiB'); }); it('can return values with byte precision', () => { - expect(formatMegaBytes(1234567, 3, 2, 1)).toBe('1MB 181KB 647B'); + expect(formatMegaBytes(1234567, 3, 2, 1)).toBe('1 MiB 181 KiB 647 B'); }); it('can return values with kilobyte precision', () => { - expect(formatMegaBytes(1234567, 3, 2, 1024)).toBe('1MB 182KB'); + expect(formatMegaBytes(1234567, 3, 2, 1024)).toBe('1 MiB 182 KiB'); }); it('can return values with megabyte precision', () => { - expect(formatMegaBytes(1234567, 3, 2, 1024 ** 2)).toBe('1MB'); + expect(formatMegaBytes(1234567, 3, 2, 1024 ** 2)).toBe('1 MiB'); }); }); describe('formatKiloBytes', () => { it('returns 0 without fractional digits when called with 0', () => { - expect(formatKiloBytes(0)).toBe('0KB'); + expect(formatKiloBytes(0)).toBe('0 KiB'); }); it('returns large values without fractional digits by default', () => { - expect(formatKiloBytes(1234567)).toBe('1,206KB'); + expect(formatKiloBytes(1234567)).toBe('1,206 KiB'); }); it('returns values with 2 fractional digits by default', () => { - expect(formatKiloBytes(1234)).toBe('1.21KB'); + expect(formatKiloBytes(1234)).toBe('1.21 KiB'); }); it('can return values with byte precision', () => { - expect(formatKiloBytes(1234, 3, 2, 1)).toBe('1KB 210B'); + expect(formatKiloBytes(1234, 3, 2, 1)).toBe('1 KiB 210 B'); }); it('can return values with kilobyte precision', () => { - expect(formatKiloBytes(1234, 3, 2, 1024)).toBe('1KB'); + expect(formatKiloBytes(1234, 3, 2, 1024)).toBe('1 KiB'); }); }); @@ -112,23 +116,23 @@ describe('formatBytes', () => { }); it('can return values with the kilobyte unit', () => { - expect(formatBytes(12345)).toBe('12.1KB'); + expect(formatBytes(12345)).toBe('12.1 KiB'); }); it('can return values with the megabyte unit', () => { - expect(formatBytes(1234567)).toBe('1.18MB'); + expect(formatBytes(1234567)).toBe('1.18 MiB'); }); it('can return values with the gigabyte unit', () => { - expect(formatBytes(1234567890)).toBe('1.15GB'); + expect(formatBytes(1234567890)).toBe('1.15 GiB'); }); it('can return values with byte precision', () => { - expect(formatBytes(12345, 3, 2, 1)).toBe('12KB 57B'); + expect(formatBytes(12345, 3, 2, 1)).toBe('12 KiB 57 B'); }); it('can return values with kilobyte precision', () => { - expect(formatBytes(12345, 3, 2, 1024)).toBe('12KB'); + expect(formatBytes(12345, 3, 2, 1024)).toBe('12 KiB'); }); }); diff --git a/src/test/unit/marker-schema.test.js b/src/test/unit/marker-schema.test.js index 967f11e0b9..f7e0a1e443 100644 --- a/src/test/unit/marker-schema.test.js +++ b/src/test/unit/marker-schema.test.js @@ -352,9 +352,9 @@ describe('marker schema formatting', function () { "bytes - 0B", "bytes - 10B", "bytes - 12B", - "bytes - 121KB", - "bytes - 118MB", - "bytes - 115GB", + "bytes - 121 KiB", + "bytes - 118 MiB", + "bytes - 115 GiB", "bytes - 0.000B", "integer - 0", "integer - 10", diff --git a/src/utils/format-numbers.js b/src/utils/format-numbers.js index a9ecd2e392..7bde27dd82 100644 --- a/src/utils/format-numbers.js +++ b/src/utils/format-numbers.js @@ -189,7 +189,7 @@ export function formatGigaBytes( bytes / bytesPerGigabyte, significantDigits, maxFractionalDigits - ) + 'GB' + ) + ' GiB' ); } @@ -199,7 +199,7 @@ export function formatGigaBytes( const megabytes = bytes % bytesPerGigabyte; return ( formatNumber((bytes - megabytes) / bytesPerGigabyte, significantDigits, 0) + - 'GB' + + ' GiB' + ((megabytes > 0 && maxFractionalDigits > 0) || precision < bytesPerGigabyte ? ' ' + formatMegaBytes(megabytes, significantDigits, 0, precision) : '') @@ -219,7 +219,7 @@ export function formatMegaBytes( bytes / bytesPerMegabyte, significantDigits, maxFractionalDigits - ) + 'MB' + ) + ' MiB' ); } @@ -229,7 +229,7 @@ export function formatMegaBytes( const kilobytes = bytes % bytesPerMegabyte; return ( formatNumber((bytes - kilobytes) / bytesPerMegabyte, significantDigits, 0) + - 'MB' + + ' MiB' + ((kilobytes > 0 && maxFractionalDigits > 0) || precision < bytesPerMegabyte ? ' ' + formatKiloBytes(kilobytes, significantDigits, 0, precision) : '') @@ -249,7 +249,7 @@ export function formatKiloBytes( bytes / bytesPerKilobyte, significantDigits, maxFractionalDigits - ) + 'KB' + ) + ' KiB' ); } @@ -259,7 +259,7 @@ export function formatKiloBytes( const bytesOnly = bytes % bytesPerKilobyte; return ( formatNumber((bytes - bytesOnly) / bytesPerKilobyte, significantDigits, 0) + - 'KB' + + ' KiB' + ((bytesOnly > 0 && maxFractionalDigits > 0) || precision < bytesPerKilobyte ? ' ' + formatBytes(bytesOnly, significantDigits, 0, precision) : '') @@ -275,7 +275,7 @@ export function formatBytes( if (bytes < 10000) { // Use singles up to 10,000. I think 9,360B looks nicer than 9.36KB. // We use "0" for significantDigits because bytes will always be integers. - return formatNumber(bytes, 0) + 'B'; + return formatNumber(bytes, 0) + ' B'; } else if (bytes < 1024 ** 2) { return formatKiloBytes( bytes,