Files
kakeibo/frontend/src/features/ledger/schema.test.ts
T
suphicakir f930f2fbcc feat(defter): hafta seçici ve hızlı harcama giriş formu
- /defter: önceki/sonraki/bu hafta, haftanın harcanan/bütçe toplamı
- Form: tutar, 4 grup düğmesi, kategori ve ödeme türü seçimi, tarih, açıklama
- Son seçimler bu cihazda hatırlanır; sunucu hataları ilgili alana düşer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 11:20:18 +03:00

42 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest'
import { entrySchema, fieldForError } from './schema'
const schema = entrySchema('2026-12-01', '2026-12-31')
const ok = {
amount: '1.250,50',
group: 'needs',
category_id: 'c1',
payment_method_id: '',
date: '2026-12-31',
description: '',
}
const errorsOf = (v: object) =>
schema.safeParse({ ...ok, ...v }).error?.issues.map((i) => [i.path[0], i.message]) ?? []
describe('entry form', () => {
it('accepts a valid entry', () => {
expect(schema.safeParse(ok).success).toBe(true)
})
it('rejects missing and out-of-range values with Turkish messages', () => {
expect(errorsOf({ amount: '' })).toEqual([['amount', 'Tutarı yazın']])
expect(errorsOf({ amount: '0' })).toEqual([['amount', 'Tutar sıfırdan büyük olmalı']])
expect(errorsOf({ group: '' })).toEqual([['group', 'Ana grubu seçin']])
expect(errorsOf({ category_id: '' })).toEqual([['category_id', 'Kategori seçin']])
expect(errorsOf({ date: '2027-01-01' })).toEqual([['date', 'Tarih dönem içinde olmalı']])
expect(errorsOf({ date: '' })).toEqual([['date', 'Tarih geçersiz']])
})
it('counts description characters like the backend', () => {
expect(errorsOf({ description: '🛒'.repeat(200) })).toEqual([])
expect(errorsOf({ description: 'a'.repeat(201) })[0][0]).toBe('description')
})
it('maps server messages to fields', () => {
expect(fieldForError('Tarih dönem içinde olmalı')).toBe('date')
expect(fieldForError('Bu kategori pasif; başka bir kategori seçin')).toBe('category_id')
expect(fieldForError('Bu ödeme türü pasif; başka birini seçin')).toBe('payment_method_id')
expect(fieldForError('Bağlantı kurulamadı')).toBe('root')
})
})