2023-11-11 17:12:20 +01:00
|
|
|
import { describe, it, expect } from 'vitest'
|
2021-09-29 16:34:48 +02:00
|
|
|
|
2023-11-11 20:16:18 +01:00
|
|
|
import {
|
|
|
|
getFileSizeInMB,
|
|
|
|
getReadableFileSize,
|
|
|
|
getReadableFileSizeAsText,
|
|
|
|
} from '@/utils/files'
|
2021-09-29 16:34:48 +02:00
|
|
|
|
2023-11-11 20:16:18 +01:00
|
|
|
describe('getReadableFileSizeAsText', () => {
|
2021-09-29 16:34:48 +02:00
|
|
|
const testsParams = [
|
|
|
|
{
|
|
|
|
description: 'returns 0 bytes if provided file size is 0',
|
|
|
|
inputFileSize: 0,
|
|
|
|
expectedReadableFileSize: '0 bytes',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns 1.0KB if provided file size is 1024',
|
|
|
|
inputFileSize: 1024,
|
|
|
|
expectedReadableFileSize: '1.0KB',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns 43.5MB if provided file size is 45654654',
|
|
|
|
inputFileSize: 45654654,
|
|
|
|
expectedReadableFileSize: '43.5MB',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
testsParams.map((testParams) => {
|
|
|
|
it(testParams.description, () => {
|
2023-11-11 20:16:18 +01:00
|
|
|
expect(getReadableFileSizeAsText(testParams.inputFileSize)).toStrictEqual(
|
2021-09-29 16:34:48 +02:00
|
|
|
testParams.expectedReadableFileSize
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('getReadableFileSize (as object)', () => {
|
|
|
|
const testsParams = [
|
|
|
|
{
|
|
|
|
description: 'returns 0 bytes if provided file size is 0',
|
|
|
|
inputFileSize: 0,
|
|
|
|
expectedReadableFileSize: { size: '0', suffix: 'bytes' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns 1.0KB if provided file size is 1024',
|
|
|
|
inputFileSize: 1024,
|
|
|
|
expectedReadableFileSize: { size: '1.0', suffix: 'KB' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns 43.5MB if provided file size is 45654654',
|
|
|
|
inputFileSize: 45654654,
|
|
|
|
expectedReadableFileSize: { size: '43.5', suffix: 'MB' },
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
testsParams.map((testParams) => {
|
|
|
|
it(testParams.description, () => {
|
2023-11-11 20:16:18 +01:00
|
|
|
expect(getReadableFileSize(testParams.inputFileSize)).toStrictEqual(
|
|
|
|
testParams.expectedReadableFileSize
|
|
|
|
)
|
2021-09-29 16:34:48 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2021-10-24 20:13:28 +02:00
|
|
|
|
|
|
|
describe('getFileSizeInMB', () => {
|
|
|
|
const testsParams = [
|
|
|
|
{
|
|
|
|
description: 'returns 0 if provided file size is 0',
|
|
|
|
inputFileSize: 0,
|
|
|
|
expectedFileSize: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns 1 (MB) if provided file size is 1048576',
|
|
|
|
inputFileSize: 1048576,
|
|
|
|
expectedFileSize: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns 2.53 (MB) if provided file size is 2652897',
|
|
|
|
inputFileSize: 2652897,
|
|
|
|
expectedFileSize: 2.53,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
testsParams.map((testParams) => {
|
|
|
|
it(testParams.description, () => {
|
2023-11-11 17:12:20 +01:00
|
|
|
expect(getFileSizeInMB(testParams.inputFileSize)).toStrictEqual(
|
2021-10-24 20:13:28 +02:00
|
|
|
testParams.expectedFileSize
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|