diff --git a/_javascript/src/utils/index.test.ts b/_javascript/src/utils/index.test.ts index 1fd7ea1..2e62000 100644 --- a/_javascript/src/utils/index.test.ts +++ b/_javascript/src/utils/index.test.ts @@ -1,5 +1,16 @@ import { expect, it, describe } from 'vitest' -import { double, formatCurrencyToIDR, calculatePriceWithDiscount } from './index' +import { + double, + formatCurrencyToIDR, + calculatePriceWithDiscount , + getReadableFileSize, + toCamelCase, + capitalizeText, + isArrayEmpty, + getUrlQueryStringAsObject, + truncateString, + validateEmail, +} from './index' describe('[utils]: double', () => { it('should double a number', () => { @@ -7,7 +18,7 @@ describe('[utils]: double', () => { }) }) -describe('[utils: formatCurrencyToID]', () => { +describe('[utils]: formatCurrencyToID', () => { it('should format a number to IDR', () => { expect(formatCurrencyToIDR(1000)).toEqual('RpĀ 1.000') }) @@ -17,7 +28,7 @@ describe('[utils: formatCurrencyToID]', () => { }) }) -describe('[utils: calculatePriceWithDiscount]', () => { +describe('[utils]: calculatePriceWithDiscount', () => { it('should calculate the price with discount', () => { expect(calculatePriceWithDiscount(1000, 50)).toBe(500) }) @@ -30,3 +41,54 @@ describe('[utils: calculatePriceWithDiscount]', () => { expect(() => calculatePriceWithDiscount(1000, 150)).toThrow('Discount percentage must be between 0 and 100') }) }) + +describe('[utils]: getReadableFileSize', () => { + it('should convert bytes into units', () => { + expect(getReadableFileSize(1025, 0)).toBe('1 KB') + }) +}) + +describe('[utils]: toCamelCase', () => { + it('should convert string to camelCase', () => { + expect(toCamelCase('front-end_bootcamp')).toBe('frontEndBootcamp') + }) +}) + +describe('[utils]: capitalizeText', () => { + it('should convert string to capitalizeText', () => { + expect(capitalizeText('frontend bootcamp')).toBe('Frontend Bootcamp') + }) +}) + +describe('[utils]: validateEmail', () => { + it('should check format email is valid', () => { + expect(validateEmail('email@test.com')).toBe('Valid email') + }) + it('should check format email is not valid', () => { + expect(validateEmail('email@testcom')).toBe('Invalid email') + }) +}) + +describe('[utils]: isArrayEmpty', () => { + it('should check isArrayEmpty false', () => { + expect(isArrayEmpty([])).toBe(true) + }) + it('should check isArrayEmpty true', () => { + expect(isArrayEmpty([1])).toBe(false) + }) +}) + +describe('[utils]: getUrlQueryStringAsObject', () => { + it('should convert url into object of params', () => { + expect(getUrlQueryStringAsObject('http://test.com?search=test&id=2')).toStrictEqual({ + search: 'test', + id: '2' + }) + }) +}) + +describe('[utils]: truncateString', () => { + it('should truncate string with maxlegth', () => { + expect(truncateString('frontend bootcamp', 8)).toBe('frontend...') + }) +}) \ No newline at end of file diff --git a/vue/app.vue b/vue/app.vue index 2d842de..2cd889c 100644 --- a/vue/app.vue +++ b/vue/app.vue @@ -15,6 +15,7 @@