fix(family): showModal editable 类型扩展与测试空值断言,tsc --noEmit 清零
This commit is contained in:
parent
5627be98f7
commit
0cb618be58
|
|
@ -10,6 +10,19 @@ import { navigateTo } from '@/utils/navigation'
|
|||
import { showToast } from '@/utils/toast'
|
||||
import styles from './index.module.scss'
|
||||
|
||||
// Taro 类型未跟进 wx.showModal 的 editable 扩展(微信 2.17.1+),运行时真实存在
|
||||
interface EditableModalOption extends Taro.showModal.Option {
|
||||
editable?: boolean
|
||||
placeholderText?: string
|
||||
}
|
||||
|
||||
interface EditableModalResult extends Taro.showModal.SuccessCallbackResult {
|
||||
content?: string
|
||||
}
|
||||
|
||||
const showEditableModal = (option: EditableModalOption) =>
|
||||
Taro.showModal(option as Taro.showModal.Option) as Promise<EditableModalResult>
|
||||
|
||||
export default function Family() {
|
||||
const [list, setList] = useState<Family[]>([])
|
||||
const [showCreateModal, setShowCreateModal] = useState(false)
|
||||
|
|
@ -30,37 +43,35 @@ export default function Family() {
|
|||
const goDetail = (id: string) => navigateTo(`${ROUTES.FAMILY_DETAIL}?id=${id}`)
|
||||
|
||||
const createFamily = () => {
|
||||
Taro.showModal({
|
||||
showEditableModal({
|
||||
title: '新建家庭',
|
||||
editable: true,
|
||||
placeholderText: '请输入家庭名',
|
||||
success: async ({ confirm, content }) => {
|
||||
if (!confirm) return
|
||||
try {
|
||||
await addFamily(content ?? '')
|
||||
setShowCreateModal(false)
|
||||
await reload()
|
||||
} catch (error) {
|
||||
showToast(error instanceof Error ? error.message : '创建失败')
|
||||
}
|
||||
placeholderText: '请输入家庭名'
|
||||
}).then(async ({ confirm, content }) => {
|
||||
if (!confirm) return
|
||||
try {
|
||||
await addFamily(content ?? '')
|
||||
setShowCreateModal(false)
|
||||
await reload()
|
||||
} catch (error) {
|
||||
showToast(error instanceof Error ? error.message : '创建失败')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const joinByCode = () => {
|
||||
Taro.showModal({
|
||||
showEditableModal({
|
||||
title: '加入家庭',
|
||||
editable: true,
|
||||
placeholderText: '请输入家庭编号',
|
||||
success: async ({ confirm, content }) => {
|
||||
if (!confirm) return
|
||||
try {
|
||||
await joinFamily(content ?? '')
|
||||
setShowCreateModal(false)
|
||||
await reload()
|
||||
} catch (error) {
|
||||
showToast(error instanceof Error ? error.message : '加入失败')
|
||||
}
|
||||
placeholderText: '请输入家庭编号'
|
||||
}).then(async ({ confirm, content }) => {
|
||||
if (!confirm) return
|
||||
try {
|
||||
await joinFamily(content ?? '')
|
||||
setShowCreateModal(false)
|
||||
await reload()
|
||||
} catch (error) {
|
||||
showToast(error instanceof Error ? error.message : '加入失败')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,10 +68,11 @@ describe('家庭圈 mock 数据层', () => {
|
|||
it('getFamilyDetail 返回家庭 + 成员 + 关爱对象', async () => {
|
||||
await getFamilies()
|
||||
const detail = await getFamilyDetail('846443196293189')
|
||||
expect(detail.family.name).toBe('JollyPlace')
|
||||
expect(detail.members.length).toBe(2)
|
||||
expect(detail.cared.length).toBe(1)
|
||||
expect(detail.cared[0].name).toBe('Jay')
|
||||
expect(detail).not.toBeNull()
|
||||
expect(detail!.family.name).toBe('JollyPlace')
|
||||
expect(detail!.members.length).toBe(2)
|
||||
expect(detail!.cared.length).toBe(1)
|
||||
expect(detail!.cared[0].name).toBe('Jay')
|
||||
})
|
||||
|
||||
it('getFamilyDetail 不存在返回 null', async () => {
|
||||
|
|
@ -94,9 +95,10 @@ describe('家庭圈 mock 数据层', () => {
|
|||
const saved = await addCared(caredInput())
|
||||
expect(saved.id).toBeTruthy()
|
||||
const detail = await getFamilyDetail('735201884550361')
|
||||
expect(detail.family.caredCount).toBe(1)
|
||||
expect(detail.family.caredLabel).toBe('王奶奶')
|
||||
expect(detail.cared[0].contacts).toEqual([])
|
||||
expect(detail).not.toBeNull()
|
||||
expect(detail!.family.caredCount).toBe(1)
|
||||
expect(detail!.family.caredLabel).toBe('王奶奶')
|
||||
expect(detail!.cared[0].contacts).toEqual([])
|
||||
})
|
||||
|
||||
it('addCared 达上限抛错', async () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue