20260922172938

This commit is contained in:
oneao committed 2026-09-22 17:29:39 +08:00
1 parent 583984c24f
commit c8dad8d4a6
46 files changed
+3366 -1246

No files matched your search

@@ -64,6 +64,8 @@ function moduleRow(id, name) {
b_canuse: 1,
b_xh: 10,
b_bz: null,
// 迁移后 s_module 才有这一列(见 sql/fms_module_updated_at.sql)
b_updated_at: '2026-09-01 08:00:00',
}
}
@@ -572,3 +574,136 @@ describe('模块管理:保存后的未保存判定', () => {
)
})
})
describe('模块管理:卡头信息与刷新', () => {
const LOCAL_DATETIME = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/
it('保存主表变更时写入 b_updated_at,且时间戳不进草稿、不会让表单重新变脏', async () => {
const wrapper = await mountManagement()
await flushPromises()
wrapper.vm.moduleSelectedId = 'demo'
await flushPromises()
await flushPromises()
wrapper.vm.maindata.b_name = '改名后'
await wrapper.vm.handleSave()
await settleConfigReload(wrapper)
const moduleReq = savedRequests.find((request) => request.table === 's_module')
expect(moduleReq.updates?.[0]).toMatchObject({
b_id: 'demo',
b_name: '改名后',
b_updated_at: expect.stringMatching(LOCAL_DATETIME),
})
// 时间戳若被写进草稿,重载后的基线与草稿就会不一致,这里会判定为仍有未保存改动
expect(wrapper.vm.hasUnsavedChanges()).toBe(false)
})
it('只改子表(多语言)时也刷新模块的最后保存时间', async () => {
const wrapper = await mountManagement()
await flushPromises()
wrapper.vm.moduleSelectedId = 'demo'
await flushPromises()
await flushPromises()
const row = wrapper.vm.i18n.find((item) => item.b_key === 'module.demo')
row['en-US'] = 'Demo module v2'
await wrapper.vm.handleSave()
await settleConfigReload(wrapper)
// 主表行本身没有变化,仍要补一条只写时间戳的 update,否则卡头时间会停在改主表的时刻
const moduleReq = savedRequests.find((request) => request.table === 's_module')
expect(moduleReq.updates).toEqual([
{ b_id: 'demo', b_updated_at: expect.stringMatching(LOCAL_DATETIME) },
])
expect(wrapper.vm.hasUnsavedChanges()).toBe(false)
})
it('库里还没有 b_updated_at 列时(迁移未执行)不补时间戳更新', async () => {
delete db.s_module.find((item) => item.b_id === 'demo').b_updated_at
const wrapper = await mountManagement()
await flushPromises()
wrapper.vm.moduleSelectedId = 'demo'
await flushPromises()
await flushPromises()
const row = wrapper.vm.i18n.find((item) => item.b_key === 'module.demo')
row['en-US'] = 'Demo module v2'
await wrapper.vm.handleSave()
await settleConfigReload(wrapper)
// 只写不存在列的 update 会被后端以「没有可修改的字段」拒绝,整次保存回滚
expect(savedRequests.some((request) => request.table === 's_module')).toBe(false)
})
it('刷新:有未保存草稿时先弹确认,放弃后原地重载并丢弃草稿', async () => {
const wrapper = await mountManagement()
await flushPromises()
wrapper.vm.moduleSelectedId = 'demo'
await flushPromises()
await flushPromises()
wrapper.vm.maindata.b_name = '改名后'
wrapper.vm.requestReloadConfig()
await flushPromises()
expect(wrapper.vm.switchConfirm).toMatchObject({ pendingId: 'demo', reload: true })
await wrapper.vm.onSwitchDiscard()
await settleConfigReload(wrapper)
expect(String(wrapper.vm.moduleSelectedId)).toBe('demo')
expect(wrapper.vm.maindata.b_name).toBe('示例模块')
expect(wrapper.vm.hasUnsavedChanges()).toBe(false)
})
it('刷新:确认框选「保存并刷新」时保存后原地重载,不切换目标', async () => {
const wrapper = await mountManagement()
await flushPromises()
wrapper.vm.moduleSelectedId = 'demo'
await flushPromises()
await flushPromises()
wrapper.vm.maindata.b_name = '改名后'
wrapper.vm.requestReloadConfig()
await flushPromises()
await wrapper.vm.onSwitchSave()
await settleConfigReload(wrapper)
expect(wrapper.vm.switchConfirm).toBe(null)
expect(String(wrapper.vm.moduleSelectedId)).toBe('demo')
expect(wrapper.vm.maindata.b_name).toBe('改名后')
expect(wrapper.vm.hasUnsavedChanges()).toBe(false)
})
it('刷新:无未保存改动时直接重载,不弹确认框', async () => {
const wrapper = await mountManagement()
await flushPromises()
wrapper.vm.moduleSelectedId = 'demo'
await flushPromises()
await flushPromises()
loadDataApi.mockClear()
wrapper.vm.requestReloadConfig()
await settleConfigReload(wrapper)
expect(wrapper.vm.switchConfirm).toBe(null)
expect(loadDataApi).toHaveBeenCalledWith('s_module', "b_id = N'demo'")
})
it('卡头「更多」删除模块走与树右键相同的入口', async () => {
const wrapper = await mountManagement()
await flushPromises()
wrapper.vm.moduleSelectedId = 'demo'
await flushPromises()
await flushPromises()
wrapper.vm.onMoreAction({ key: 'delete' })
await flushPromises()
expect(wrapper.vm.confirmVisible).toBe(true)
expect(wrapper.vm.confirmState?.title).toBe('删除模块')
})
})