45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import type { UserInfo } from '@/types/common'
|
|
import {
|
|
buildCustomerCreateDraft,
|
|
resolveCustomerDisplay,
|
|
validateAppointmentCustomerSelection
|
|
} from '@/utils/customer-selection'
|
|
|
|
describe('customer selection helpers', () => {
|
|
it('requires a selected customer id before appointment submit', () => {
|
|
expect(validateAppointmentCustomerSelection('', '王女士', '13800138000')).toBe('请先选择客户或新增客户')
|
|
expect(validateAppointmentCustomerSelection('42', '', '13800138000')).toBe('请补全客户姓名和手机号')
|
|
expect(validateAppointmentCustomerSelection('42', '王女士', '13800138000')).toBeNull()
|
|
})
|
|
|
|
it('resolves selected customer display data from existing user', () => {
|
|
const customer: UserInfo = {
|
|
id: 42,
|
|
nickname: '王女士',
|
|
phone: '13800138000',
|
|
avatar: 'https://img.test/avatar.jpg'
|
|
}
|
|
|
|
expect(resolveCustomerDisplay(customer)).toEqual({
|
|
id: '42',
|
|
name: '王女士',
|
|
phone: '13800138000',
|
|
avatar: 'https://img.test/avatar.jpg',
|
|
initial: '王',
|
|
searchText: '王女士 13800138000'
|
|
})
|
|
})
|
|
|
|
it('prefills quick create form from search keyword', () => {
|
|
expect(buildCustomerCreateDraft('王女士 13800138000')).toEqual({
|
|
nickname: '王女士',
|
|
phone: '13800138000'
|
|
})
|
|
expect(buildCustomerCreateDraft('13800138000')).toEqual({
|
|
nickname: '',
|
|
phone: '13800138000'
|
|
})
|
|
})
|
|
})
|