update refunds

This commit is contained in:
2026-04-03 10:17:48 +08:00
parent 240a714f6e
commit 783715bead
2 changed files with 60 additions and 5 deletions
@@ -20,6 +20,12 @@ Object.defineProperty(window, 'matchMedia', {
}), }),
}) })
let mockRouteQuery: Record<string, string> = {}
vi.mock('vue-router', () => ({
useRoute: () => ({ query: mockRouteQuery }),
useRouter: () => ({ push: vi.fn() }),
}))
vi.mock('@/utils/request', () => ({ vi.mock('@/utils/request', () => ({
api: { api: {
get: vi.fn(), get: vi.fn(),
@@ -88,7 +94,7 @@ const mockLookupCompanies = [
{ id: 1, name: 'Company A', label: '公司A' }, { id: 1, name: 'Company A', label: '公司A' },
{ id: 2, name: 'Company B', label: '公司B' }, { id: 2, name: 'Company B', label: '公司B' },
] ]
const mockLookupPlatforms = [{ id: 1, developer_id: 1 }] const mockLookupPlatforms = [{ id: 1, name: 'Tmall', label: '天猫', developer_id: 1 }]
const mockLookupStores = [ const mockLookupStores = [
{ id: 1, company_id: 1, platform_id: 1, name: 'Store 1', label: '店铺1' }, { id: 1, company_id: 1, platform_id: 1, name: 'Store 1', label: '店铺1' },
{ id: 2, company_id: 2, platform_id: 1, name: 'Store 2', label: '店铺2' }, { id: 2, company_id: 2, platform_id: 1, name: 'Store 2', label: '店铺2' },
@@ -245,7 +251,7 @@ describe('useRefundStore', () => {
await store.loadLookups() await store.loadLookups()
expect(store.companyMap.get(1)).toBe('公司A') expect(store.companyMap.get(1)).toBe('公司A')
expect(store.platformMap.get(1)).toBe('平台 #1') expect(store.platformMap.get(1)).toBe('天猫')
expect(store.storeMap.get(1)).toBe('店铺1') expect(store.storeMap.get(1)).toBe('店铺1')
}) })
@@ -272,6 +278,7 @@ describe('RefundsPage', () => {
beforeEach(() => { beforeEach(() => {
setActivePinia(createPinia()) setActivePinia(createPinia())
vi.restoreAllMocks() vi.restoreAllMocks()
mockRouteQuery = {}
document.body.innerHTML = '' document.body.innerHTML = ''
}) })
@@ -513,4 +520,37 @@ describe('RefundsPage', () => {
expect(errorSpy).toHaveBeenCalledWith('获取退款详情失败') expect(errorSpy).toHaveBeenCalledWith('获取退款详情失败')
}) })
// ─── P19.2 URL 参数自动填充测试 ───────────────────────────
it('fills filter and fetches when auto_submit=1 with platform_refund_id', async () => {
mockRouteQuery = { platform_refund_id: 'RF-FROM-URL', auto_submit: '1' }
const { api } = await mountPage()
const store = useRefundStore()
expect(store.filters.platform_refund_id).toBe('RF-FROM-URL')
expect(api.get).toHaveBeenCalledWith(
'/api/v1/refunds',
expect.objectContaining({
platform_refund_id: 'RF-FROM-URL',
page: 1,
}),
)
})
it('does not fill filter when platform_refund_id present but no auto_submit', async () => {
mockRouteQuery = { platform_refund_id: 'RF-FROM-URL' }
await mountPage()
const store = useRefundStore()
expect(store.filters.platform_refund_id).toBe('')
})
it('does not fill filter when only auto_submit is present without platform_refund_id', async () => {
mockRouteQuery = { auto_submit: '1' }
await mountPage()
const store = useRefundStore()
expect(store.filters.platform_refund_id).toBe('')
})
}) })
+17 -2
View File
@@ -12,6 +12,7 @@ import {
} from '@ant-design/icons-vue' } from '@ant-design/icons-vue'
const router = useRouter() const router = useRouter()
const route = useRoute()
const store = useRefundStore() const store = useRefundStore()
// Detail drawer // Detail drawer
@@ -71,8 +72,19 @@ const createdDateRange = computed({
}, },
}) })
onMounted(() => { onMounted(async () => {
const hasAutoSubmit = route.query.auto_submit === '1'
if (hasAutoSubmit) {
await store.loadLookups()
if (route.query.platform_refund_id) {
store.filters.platform_refund_id = route.query.platform_refund_id as string
}
store.pagination.page = 1
} else {
store.loadLookups() store.loadLookups()
}
store.fetchRefunds() store.fetchRefunds()
}) })
@@ -112,7 +124,10 @@ async function handleCopyId(text: string, label: string) {
} }
function handleGoToOrder(platformOrderId: string) { function handleGoToOrder(platformOrderId: string) {
router.push({ path: '/orders', query: { platform_order_id: platformOrderId } }) router.push({
path: '/orders',
query: { platform_order_id: platformOrderId, auto_submit: '1' },
})
} }
async function handleViewDetail(record: { id: number }) { async function handleViewDetail(record: { id: number }) {