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>
This commit is contained in:
2026-11-12 11:20:18 +03:00
parent 7143613ab2
commit f930f2fbcc
14 changed files with 696 additions and 5 deletions
@@ -0,0 +1,41 @@
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')
})
})