diff --git a/app/components/version-list/row.module.css b/app/components/version-list/row.module.css index 1d784756d9e..8cd2c0e16ab 100644 --- a/app/components/version-list/row.module.css +++ b/app/components/version-list/row.module.css @@ -211,6 +211,7 @@ .bytes { font-variant-numeric: tabular-nums; + text-transform: none; } .feature-list { diff --git a/app/helpers/pretty-bytes.js b/app/helpers/pretty-bytes.js index 33acf40945d..3511e72898c 100644 --- a/app/helpers/pretty-bytes.js +++ b/app/helpers/pretty-bytes.js @@ -2,4 +2,12 @@ import { helper } from '@ember/component/helper'; import prettyBytes from 'pretty-bytes'; -export default helper(([bytes], options) => prettyBytes(bytes, options)); +/** + * See https://github.com/rust-lang/crates.io/discussions/7177 + */ +export default helper(([bytes], options) => + prettyBytes(bytes, { + binary: true, + ...options, + }), +); diff --git a/tests/unit/helpers/pretty-bytes-test.js b/tests/unit/helpers/pretty-bytes-test.js new file mode 100644 index 00000000000..a5d93b76907 --- /dev/null +++ b/tests/unit/helpers/pretty-bytes-test.js @@ -0,0 +1,40 @@ +import { render } from '@ember/test-helpers'; +import { module, test } from 'qunit'; + +import { hbs } from 'ember-cli-htmlbars'; + +import { setupRenderingTest } from 'cargo/tests/helpers'; + +module('Unit | Helper | pretty-bytes', function (hooks) { + setupRenderingTest(hooks); + + test('it displays as expected', async function (assert) { + this.owner.lookup('service:intl').locale = 'en'; + + await render(hbs`{{pretty-bytes 42}}`); + assert.dom().hasText('42 B'); + + await render(hbs`{{pretty-bytes 1024}}`); + assert.dom().hasText('1 KiB'); + + // 4200 / 1024 = 4.101... + await render(hbs`{{pretty-bytes 4200}}`); + assert.dom().hasText('4.1 KiB'); + + // 4200 / 1024 = 4.142... + await render(hbs`{{pretty-bytes 4242}}`); + assert.dom().hasText('4.14 KiB'); + + // 42000 / 1024 = 41.0156... + await render(hbs`{{pretty-bytes 42000}}`); + assert.dom().hasText('41 KiB'); + + // 42623 / 1024 = 41.625 + await render(hbs`{{pretty-bytes 42624}}`); + assert.dom().hasText('41.6 KiB'); + + // 424242 / 1024 = 414.2988... + await render(hbs`{{pretty-bytes 424242}}`); + assert.dom().hasText('414 KiB'); + }); +});