JavaScript unit tests for new SI units added, privatebin.js SRI updated

This commit is contained in:
Ribas160 2025-07-24 00:32:04 +03:00
parent 390f8ddc53
commit 5d119768c3
No known key found for this signature in database
GPG key ID: ED4AE99DCA25A6BB
3 changed files with 22 additions and 3 deletions

View file

@ -591,7 +591,7 @@ jQuery.PrivateBin = (function($) {
};
/**
* Convert Bytes to KiB/MiB/GiB
* Convert Bytes to kB/MB/GB/TB/PB/EB/ZB/YB
*
* @name Helper.formatBytes
* @function
@ -604,7 +604,10 @@ jQuery.PrivateBin = (function($) {
let result = '';
const kilobyte = 1000;
const decimalPoint = 2;
const sizes = [I18n._('B'), I18n._('kB'), I18n._('MB'), I18n._('GB'), I18n._('TB'), I18n._('PB'), I18n._('EB'), I18n._('ZB'), I18n._('YB')];
const sizes = [
I18n._('B'), I18n._('kB'), I18n._('MB'), I18n._('GB'), I18n._('TB'),
I18n._('PB'), I18n._('EB'), I18n._('ZB'), I18n._('YB')
];
const index = Math.floor(Math.log(bytes) / Math.log(kilobyte));
if (bytes > 0) {

View file

@ -312,6 +312,22 @@ describe('Helper', function () {
return $.PrivateBin.Helper.formatBytes(3.45 * 1000 * 1000 * 1000) === '3.45 GB';
});
jsc.property('formats terabytes correctly', function () {
return $.PrivateBin.Helper.formatBytes(1.75 * 1000 ** 4) === '1.75 TB';
});
jsc.property('formats petabytes correctly', function () {
return $.PrivateBin.Helper.formatBytes(1.5 * 1000 ** 5) === '1.5 PB';
});
jsc.property('formats exabytes correctly', function () {
return $.PrivateBin.Helper.formatBytes(1.2345 * 1000 ** 6).startsWith('1.23 EB');
});
jsc.property('formats yottabytes correctly', function () {
return $.PrivateBin.Helper.formatBytes(1.23 * 1000 ** 8).startsWith('1.23 YB');
});
jsc.property('rounds to two decimal places', function () {
return $.PrivateBin.Helper.formatBytes(1234567) === '1.23 MB';
});

View file

@ -116,7 +116,7 @@ class Configuration
'js/kjua-0.10.0.js' => 'sha512-BYj4xggowR7QD150VLSTRlzH62YPfhpIM+b/1EUEr7RQpdWAGKulxWnOvjFx1FUlba4m6ihpNYuQab51H6XlYg==',
'js/legacy.js' => 'sha512-UxW/TOZKon83n6dk/09GsYKIyeO5LeBHokxyIq+r7KFS5KMBeIB/EM7NrkVYIezwZBaovnyNtY2d9tKFicRlXg==',
'js/prettify.js' => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==',
'js/privatebin.js' => 'sha512-KANCiaRidjdq4qQoQ6hWROVt3Lazvx7/Po9oSNFdeREo2fThyu4tjkFg/b6i2ZVjOvin6PHzj3Bza0yzA2Xktw==',
'js/privatebin.js' => 'sha512-gwzwJC0yMtonwX7zzx58e+mpYKUmuQYnuuyIC/Z0XOtYrZlR+DyDkP9hHqj6ejCyAV74SPA670+rUDnYQGS5/Q==',
'js/purify-3.2.6.js' => 'sha512-zqwL4OoBLFx89QPewkz4Lz5CSA2ktU+f31fuECkF0iK3Id5qd3Zpq5dMby8KwHjIEpsUgOqwF58cnmcaNem0EA==',
'js/showdown-2.1.0.js' => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==',
'js/zlib-1.3.1-1.js' => 'sha512-5bU9IIP4PgBrOKLZvGWJD4kgfQrkTz8Z3Iqeu058mbQzW3mCumOU6M3UVbVZU9rrVoVwaW4cZK8U8h5xjF88eQ==',