feat: 优化预定页面UI和交互

This commit is contained in:
richarjiang
2026-09-10 11:00:13 +08:00
parent 22407a7ff9
commit 51dea488f6
3 changed files with 740 additions and 366 deletions

View File

@@ -187,6 +187,7 @@ describe('BookingService', () => {
count: jest.fn(),
create: jest.fn(),
update: jest.fn(),
groupBy: jest.fn(),
},
timeSlot: {
findUnique: jest.fn(),
@@ -1170,8 +1171,10 @@ describe('BookingService', () => {
membership: mockActiveMembership,
},
]
;(prisma.booking.groupBy as jest.Mock).mockResolvedValue([
{ status: BookingStatus.CONFIRMED, _count: { _all: 1 } },
])
;(prisma.booking.findMany as jest.Mock).mockResolvedValue(bookings)
;(prisma.booking.count as jest.Mock).mockResolvedValue(1)
const result = await service.getAllBookings(1, 10)
@@ -1191,6 +1194,45 @@ describe('BookingService', () => {
}),
)
})
it('sorts the unfiltered list by status priority and pages across segments', async () => {
// 全部视图:待确认 → 已确认 → 已完成 → 已取消,未到归入已完成之后
;(prisma.booking.groupBy as jest.Mock).mockResolvedValue([
{ status: BookingStatus.PENDING_CONFIRMATION, _count: { _all: 1 } },
{ status: BookingStatus.CONFIRMED, _count: { _all: 2 } },
{ status: BookingStatus.COMPLETED, _count: { _all: 1 } },
{ status: BookingStatus.CANCELLED, _count: { _all: 1 } },
])
const byStatus: Record<string, { id: string }[]> = {
[BookingStatus.PENDING_CONFIRMATION]: [{ id: 'b-pending' }],
[BookingStatus.CONFIRMED]: [{ id: 'b-confirmed-1' }, { id: 'b-confirmed-2' }],
[BookingStatus.COMPLETED]: [{ id: 'b-completed' }],
[BookingStatus.CANCELLED]: [{ id: 'b-cancelled' }],
}
;(prisma.booking.findMany as jest.Mock).mockImplementation(
(args: { where: { status: string } }) => byStatus[args.where.status] ?? [],
)
const page1 = await service.getAllBookings(1, 3)
expect(page1.total).toBe(5)
expect(page1.data.map((b) => b.id)).toEqual(['b-pending', 'b-confirmed-1', 'b-confirmed-2'])
const page2 = await service.getAllBookings(2, 3)
expect(page2.data.map((b) => b.id)).toEqual(['b-completed', 'b-cancelled'])
// 段内排序:已确认按上课时间正序,其余按创建时间倒序
const confirmedCall = (prisma.booking.findMany as jest.Mock).mock.calls.find(
([args]: [{ where: { status: string } }]) => args.where.status === BookingStatus.CONFIRMED,
)
expect(confirmedCall[0].orderBy).toEqual([
{ timeSlot: { date: 'asc' } },
{ timeSlot: { startTime: 'asc' } },
])
const pendingCall = (prisma.booking.findMany as jest.Mock).mock.calls.find(
([args]: [{ where: { status: string } }]) => args.where.status === BookingStatus.PENDING_CONFIRMATION,
)
expect(pendingCall[0].orderBy).toEqual({ createdAt: 'desc' })
})
})
describe('getTeachingScheduleByDate', () => {