297 lines
12 KiB
TypeScript
297 lines
12 KiB
TypeScript
import { policyReceipt } from '../../fixtures/quality-policy'
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
|
import { actionExceptionTargets } from '@/features/breakdown/action-exceptions'
|
|
import ActionExceptionRepair from '@/features/breakdown/components/ActionExceptionRepair.vue'
|
|
import { breakdownQuality, selectBreakdownSource } from '@/features/breakdown/quality'
|
|
import { projectsApi } from '@/features/projects/api'
|
|
import type { ProjectQualityPolicy } from '@/features/projects/types'
|
|
import { candidateCheckpoint, candidateReview, resourceConflictState } from '../../fixtures/breakdown-candidate'
|
|
import { getOperation } from '@/features/workflows/operations'
|
|
|
|
/**
|
|
* 同阶段同一角色左手执行两个互斥动作,坐标与后端审核一致。
|
|
* @returns 独立的真实契约形状的候选与审核
|
|
*/
|
|
function conflict() {
|
|
const state = resourceConflictState()
|
|
const shot = state.storyboardEpisodeShots![0]!.beatShots[0]!.shots[0]!
|
|
const review = candidateReview({
|
|
actionQualityBlocks: [
|
|
{
|
|
episodeNo: 1,
|
|
beatNo: 1,
|
|
shotNo: 1,
|
|
status: 'blocked',
|
|
blockingCodes: ['action_resource_conflict'],
|
|
warningCodes: [],
|
|
isPendingEpisode: true
|
|
}
|
|
],
|
|
pendingQualityEpisodeNos: [1]
|
|
})
|
|
const quality = breakdownQuality(selectBreakdownSource([candidateCheckpoint(state)]), review)
|
|
return { state, quality, shot }
|
|
}
|
|
|
|
/** 已有例外与独立全局规则,写入时必须全部保留。 */
|
|
const policy: ProjectQualityPolicy = {
|
|
version: 1,
|
|
physicsMode: 'stylized',
|
|
allowExaggeratedMotion: true,
|
|
allowNonPhysicalActions: false,
|
|
allowSupernaturalAbilities: false,
|
|
customRules: ['跳跃后正常落地'],
|
|
actionExceptions: [
|
|
{ code: 'action_resource_conflict', ownerRef: '@CH0099', resource: 'right_hand', reason: '旧例外依据' }
|
|
]
|
|
}
|
|
/** 当前真实修订面板实例。 */
|
|
let wrapper: VueWrapper<InstanceType<typeof ActionExceptionRepair>> | undefined
|
|
afterEach(() => {
|
|
wrapper?.unmount()
|
|
wrapper = undefined
|
|
vi.restoreAllMocks()
|
|
localStorage.clear()
|
|
Object.assign(getOperation('candidate-project'), { pending: false, error: '', label: '', notice: '' })
|
|
})
|
|
|
|
describe('从实际问题建立动作例外', () => {
|
|
it('只从当前审核的互斥动作证据带入角色、部位与动作,不从文字猜测', () => {
|
|
const { state, quality, shot } = conflict()
|
|
expect(actionExceptionTargets(state, quality)).toMatchObject([
|
|
{
|
|
episodeNo: 1,
|
|
beatNo: 1,
|
|
shotNo: 1,
|
|
phaseNo: 1,
|
|
ownerRef: '@CH0001',
|
|
ownerName: '人物',
|
|
resource: 'left_hand',
|
|
actions: ['左手握住铜铃', '左手向村民挥动']
|
|
}
|
|
])
|
|
shot.durationPlanning!.phases[0]!.resourceOccupancy = []
|
|
expect(actionExceptionTargets(state, quality)).toEqual([])
|
|
})
|
|
|
|
it('不同阶段、可共享证据、未知角色或动作及历史审核都不能生成例外目标', () => {
|
|
const { state, quality, shot } = conflict()
|
|
const phase = shot.durationPlanning!.phases[0]!
|
|
phase.resourceOccupancy![1]!.ownerRef = '@CH9999'
|
|
expect(actionExceptionTargets(state, quality)).toEqual([])
|
|
phase.resourceOccupancy![1]!.ownerRef = '@CH0001'
|
|
phase.actionIds = ['hold']
|
|
expect(actionExceptionTargets(state, quality)).toEqual([])
|
|
phase.actionIds = ['hold', 'wave']
|
|
phase.resourceOccupancy!.forEach(item => {
|
|
item.shareable = true
|
|
item.usage = 'hold'
|
|
})
|
|
expect(actionExceptionTargets(state, quality)).toEqual([])
|
|
phase.resourceOccupancy!.forEach(item => {
|
|
item.shareable = false
|
|
})
|
|
expect(actionExceptionTargets(state, { ...quality, source: 'history' })).toEqual([])
|
|
const resource = phase.resourceOccupancy!.pop()!
|
|
shot.durationPlanning!.phases.push({ ...phase, resourceOccupancy: [resource] })
|
|
expect(actionExceptionTargets(state, quality)).toEqual([])
|
|
})
|
|
|
|
it('用户仅填写原因,保存前重读并合并已有例外,不改全局规则或自动放行质量', async () => {
|
|
const { state, quality } = conflict()
|
|
const latest = { ...policy, customRules: ['其他入口刚保存的新规则'] }
|
|
vi.spyOn(projectsApi, 'qualityPolicy')
|
|
.mockResolvedValueOnce(policyReceipt('candidate-project', policy))
|
|
.mockResolvedValue(policyReceipt('candidate-project', latest))
|
|
const save = vi
|
|
.spyOn(projectsApi, 'saveQualityPolicy')
|
|
.mockImplementation(async (id, input) => policyReceipt(id, input))
|
|
wrapper = mount(ActionExceptionRepair, {
|
|
props: {
|
|
projectId: 'candidate-project',
|
|
checkpointId: 'candidate-current',
|
|
state,
|
|
quality,
|
|
disabled: false
|
|
}
|
|
})
|
|
await flushPromises()
|
|
expect(wrapper.text()).toContain('左手握住铜铃')
|
|
expect(wrapper.text()).toContain('左手向村民挥动')
|
|
await wrapper
|
|
.findAll('button')
|
|
.find(button => button.text() === '添加例外')!
|
|
.trigger('click')
|
|
expect(wrapper.find('input').exists()).toBe(false)
|
|
expect(wrapper.find('textarea').element.value).toBe('')
|
|
expect(wrapper.text()).not.toContain('请填写允许原因')
|
|
await wrapper
|
|
.findAll('button')
|
|
.find(button => button.text() === '保存动作例外')!
|
|
.trigger('click')
|
|
expect(wrapper.text()).toContain('请填写允许原因')
|
|
expect(save).not.toHaveBeenCalled()
|
|
await wrapper.get('textarea').setValue('剧本明确允许左手同时挥动持物')
|
|
await wrapper
|
|
.findAll('button')
|
|
.find(button => button.text() === '保存动作例外')!
|
|
.trigger('click')
|
|
await flushPromises()
|
|
expect(save).toHaveBeenCalledExactlyOnceWith(
|
|
'candidate-project',
|
|
{
|
|
...latest,
|
|
actionExceptions: [
|
|
policy.actionExceptions![0],
|
|
{
|
|
code: 'action_resource_conflict',
|
|
ownerRef: '@CH0001',
|
|
resource: 'left_hand',
|
|
reason: '剧本明确允许左手同时挥动持物'
|
|
}
|
|
]
|
|
},
|
|
2
|
|
)
|
|
expect(wrapper.emitted('refresh')).toHaveLength(1)
|
|
expect(quality.actionStatus).toBe('blocked')
|
|
expect(wrapper.find('textarea').exists()).toBe(false)
|
|
})
|
|
|
|
it('保存前出现活动任务或切换检查点时,不提交旧问题的例外', async () => {
|
|
const { state, quality } = conflict()
|
|
let finish!: (value: ReturnType<typeof policyReceipt>) => void
|
|
const read = vi
|
|
.spyOn(projectsApi, 'qualityPolicy')
|
|
.mockResolvedValue(policyReceipt('candidate-project', policy))
|
|
const save = vi.spyOn(projectsApi, 'saveQualityPolicy')
|
|
wrapper = mount(ActionExceptionRepair, {
|
|
props: {
|
|
projectId: 'candidate-project',
|
|
checkpointId: 'candidate-current',
|
|
state,
|
|
quality,
|
|
disabled: false
|
|
}
|
|
})
|
|
await flushPromises()
|
|
await wrapper
|
|
.findAll('button')
|
|
.find(button => button.text() === '添加例外')!
|
|
.trigger('click')
|
|
await wrapper.get('textarea').setValue('允许原因')
|
|
read.mockImplementationOnce(
|
|
() =>
|
|
new Promise(resolve => {
|
|
finish = resolve
|
|
})
|
|
)
|
|
await wrapper
|
|
.findAll('button')
|
|
.find(button => button.text() === '保存动作例外')!
|
|
.trigger('click')
|
|
await wrapper.setProps({ disabled: true })
|
|
finish(policyReceipt('candidate-project', policy))
|
|
await flushPromises()
|
|
expect(save).not.toHaveBeenCalled()
|
|
expect(wrapper.find('textarea').element.value).toBe('允许原因')
|
|
await wrapper.setProps({ checkpointId: 'new-checkpoint' })
|
|
expect(wrapper.find('textarea').exists()).toBe(false)
|
|
expect(wrapper.emitted('refresh')).toBeUndefined()
|
|
})
|
|
|
|
it('已有同一角色部位的例外不重复添加,其他例外保持可见', async () => {
|
|
const { state, quality } = conflict()
|
|
const existing = {
|
|
...policy,
|
|
actionExceptions: [
|
|
...policy.actionExceptions!,
|
|
{
|
|
code: 'action_resource_conflict' as const,
|
|
ownerRef: '@CH0001',
|
|
resource: 'left_hand' as const,
|
|
reason: '已确认的同类例外'
|
|
}
|
|
]
|
|
}
|
|
vi.spyOn(projectsApi, 'qualityPolicy').mockResolvedValue(policyReceipt('candidate-project', existing))
|
|
const save = vi.spyOn(projectsApi, 'saveQualityPolicy')
|
|
wrapper = mount(ActionExceptionRepair, {
|
|
props: {
|
|
projectId: 'candidate-project',
|
|
checkpointId: 'candidate-current',
|
|
state,
|
|
quality,
|
|
disabled: false
|
|
}
|
|
})
|
|
await flushPromises()
|
|
expect(wrapper.text()).toContain('已有动作例外 · 2 项')
|
|
expect(
|
|
wrapper
|
|
.findAll('button')
|
|
.find(button => button.text() === '已有例外')!
|
|
.attributes('disabled')
|
|
).toBeDefined()
|
|
expect(wrapper.find('textarea').exists()).toBe(false)
|
|
expect(save).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('保存失败保留原因供修正,不增加本地例外或宣称已通过', async () => {
|
|
const { state, quality } = conflict()
|
|
vi.spyOn(projectsApi, 'qualityPolicy').mockResolvedValue(policyReceipt('candidate-project', policy))
|
|
vi.spyOn(projectsApi, 'saveQualityPolicy').mockRejectedValue(new Error('后端拒绝修改'))
|
|
wrapper = mount(ActionExceptionRepair, {
|
|
props: {
|
|
projectId: 'candidate-project',
|
|
checkpointId: 'candidate-current',
|
|
state,
|
|
quality,
|
|
disabled: false
|
|
}
|
|
})
|
|
await flushPromises()
|
|
await wrapper
|
|
.findAll('button')
|
|
.find(button => button.text() === '添加例外')!
|
|
.trigger('click')
|
|
await wrapper.get('textarea').setValue('仍需保存的依据')
|
|
await wrapper
|
|
.findAll('button')
|
|
.find(button => button.text() === '保存动作例外')!
|
|
.trigger('click')
|
|
await flushPromises()
|
|
expect(wrapper.get('textarea').element.value).toBe('仍需保存的依据')
|
|
expect(wrapper.text()).toContain('系统拒绝修改')
|
|
expect(wrapper.text()).toContain('已有动作例外 · 1 项')
|
|
expect(wrapper.emitted('refresh')).toBeUndefined()
|
|
expect(wrapper.emitted('busy')?.map(event => event[0])).toEqual([true, false])
|
|
})
|
|
|
|
it('读取失败或项目不符时不使用默认规则、不开放添加', async () => {
|
|
const { state, quality } = conflict()
|
|
vi.spyOn(projectsApi, 'qualityPolicy').mockResolvedValue(policyReceipt('other', policy))
|
|
const save = vi.spyOn(projectsApi, 'saveQualityPolicy')
|
|
wrapper = mount(ActionExceptionRepair, {
|
|
props: {
|
|
projectId: 'candidate-project',
|
|
checkpointId: 'candidate-current',
|
|
state,
|
|
quality,
|
|
disabled: false
|
|
}
|
|
})
|
|
await flushPromises()
|
|
expect(wrapper.text()).toContain('规则所属项目不一致')
|
|
expect(
|
|
wrapper
|
|
.findAll('button')
|
|
.find(button => button.text() === '添加例外')!
|
|
.attributes('disabled')
|
|
).toBeDefined()
|
|
expect(wrapper.find('textarea').exists()).toBe(false)
|
|
expect(save).not.toHaveBeenCalled()
|
|
})
|
|
})
|