feat(pl): 实现合同产品用证与额度结转以支持购买证和运输证全流程管理。
This commit is contained in:
1 parent
cb0344498a
commit
fb866c7fa7
104 files changed
+10187
-3833
No files matched your search
@@ -79,7 +79,7 @@ function harness(file: string) {
|
||||
run: (reset: boolean) => api.run(fn === 'load' ? !reset : reset)
|
||||
}
|
||||
}
|
||||
for (const file of ['plan/index.vue', 'plan-cert/index.vue']) {
|
||||
for (const file of ['plan/index.vue']) {
|
||||
test(`${file}: latest search wins including stale failure and finally`, async () => {
|
||||
const h = harness(file)
|
||||
const old = h.run(true)
|
||||
@@ -138,7 +138,7 @@ for (const file of ['plan/index.vue', 'plan-cert/index.vue']) {
|
||||
})
|
||||
}
|
||||
|
||||
function actionHarness(file: string, overrides: any = {}) {
|
||||
function actionHarness(file: string) {
|
||||
const userStore = reactive({
|
||||
accessToken: 'session-a',
|
||||
getUserInfo: { tenantNo: 'tenant-a', roles: ['sales'] }
|
||||
@@ -151,7 +151,6 @@ function actionHarness(file: string, overrides: any = {}) {
|
||||
const plan = { id: 'p1', products: [] }
|
||||
const state: any = {
|
||||
acting: ref(false),
|
||||
canReady: ref(true),
|
||||
morePlan: ref(plan),
|
||||
moreOpen: ref(true),
|
||||
voidTarget: ref(plan),
|
||||
@@ -161,19 +160,14 @@ function actionHarness(file: string, overrides: any = {}) {
|
||||
canWaitNotice: () => true,
|
||||
canCancelWaitNotice: () => true,
|
||||
canVoidPlan: () => true,
|
||||
readyTargets: (rows: any[]) => rows,
|
||||
refreshSidebarBadges: async () => {},
|
||||
planHasHazardProducts: () => true,
|
||||
HAZARD_CERT_READY_CONFIRM_HINT: '',
|
||||
showCrmConfirmDialog: () => {
|
||||
events.push('confirm')
|
||||
return confirm
|
||||
},
|
||||
planApi: {
|
||||
get: async (id: string) => ({ id, products: [] }),
|
||||
setHazardCertReady: async (id: string) => {
|
||||
events.push(`ready:${id}`)
|
||||
},
|
||||
cancel: async (id: string, data: any) => {
|
||||
events.push(`void:${id}:${data.cancelReason}`)
|
||||
},
|
||||
@@ -202,8 +196,7 @@ function actionHarness(file: string, overrides: any = {}) {
|
||||
ts.ScriptTarget.Latest,
|
||||
true
|
||||
)
|
||||
Object.assign(state.planApi, overrides.planApi || {})
|
||||
const names = ['setReady', 'runMoreAction', 'confirmVoidPlan']
|
||||
const names = ['runMoreAction', 'confirmVoidPlan']
|
||||
const code = ts.transpile(
|
||||
source.statements
|
||||
.filter(
|
||||
@@ -218,7 +211,7 @@ function actionHarness(file: string, overrides: any = {}) {
|
||||
)
|
||||
const api = new Function(
|
||||
...Object.keys(state),
|
||||
`let disposed=false; let actionVersion=0; ${code}; return { run: ${file.startsWith('plan-cert') ? '(row={id:"p1"})=>setReady(typeof row==="object"?row:{id:"p1"},true)' : '(key)=>key==="void" ? confirmVoidPlan() : runMoreAction(key)'}, dispose:()=>{disposed=true;actionVersion++}, invalidate:()=>{actionVersion++;acting.value=false} }`
|
||||
`let disposed=false; let actionVersion=0; ${code}; return { run: (key)=>key==="void" ? confirmVoidPlan() : runMoreAction(key), dispose:()=>{disposed=true;actionVersion++}, invalidate:()=>{actionVersion++;acting.value=false} }`
|
||||
)(...Object.values(state))
|
||||
return {
|
||||
state,
|
||||
@@ -230,10 +223,10 @@ function actionHarness(file: string, overrides: any = {}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const kind of ['ready', 'wait', 'cancel-wait', 'void']) {
|
||||
for (const kind of ['wait', 'cancel-wait', 'void']) {
|
||||
for (const invalidation of ['dispose', 'scope', 'session']) {
|
||||
test(`${kind}: confirmation followed by ${invalidation} in same tick does not write`, async () => {
|
||||
const h = actionHarness(kind === 'ready' ? 'plan-cert/index.vue' : 'plan/index.vue')
|
||||
const h = actionHarness('plan/index.vue')
|
||||
const pending = h.run(kind)
|
||||
for (let n = 0; n < 5; n++) await Promise.resolve()
|
||||
assert.ok(h.events.includes('confirm'))
|
||||
@@ -246,7 +239,7 @@ for (const kind of ['ready', 'wait', 'cancel-wait', 'void']) {
|
||||
})
|
||||
}
|
||||
test(`${kind}: duplicate confirmation is locked before dialog, captured target/reason is written once`, async () => {
|
||||
const h = actionHarness(kind === 'ready' ? 'plan-cert/index.vue' : 'plan/index.vue')
|
||||
const h = actionHarness('plan/index.vue')
|
||||
const pending = h.run(kind)
|
||||
for (let n = 0; n < 5; n++) await Promise.resolve()
|
||||
const duplicate = h.run(kind)
|
||||
@@ -387,7 +380,7 @@ function mountTemplate(file: string, mode = 'manage') {
|
||||
return { state, find, app }
|
||||
}
|
||||
|
||||
for (const file of ['plan/index.vue', 'plan-cert/index.vue']) {
|
||||
for (const file of ['plan/index.vue']) {
|
||||
test(`${file}: header input survives reload, empty result, error and retry`, async () => {
|
||||
const { state, find, app } = mountTemplate(file)
|
||||
const input = find('input')
|
||||
@@ -502,7 +495,7 @@ function returnStateHarness(base = '/m/pl/plan') {
|
||||
return { create, navigate, openDetail, user, scrolls }
|
||||
}
|
||||
|
||||
for (const base of ['/m/pl/plan', '/m/pl/plan-cert']) {
|
||||
for (const base of ['/m/pl/plan']) {
|
||||
test(`${base}: details restore filters/pages/expanded/scroll with no row cache`, async () => {
|
||||
const env = returnStateHarness(base)
|
||||
const list = env.create()
|
||||
@@ -549,49 +542,7 @@ const flush = async () => {
|
||||
for (let n = 0; n < 20; n++) await Promise.resolve()
|
||||
}
|
||||
|
||||
for (const response of [{ id: 'B', products: [] }, { products: [] }, null]) {
|
||||
test(`ready: deferred GET A returning ${JSON.stringify(response)} cannot confirm or write another record`, async () => {
|
||||
const get = deferred()
|
||||
const h = actionHarness('plan-cert/index.vue', { planApi: { get: () => get.promise } })
|
||||
h.confirmResolve()
|
||||
const pending = h.run({ id: 'A' })
|
||||
await flush()
|
||||
assert.deepEqual(h.events, [])
|
||||
get.resolve({ data: response })
|
||||
await pending
|
||||
assert.deepEqual(h.events, ['toast'])
|
||||
assert.equal(h.state.acting.value, false)
|
||||
})
|
||||
}
|
||||
for (const failure of ['get', 'write']) {
|
||||
test(`ready: delayed ${failure} failure and revoked permission cannot show stale result or refresh`, async () => {
|
||||
const pendingApi = deferred()
|
||||
const gets: string[] = [],
|
||||
writes: string[] = []
|
||||
const h = actionHarness('plan-cert/index.vue', {
|
||||
planApi: {
|
||||
get: (id: string) => {
|
||||
gets.push(id)
|
||||
return failure === 'get' ? pendingApi.promise : Promise.resolve({ id, products: [] })
|
||||
},
|
||||
setHazardCertReady: (id: string) => {
|
||||
writes.push(id)
|
||||
return pendingApi.promise
|
||||
}
|
||||
}
|
||||
})
|
||||
h.confirmResolve()
|
||||
const pending = h.run({ id: 'A' })
|
||||
await flush()
|
||||
h.state.canReady.value = false
|
||||
pendingApi.reject(new Error('late failure'))
|
||||
await pending
|
||||
assert.deepEqual(gets, ['A'])
|
||||
assert.deepEqual(writes, failure === 'get' ? [] : ['A'])
|
||||
assert.deepEqual(h.events, failure === 'get' ? [] : ['confirm'])
|
||||
})
|
||||
}
|
||||
for (const file of ['plan/index.vue', 'plan-cert/index.vue']) {
|
||||
for (const file of ['plan/index.vue']) {
|
||||
for (const outcome of ['success', 'error']) {
|
||||
test(`${file}: actual requestKey and sessionScope discard old ${outcome} after tenant change`, async () => {
|
||||
const h = harness(file)
|
||||
@@ -744,190 +695,3 @@ for (const change of ['token', 'tenant', 'roles']) {
|
||||
h.stop()
|
||||
})
|
||||
}
|
||||
|
||||
// Execute the production setup and Vue watchers, stubbing only external services/hooks.
|
||||
function certSessionHarness() {
|
||||
const lists: any[] = [],
|
||||
permissions: any[] = [],
|
||||
gets: any[] = [],
|
||||
writes: any[] = []
|
||||
const events: string[] = []
|
||||
const user = reactive({ accessToken: 'a', getUserInfo: { tenantNo: 'a', roles: ['sales'] } })
|
||||
const queue = (items: any[], params?: any) => {
|
||||
const request = deferred()
|
||||
items.push({ ...request, params })
|
||||
return request.promise
|
||||
}
|
||||
const env = {
|
||||
...Object.fromEntries(
|
||||
Object.entries(vue).filter(([key]) => /^[a-zA-Z_$][\w$]*$/.test(key) && key !== 'default')
|
||||
),
|
||||
useUserStore: () => user,
|
||||
useRouter: () => ({ push: (path: string) => events.push(path) }),
|
||||
useMenuStore: () => ({ refreshSidebarBadges: async () => {} }),
|
||||
onBeforeUnmount: () => {},
|
||||
useDebounceFn: (fn: any) => fn,
|
||||
useIntersectionObserver: () => {},
|
||||
useListReturnState: () => ({ restoring: ref(false), restore: () => events.push('restore') }),
|
||||
useMobilePlanListDetails: () => ({ reset() {}, ensure: async () => true, records: {} }),
|
||||
PL_PLAN_DEFAULT_FOLLOW_STATUSES: ['pending'],
|
||||
plPlanCertColumnFilterDefs: [],
|
||||
useServerColumnFilters: (_defs: any, options: any) => {
|
||||
const filters = reactive(options.initialFilters)
|
||||
return { filters, toQueryParams: () => ({ ...filters }) }
|
||||
},
|
||||
buildQuery: (tab: string, filters: any, keyword: string, dates: any) => ({
|
||||
tab,
|
||||
filters,
|
||||
keyword,
|
||||
dates
|
||||
}),
|
||||
applyMergedCustomerQueryParams: () => {},
|
||||
applyContractSideQueryParams: () => {},
|
||||
canEdit: () => true,
|
||||
readyTargets: (rows: any[]) => rows,
|
||||
planHasHazardProducts: () => true,
|
||||
HAZARD_CERT_READY_CONFIRM_HINT: '',
|
||||
showCrmConfirmDialog: async () => {
|
||||
events.push('confirm')
|
||||
},
|
||||
ElMessage: Object.assign(() => events.push('toast'), { warning: () => events.push('toast') }),
|
||||
planApi: {
|
||||
list: (params: any) => queue(lists, params),
|
||||
get: (id: string) => queue(gets, id),
|
||||
setHazardCertReady: (id: string) => queue(writes, id)
|
||||
},
|
||||
fetchGetMenuCodes: () => queue(permissions)
|
||||
}
|
||||
const source = ts.createSourceFile(
|
||||
'page.ts',
|
||||
parse(readFileSync(new URL('plan-cert/index.vue', root), 'utf8')).descriptor.scriptSetup!
|
||||
.content,
|
||||
ts.ScriptTarget.Latest,
|
||||
true
|
||||
)
|
||||
const code = ts.transpile(
|
||||
source.statements
|
||||
.filter((s) => !ts.isImportDeclaration(s))
|
||||
.map((s) => s.getText(source))
|
||||
.join('\n'),
|
||||
{ target: ts.ScriptTarget.ESNext }
|
||||
)
|
||||
const scope = vue.effectScope()
|
||||
const state = scope.run(() =>
|
||||
new Function(
|
||||
...Object.keys(env),
|
||||
`${code}; return { load, loadPermissions, setReady, saved, openUpload, userStore, plans, expandedIds, total, page, loading, acting, error, failedMore, canUpload, canReady, canPrice, permissionsLoaded, permissionError, uploadOpen, uploadId, keyword, appliedKeyword, dates, dateKind, readyKind, tab, filters, sort, filtersOpen, ${code.includes('function reloadSession') ? 'reloadSession, sessionChanged, uploadRef,' : ''} }`
|
||||
)(...Object.values(env))
|
||||
)
|
||||
return { state, user, lists, permissions, gets, writes, events, stop: () => scope.stop() }
|
||||
}
|
||||
|
||||
for (const change of ['token', 'tenant', 'roles']) {
|
||||
test(`cert session: ${change} synchronously clears private state and recovers without old callbacks`, async () => {
|
||||
const h = certSessionHarness(),
|
||||
s = h.state
|
||||
s.plans.value = [{ id: 'private' }]
|
||||
s.loading.value = false
|
||||
s.total.value = 40
|
||||
s.page.value = 2
|
||||
s.expandedIds.value = new Set(['private'])
|
||||
s.keyword.value = s.appliedKeyword.value = 'private keyword'
|
||||
s.filters.customer = { text: 'private customer' }
|
||||
s.filtersOpen.value = true
|
||||
const oldPermission = s.loadPermissions()
|
||||
s.canUpload.value = s.canReady.value = s.canPrice.value = true
|
||||
s.openUpload({ id: 'private' })
|
||||
let invalidations = 0
|
||||
if (s.uploadRef) s.uploadRef.value = { invalidateRecord: () => invalidations++ }
|
||||
const oldAction = s.setReady({ id: 'private' }, true)
|
||||
const oldList = s.load(true)
|
||||
h.user.getUserInfo = { tenantNo: 'a', roles: ['sales'] }
|
||||
assert.equal(s.loading.value, true, 'same-content user info does not invalidate')
|
||||
if (change === 'token') h.user.accessToken = 'b'
|
||||
if (change === 'tenant') h.user.getUserInfo.tenantNo = 'b'
|
||||
if (change === 'roles') h.user.getUserInfo.roles = ['viewer']
|
||||
assert.deepEqual(s.plans.value, [], 'old tenant rows must clear synchronously')
|
||||
assert.equal(s.loading.value, false)
|
||||
assert.equal(s.acting.value, false)
|
||||
for (const name of ['canUpload', 'canReady', 'canPrice', 'uploadOpen', 'filtersOpen'])
|
||||
assert.equal(s[name].value, false)
|
||||
assert.equal(s.uploadId.value, '')
|
||||
assert.equal(invalidations, 1, 'child must invalidate before Vue propagates props')
|
||||
assert.equal(s.total.value, 0)
|
||||
assert.equal(s.page.value, 1)
|
||||
assert.equal(s.expandedIds.value.size, 0)
|
||||
assert.equal(s.keyword.value + s.appliedKeyword.value, '')
|
||||
assert.equal(s.filters.customer, undefined)
|
||||
assert.equal(s.sessionChanged.value, true)
|
||||
await s.saved('private')
|
||||
assert.equal(h.lists.length, 1, 'late upload success cannot trigger reload')
|
||||
const recovery = s.reloadSession()
|
||||
assert.equal(h.lists[1].params.page, 1)
|
||||
assert.equal(h.lists[1].params.keyword, '')
|
||||
h.permissions[0].resolve({ all: true })
|
||||
h.lists[0].reject(new Error('old tenant failed'))
|
||||
h.gets[0].resolve({ id: 'private', products: [] })
|
||||
await Promise.all([oldPermission, oldList, oldAction])
|
||||
assert.equal(s.loading.value, true, 'old finally cannot release fresh load')
|
||||
assert.equal(s.canUpload.value, false)
|
||||
assert.equal(s.error.value, '')
|
||||
assert.deepEqual(h.events, [])
|
||||
h.permissions[1].resolve({ menuCodes: ['pl:plan-cert:upload'] })
|
||||
h.lists[1].resolve({ list: [{ id: 'fresh' }], total: 1 })
|
||||
await recovery
|
||||
assert.deepEqual(s.plans.value, [{ id: 'fresh' }])
|
||||
assert.equal(s.canUpload.value, true)
|
||||
assert.equal(s.canReady.value, false)
|
||||
assert.equal(s.loading.value, false)
|
||||
h.stop()
|
||||
})
|
||||
}
|
||||
|
||||
for (const outcome of ['success', 'failure']) {
|
||||
test(`cert session: late ${outcome} write cannot release a new action or reload`, async () => {
|
||||
const h = certSessionHarness(),
|
||||
s = h.state
|
||||
s.canReady.value = true
|
||||
const old = s.setReady({ id: 'private' }, true)
|
||||
h.gets[0].resolve({ id: 'private', products: [] })
|
||||
await flush()
|
||||
assert.equal(h.writes.length, 1)
|
||||
h.user.accessToken = 'b'
|
||||
s.canReady.value = true
|
||||
const fresh = s.setReady({ id: 'fresh' }, true)
|
||||
if (outcome === 'success') h.writes[0].resolve()
|
||||
else h.writes[0].reject(new Error('late write failure'))
|
||||
await old
|
||||
assert.equal(s.acting.value, true)
|
||||
assert.equal(h.lists.length, 0)
|
||||
assert.deepEqual(h.events, ['confirm'])
|
||||
h.gets[1].resolve({ id: 'fresh', products: [] })
|
||||
await flush()
|
||||
h.writes[1].resolve()
|
||||
await flush()
|
||||
assert.equal(h.lists.length, 1)
|
||||
h.lists[0].resolve({ list: [{ id: 'fresh' }], total: 1 })
|
||||
await fresh
|
||||
assert.equal(s.acting.value, false)
|
||||
h.stop()
|
||||
})
|
||||
}
|
||||
|
||||
for (const changed of [false, true]) {
|
||||
test(`cert session: upload success ${changed ? 'cannot navigate after scope change during refresh' : 'navigates after normal child close'}`, async () => {
|
||||
const h = certSessionHarness(),
|
||||
s = h.state
|
||||
s.canUpload.value = true
|
||||
s.openUpload({ id: 'target' })
|
||||
s.uploadOpen.value = false // The child closes its v-model before emitting success.
|
||||
const saved = s.saved('target')
|
||||
assert.equal(h.lists.length, 1)
|
||||
if (changed) h.user.accessToken = 'b'
|
||||
h.lists[0].resolve({ list: [{ id: 'target' }], total: 1 })
|
||||
await saved
|
||||
assert.deepEqual(h.events, changed ? [] : ['/m/pl/plan-cert/target'])
|
||||
assert.deepEqual(s.plans.value, changed ? [] : [{ id: 'target' }])
|
||||
h.stop()
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user