Skip to content

Commit 7e95789

Browse files
authored
Switch to binary prefixes (#7218)
1 parent 6478354 commit 7e95789

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

app/components/version-list/row.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211

212212
.bytes {
213213
font-variant-numeric: tabular-nums;
214+
text-transform: none;
214215
}
215216

216217
.feature-list {

app/helpers/pretty-bytes.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@ import { helper } from '@ember/component/helper';
22

33
import prettyBytes from 'pretty-bytes';
44

5-
export default helper(([bytes], options) => prettyBytes(bytes, options));
5+
/**
6+
* See https://github.com/rust-lang/crates.io/discussions/7177
7+
*/
8+
export default helper(([bytes], options) =>
9+
prettyBytes(bytes, {
10+
binary: true,
11+
...options,
12+
}),
13+
);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { render } from '@ember/test-helpers';
2+
import { module, test } from 'qunit';
3+
4+
import { hbs } from 'ember-cli-htmlbars';
5+
6+
import { setupRenderingTest } from 'cargo/tests/helpers';
7+
8+
module('Unit | Helper | pretty-bytes', function (hooks) {
9+
setupRenderingTest(hooks);
10+
11+
test('it displays as expected', async function (assert) {
12+
this.owner.lookup('service:intl').locale = 'en';
13+
14+
await render(hbs`{{pretty-bytes 42}}`);
15+
assert.dom().hasText('42 B');
16+
17+
await render(hbs`{{pretty-bytes 1024}}`);
18+
assert.dom().hasText('1 KiB');
19+
20+
// 4200 / 1024 = 4.101...
21+
await render(hbs`{{pretty-bytes 4200}}`);
22+
assert.dom().hasText('4.1 KiB');
23+
24+
// 4200 / 1024 = 4.142...
25+
await render(hbs`{{pretty-bytes 4242}}`);
26+
assert.dom().hasText('4.14 KiB');
27+
28+
// 42000 / 1024 = 41.0156...
29+
await render(hbs`{{pretty-bytes 42000}}`);
30+
assert.dom().hasText('41 KiB');
31+
32+
// 42623 / 1024 = 41.625
33+
await render(hbs`{{pretty-bytes 42624}}`);
34+
assert.dom().hasText('41.6 KiB');
35+
36+
// 424242 / 1024 = 414.2988...
37+
await render(hbs`{{pretty-bytes 424242}}`);
38+
assert.dom().hasText('414 KiB');
39+
});
40+
});

0 commit comments

Comments
 (0)