Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/test/components/MenuButtons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
22 changes: 11 additions & 11 deletions src/test/components/__snapshots__/MenuButtons.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ exports[`app/MenuButtons <MetaInfoPanel> matches the snapshot 1`] = `
>
Buffer capacity:
</span>
1GB
1 GiB
</div>
<div
class="metaInfoRow"
Expand Down Expand Up @@ -846,7 +846,7 @@ exports[`app/MenuButtons <MetaInfoPanel> matches the snapshot with device inform
>
Buffer capacity:
</span>
8MB
8 MiB
</div>
<div
class="metaInfoRow"
Expand Down Expand Up @@ -1208,7 +1208,7 @@ exports[`app/MenuButtons <MetaInfoPanel> matches the snapshot with uptime 1`] =
>
Buffer capacity:
</span>
8MB
8 MiB
</div>
<div
class="metaInfoRow"
Expand Down Expand Up @@ -1651,7 +1651,7 @@ exports[`app/MenuButtons <MetaInfoPanel> with no statistics object should not ma
>
Buffer capacity:
</span>
8MB
8 MiB
</div>
<div
class="metaInfoRow"
Expand Down Expand Up @@ -1905,7 +1905,7 @@ exports[`app/MenuButtons <Publish> 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.
</p>
<h3
Expand Down Expand Up @@ -2132,7 +2132,7 @@ exports[`app/MenuButtons <Publish> 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.
</p>
<h3
Expand Down Expand Up @@ -2206,7 +2206,7 @@ exports[`app/MenuButtons <Publish> matches the snapshot for the menu buttons and
class="menuButtonsPublishButtonsSvg menuButtonsPublishButtonsSvgDownload"
/>
Download

<span
class="menuButtonsDownloadSize"
>
Expand Down Expand Up @@ -2245,7 +2245,7 @@ exports[`app/MenuButtons <Publish> 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.
</p>
<h3
Expand Down Expand Up @@ -2324,7 +2324,7 @@ exports[`app/MenuButtons <Publish> matches the snapshot for the opened panel for
class="menuButtonsPublishButtonsSvg menuButtonsPublishButtonsSvgDownload"
/>
Download

<span
class="menuButtonsDownloadSize"
>
Expand Down Expand Up @@ -2363,7 +2363,7 @@ exports[`app/MenuButtons <Publish> 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.
</p>
<h3
Expand Down Expand Up @@ -2437,7 +2437,7 @@ exports[`app/MenuButtons <Publish> matches the snapshot for the opened panel for
class="menuButtonsPublishButtonsSvg menuButtonsPublishButtonsSvgDownload"
/>
Download

<span
class="menuButtonsDownloadSize"
>
Expand Down
44 changes: 24 additions & 20 deletions src/test/unit/format-numbers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand All @@ -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');
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/test/unit/marker-schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions src/utils/format-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function formatGigaBytes(
bytes / bytesPerGigabyte,
significantDigits,
maxFractionalDigits
) + 'GB'
) + ' GiB'
);
}

Expand All @@ -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)
: '')
Expand All @@ -219,7 +219,7 @@ export function formatMegaBytes(
bytes / bytesPerMegabyte,
significantDigits,
maxFractionalDigits
) + 'MB'
) + ' MiB'
);
}

Expand All @@ -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)
: '')
Expand All @@ -249,7 +249,7 @@ export function formatKiloBytes(
bytes / bytesPerKilobyte,
significantDigits,
maxFractionalDigits
) + 'KB'
) + ' KiB'
);
}

Expand All @@ -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)
: '')
Expand All @@ -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,
Expand Down