Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to binary prefixes #7218

Merged
merged 10 commits into from
Oct 3, 2023
1 change: 1 addition & 0 deletions app/components/version-list/row.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@

.bytes {
font-variant-numeric: tabular-nums;
text-transform: none;
}

.feature-list {
Expand Down
10 changes: 9 additions & 1 deletion app/helpers/pretty-bytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Comment on lines +9 to +12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Turbo87, what's the point of "making it possible to override these defaults", if it is never (AFAIU) overridden anywhere?

In #7177 (comment) I intentionally wrote {...options, binary: true} so that binary prefixes will be anywhere and everywhere (that was the point from the start).

);
40 changes: 40 additions & 0 deletions tests/unit/helpers/pretty-bytes-test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
Loading