fix: preserve required inputs and refine operations screens
This commit is contained in:
@@ -4,7 +4,7 @@ import { resolve } from 'node:path'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { ApiResponseError } from '@/shared/api/http'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { useAuthStore } from '@/core/auth/auth'
|
||||
@@ -367,6 +367,7 @@ describe('InboundFeePanel', () => {
|
||||
|
||||
it('confirms and then sends a calculated fee through the implemented backend transitions', async () => {
|
||||
vi.mocked(getLatestInboundFee).mockResolvedValue({ ...snapshot, feeStatus: 'CALCULATED', confirmedAt: null, sentAt: null })
|
||||
vi.mocked(getInboundMeasurement).mockRejectedValue(new ApiResponseError('无测量查看权限', 'A0403', 403))
|
||||
vi.spyOn(ElMessageBox, 'confirm').mockResolvedValue(undefined as never)
|
||||
const wrapper = mountPanel()
|
||||
await flushPromises()
|
||||
@@ -379,10 +380,47 @@ describe('InboundFeePanel', () => {
|
||||
await wrapper.get('[data-testid="send-fee-button"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(sendInboundFee).toHaveBeenCalledWith('10001', '88', expect.stringMatching(/^fee-send-/))
|
||||
expect(getInboundMeasurement).not.toHaveBeenCalled()
|
||||
expect(wrapper.emitted('changed')).toHaveLength(2)
|
||||
expect(wrapper.find('[data-testid="send-fee-button"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it.each(['confirm', 'push'])('shows the backend review rejection for the %s entry point without sending', async (entry) => {
|
||||
const message = '测量数据尚未审核通过,请先完成测量审核后再确认费用'
|
||||
const showError = vi.spyOn(ElMessage, 'error')
|
||||
vi.spyOn(ElMessageBox, 'confirm').mockResolvedValue(undefined as never)
|
||||
vi.mocked(getLatestInboundFee).mockResolvedValue({ ...snapshot, feeStatus: 'CALCULATED' })
|
||||
vi.mocked(confirmInboundFee).mockRejectedValue(new ApiResponseError(message, 'A0409', 200))
|
||||
const wrapper = mountPanel()
|
||||
await flushPromises()
|
||||
const button = entry === 'confirm'
|
||||
? wrapper.get('[data-testid="confirm-fee-button"]')
|
||||
: wrapper.findAll('button').find(button => button.text().includes('确认推送费用'))!
|
||||
await button.trigger('click')
|
||||
await flushPromises()
|
||||
expect(confirmInboundFee).toHaveBeenCalledTimes(1)
|
||||
expect(sendInboundFee).not.toHaveBeenCalled()
|
||||
expect(getInboundMeasurement).not.toHaveBeenCalled()
|
||||
expect(showError).toHaveBeenCalledWith(expect.objectContaining({ message }))
|
||||
expect(wrapper.find('[data-testid="send-fee-button"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('shows the backend review rejection when sending an already confirmed fee', async () => {
|
||||
const message = '测量数据尚未审核通过,请先完成测量审核后再发送客户'
|
||||
const showError = vi.spyOn(ElMessage, 'error')
|
||||
vi.spyOn(ElMessageBox, 'confirm').mockResolvedValue(undefined as never)
|
||||
vi.mocked(getLatestInboundFee).mockResolvedValue({ ...snapshot, feeStatus: 'CONFIRMED' })
|
||||
vi.mocked(sendInboundFee).mockRejectedValue(new ApiResponseError(message, 'A0409', 200))
|
||||
const wrapper = mountPanel()
|
||||
await flushPromises()
|
||||
await wrapper.get('[data-testid="send-fee-button"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(sendInboundFee).toHaveBeenCalledTimes(1)
|
||||
expect(getInboundMeasurement).not.toHaveBeenCalled()
|
||||
expect(wrapper.emitted('changed')).toBeUndefined()
|
||||
expect(showError).toHaveBeenCalledWith(expect.objectContaining({ message }))
|
||||
})
|
||||
|
||||
it('does not expose fee transitions without their independent permissions', async () => {
|
||||
vi.mocked(getLatestInboundFee).mockResolvedValue({ ...snapshot, feeStatus: 'CALCULATED', confirmedAt: null, sentAt: null })
|
||||
const wrapper = mountPanel(['firstleg:fba-pricing:view', 'firstleg:fba-pricing:adjust'])
|
||||
@@ -392,6 +430,20 @@ describe('InboundFeePanel', () => {
|
||||
expect(wrapper.find('[data-testid="send-fee-button"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('confirms and publishes without requiring measurement-view permission', async () => {
|
||||
vi.spyOn(ElMessageBox, 'confirm').mockResolvedValue(undefined as never)
|
||||
vi.mocked(getLatestInboundFee).mockResolvedValue({ ...snapshot, feeStatus: 'CALCULATED' })
|
||||
vi.mocked(getInboundMeasurement).mockRejectedValue(new ApiResponseError('无测量查看权限', 'A0403', 403))
|
||||
const wrapper = mountPanel(['firstleg:fba-pricing:view', 'firstleg:fba-pricing:confirm', 'firstleg:inbound:send-fee'])
|
||||
await flushPromises()
|
||||
await wrapper.findAll('button').find(button => button.text().includes('确认推送费用'))!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(confirmInboundFee).toHaveBeenCalledWith('10001', '88', expect.stringMatching(/^fee-confirm-/))
|
||||
expect(sendInboundFee).toHaveBeenCalledWith('10001', '88', expect.stringMatching(/^fee-send-/))
|
||||
expect(getInboundMeasurement).not.toHaveBeenCalled()
|
||||
expect(wrapper.emitted('changed')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('submits a reasoned adjustment and emits the refreshed snapshot', async () => {
|
||||
vi.mocked(getLatestInboundFee).mockResolvedValue({ ...snapshot, feeStatus: 'CALCULATED' })
|
||||
const wrapper = mountPanel()
|
||||
|
||||
Reference in New Issue
Block a user