From 84506d790332c0a223de115c1feda9873139c984 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Fri, 23 Feb 2024 12:16:44 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=90=20Adds=20test=20for=20string=20byt?= =?UTF-8?q?e=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/test/specs/byteformat.spec.ts | 28 +++++++++++++++++++ .../{result.test.ts => specs/result.spec.ts} | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/test/specs/byteformat.spec.ts rename app/test/{result.test.ts => specs/result.spec.ts} (95%) diff --git a/app/test/specs/byteformat.spec.ts b/app/test/specs/byteformat.spec.ts new file mode 100644 index 0000000..10898cf --- /dev/null +++ b/app/test/specs/byteformat.spec.ts @@ -0,0 +1,28 @@ +import { describe, it, expect } from 'vitest'; +import { humanFileSize } from '../../src/lib/utilities'; + +describe('humanFileSize', () => { + it('returns "0B" for 0 bytes', () => { + expect(humanFileSize(0)).toBe('0B'); + }); + + it('returns the size in bytes correctly', () => { + expect(humanFileSize(500)).toBe('500B'); + }); + + it('returns the size in kB correctly', () => { + expect(humanFileSize(1024)).toBe('1kB'); + }); + + it('returns the size in MB correctly', () => { + expect(humanFileSize(1048576)).toBe('1MB'); // 1024 * 1024 + }); + + it('returns the size in GB correctly', () => { + expect(humanFileSize(1073741824)).toBe('1GB'); // 1024 * 1024 * 1024 + }); + + it('rounds to 2 decimal places correctly', () => { + expect(humanFileSize(1536)).toBe('1.5kB'); // 1024 + 512 + }); +}); \ No newline at end of file diff --git a/app/test/result.test.ts b/app/test/specs/result.spec.ts similarity index 95% rename from app/test/result.test.ts rename to app/test/specs/result.spec.ts index ee78ee6..eff37ad 100644 --- a/app/test/result.test.ts +++ b/app/test/specs/result.spec.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { Result } from '../src/lib/utilities'; +import { Result } from '../../src/lib/utilities'; describe('Result', () => { it('should create a success result correctly', () => {