// size column
if (typeof(fileData.size) !== 'undefined' && fileData.size >= 0) {
- simpleSize = humanFileSize(parseInt(fileData.size, 10));
+ simpleSize = humanFileSize(parseInt(fileData.size, 10), true);
sizeColor = Math.round(160-Math.pow((fileData.size/(1024*1024)),2));
} else {
simpleSize = t('files', 'Pending');
size: '0'
};
var $tr = fileList.add(fileData);
- expect($tr.find('.filesize').text()).toEqual('0 B');
+ expect($tr.find('.filesize').text()).toEqual('0 kB');
});
it('adds new file to the end of the list', function() {
var $tr;
/**
* Returns a human readable file size
* @param {number} size Size in bytes
+ * @param {boolean} skipSmallSizes return '< 1 kB' for small files
* @return {string}
*/
-function humanFileSize(size) {
+function humanFileSize(size, skipSmallSizes) {
var humanList = ['B', 'kB', 'MB', 'GB', 'TB'];
// Calculate Log with base 1024: size = 1024 ** order
var order = size?Math.floor(Math.log(size) / Math.log(1024)):0;
order = Math.min(humanList.length - 1, order);
var readableFormat = humanList[order];
var relativeSize = (size / Math.pow(1024, order)).toFixed(1);
+ if(skipSmallSizes === true && order === 0) {
+ if(relativeSize !== "0.0"){
+ return '< 1 kB';
+ } else {
+ return '0 kB';
+ }
+ }
if(order < 2){
relativeSize = parseFloat(relativeSize).toFixed(0);
}
expect(OC.Util.humanFileSize(data[i][0])).toEqual(data[i][1]);
}
});
+ it('renders file sizes with the correct unit for small sizes', function() {
+ var data = [
+ [0, '0 kB'],
+ [125, '< 1 kB'],
+ [128000, '125 kB'],
+ [128000000, '122.1 MB'],
+ [128000000000, '119.2 GB'],
+ [128000000000000, '116.4 TB']
+ ];
+ for (var i = 0; i < data.length; i++) {
+ expect(OC.Util.humanFileSize(data[i][0], true)).toEqual(data[i][1]);
+ }
+ });
});
});
});