mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-09-19 12:14:50 -04:00
JavaScript unit tests for new SI units added, privatebin.js SRI updated
This commit is contained in:
parent
390f8ddc53
commit
5d119768c3
3 changed files with 22 additions and 3 deletions
|
@ -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) {
|
||||
|
|
|
@ -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';
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue