add tests

This commit is contained in:
2024-05-22 01:39:01 +02:00
parent 92b7f60c75
commit c210ed7fac
2 changed files with 24 additions and 1 deletions

23
src/formaters.spec.ts Normal file
View File

@@ -0,0 +1,23 @@
import { describe, expect, test } from 'vitest'
import { formatEveDate, formatIsk } from './formaters'
describe('formatIsk', () => {
test('Formats ISK correctly', () => {
expect(formatIsk(123456789)).toBe('123.456.789,00 ISK')
})
})
describe('formatEveDate', () => {
test('Formats EVE date correctly', () => {
const date = new Date(Date.UTC(2022, 0, 1, 0, 0))
expect(formatEveDate(date)).toBe('2022.1.1 0:0')
})
test('Returns empty string for undefined date', () => {
expect(formatEveDate()).toBe('')
})
test('Returns empty string for null date', () => {
expect(formatEveDate(null)).toBe('')
})
})

View File

@@ -11,4 +11,4 @@ export const percentFormater = new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0 maximumFractionDigits: 0
}); });
export const formatEveDate = (date?: Date) => !date ? '' : `${date.getUTCFullYear()}.${date.getUTCMonth() + 1}.${date.getUTCDate()} ${date.getUTCHours()}:${date.getUTCMinutes()}`; export const formatEveDate = (date?: Date | null) => !date ? '' : `${date.getUTCFullYear()}.${date.getUTCMonth() + 1}.${date.getUTCDate()} ${date.getUTCHours()}:${date.getUTCMinutes()}`;