fix: resolve ui audit bugs
ci / docker (push) Successful in 3m30s

This commit is contained in:
2026-09-07 09:08:22 +08:00
parent 6f7694c23e
commit ec90e9155e
7 changed files with 119 additions and 16 deletions
+28
View File
@@ -93,3 +93,31 @@ export function calendarModeLabel(mode: string) {
export function shouldToggleRowSwipe(deltaX: number, deltaY: number) {
return deltaX >= 64 && deltaX > Math.abs(deltaY) * 1.5
}
export function nextTotalAfterLocalTaskAdd(total: number) {
return Math.max(0, Number(total) || 0) + 1
}
export function formatApiErrorDetail(detail: unknown): string {
if (typeof detail === 'string') return detail
if (Array.isArray(detail)) {
const messages = detail.map((item) => {
if (item && typeof item === 'object') {
const record = item as Record<string, unknown>
const location = Array.isArray(record.loc)
? record.loc.filter((part) => part !== 'body').join('.')
: ''
const message = typeof record.msg === 'string' ? record.msg : JSON.stringify(record)
return location ? `${location}${message}` : message
}
return String(item)
})
return messages.filter(Boolean).join('') || '请求参数有误'
}
if (detail && typeof detail === 'object') {
const record = detail as Record<string, unknown>
if ('detail' in record) return formatApiErrorDetail(record.detail)
return JSON.stringify(record)
}
return '请求失败'
}
+20
View File
@@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest'
import { formatApiErrorDetail, nextTotalAfterLocalTaskAdd } from './mvp-utils'
describe('UI bugfix helpers', () => {
it('formats FastAPI validation arrays into readable messages', () => {
expect(formatApiErrorDetail([
{ loc: ['body', 'lunar_day'], msg: 'Input should be less than or equal to 30' },
{ loc: ['body', 'title'], msg: 'String should have at least 1 character' },
])).toBe('lunar_dayInput should be less than or equal to 30titleString should have at least 1 character')
})
it('formats nested API detail objects instead of [object Object]', () => {
expect(formatApiErrorDetail({ detail: [{ loc: ['body', 'event_date'], msg: 'Input should be a valid date' }] })).toBe('event_dateInput should be a valid date')
})
it('increments the visible total after a local quick-add insert', () => {
expect(nextTotalAfterLocalTaskAdd(0)).toBe(1)
expect(nextTotalAfterLocalTaskAdd(49)).toBe(50)
})
})