恢复后台表单弹窗草稿

This commit is contained in:
2026-07-01 12:49:18 +08:00
parent 975cdb20cb
commit 9f1d2dec77
6 changed files with 409 additions and 28 deletions
@@ -0,0 +1,44 @@
import { beforeEach, describe, expect, it } from 'vitest'
import { buildFormModalDraftKey, readFormModalDraft, removeFormModalDraft, writeFormModalDraft } from '@/utils/form-modal-draft'
import type { UserInfo } from '@/types/common'
interface EmployeeDraftForm {
nickname: string
phone: string
}
const buildEmployeeDraftForm = (): EmployeeDraftForm => ({
nickname: '王女士',
phone: '13800138000'
})
describe('form modal draft storage', () => {
beforeEach(() => {
window.localStorage.clear()
window.sessionStorage.clear()
})
it('scopes draft by user, shop and modal name', () => {
const userInfo: UserInfo = { id: 10, shopId: 20 }
expect(buildFormModalDraftKey(userInfo, 'employee-create')).toBe('managerFormModalDraft:10:20:employee-create')
})
it('writes, reads and removes modal draft', () => {
const userInfo: UserInfo = { id: 10, shopId: 20 }
const form = buildEmployeeDraftForm()
writeFormModalDraft(userInfo, 'employee-create', form, true)
expect(readFormModalDraft<EmployeeDraftForm>(userInfo, 'employee-create')?.form).toEqual(form)
expect(readFormModalDraft<EmployeeDraftForm>(userInfo, 'employee-create')?.open).toBe(true)
removeFormModalDraft(userInfo, 'employee-create')
expect(readFormModalDraft<EmployeeDraftForm>(userInfo, 'employee-create')).toBeNull()
})
it('rejects invalid draft names', () => {
const userInfo: UserInfo = { id: 10, shopId: 20 }
expect(() => buildFormModalDraftKey(userInfo, ' ')).toThrow('弹窗草稿名称不能为空')
})
})