Files
crawler-plugin/admin-frontend-vue/tests/mount/gating-page.mount.test.ts
T
huangzd1997 eb6dd9bf44 feat(gating): 后管新增品牌Gating库管理页
菜单权限键 admin_brand_gating(admin_group_data 组),路由 asin-center/gating;
统计卡+五字段筛选+13 列表格+新增/删除/启停用/批量导入(粘文本 { text }
整段交后端,前端同款 parse_batch 规则只做行数预览);companyScoped=false
(biz_brand_gating 全平台共享表口径)。补 ops-cell 操作列宽登记与操作提示条。
2026-10-23 21:57:05 +08:00

139 lines
4.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 品牌Gating库页面挂载测试:渲染(统计卡 + 行)与两次操作载荷断言(新增、恢复生效)。
* 跑法:`npm run test:mount`(vitest + jsdom,配置见 vitest.config.ts)。
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import GatingPage from '@/pages/gating/GatingPage.vue'
const gatingApi = vi.hoisted(() => ({
fetchGatingPage: vi.fn(),
fetchGatingStats: vi.fn(),
createGating: vi.fn(),
deleteGating: vi.fn(),
updateGatingStatus: vi.fn(),
importGatingText: vi.fn(),
}))
vi.mock('@/pages/gating/gating-api', () => gatingApi)
const listPayload = {
total: 2,
rows: [
{
id: 1,
brand: 'jellycat',
asin: 'B0ABC123',
country: '英国',
gatingType: '品牌gating',
status: 1,
source: 'AUTO',
shopName: '',
remark: '',
createdAt: '2026-01-02 03:04:05',
updatedAt: '2026-01-03 03:04:05',
},
{
id: 2,
brand: 'crocs',
asin: '',
country: '全部',
gatingType: '类目gating',
status: 0,
source: 'MANUAL',
shopName: '店A',
remark: '人为录入',
createdAt: '2026-02-01 00:00:00',
updatedAt: '2026-02-02 00:00:00',
disabledAt: '2026-02-03 00:00:00',
},
],
}
const statsPayload = {
total: 2,
active: 1,
disabled: 1,
brands: 2,
byType: [{ name: '品牌gating', count: 1 }],
byCountry: [{ name: '英国', count: 1 }],
bySource: [{ name: 'MANUAL', count: 1 }],
}
const findButton = (wrapper: VueWrapper, label: string) =>
wrapper.findAll('button').find((button) => button.text().trim() === label)
describe('GatingPage', () => {
beforeEach(() => {
vi.clearAllMocks()
gatingApi.fetchGatingPage.mockResolvedValue(listPayload)
gatingApi.fetchGatingStats.mockResolvedValue(statsPayload)
})
it('渲染统计卡、筛选区与表格行', async () => {
const wrapper = mount(GatingPage)
await flushPromises()
const text = wrapper.text()
expect(text).toContain('Gating总记录')
expect(text).toContain('去重品牌数')
expect(text).toContain('jellycat')
expect(text).toContain('crocs')
expect(text).toContain('生效')
expect(text).toContain('停用')
expect(text).toContain('按Gating类型')
expect(wrapper.findAll('tbody tr').length).toBeGreaterThanOrEqual(2)
expect(gatingApi.fetchGatingPage).toHaveBeenCalledTimes(1)
expect(gatingApi.fetchGatingStats).toHaveBeenCalledTimes(1)
})
it('新增弹窗提交后按驼峰字段发载荷', async () => {
const wrapper = mount(GatingPage)
await flushPromises()
gatingApi.createGating.mockResolvedValue(1)
await findButton(wrapper, '新增')!.trigger('click')
const modal = wrapper.get('.modal')
const inputs = modal.findAll('input[type="text"]')
await inputs[0]!.setValue('jellycat') // 品牌
await inputs[1]!.setValue('B0Z9X') // ASIN
await inputs[2]!.setValue('店A') // 店铺
await inputs[3]!.setValue('测试备注') // 备注
await findButton(modal, '保存')!.trigger('click')
await flushPromises()
expect(gatingApi.createGating).toHaveBeenCalledTimes(1)
expect(gatingApi.createGating).toHaveBeenCalledWith({
brand: 'jellycat',
asin: 'B0Z9X',
country: '全部',
gatingType: '品牌gating',
source: 'MANUAL',
shopName: '店A',
remark: '测试备注',
})
})
it('停用行点恢复 → POST status 载荷 status=1;品牌为空时新增被拦截', async () => {
const wrapper = mount(GatingPage)
await flushPromises()
const crocsRow = wrapper
.findAll('tbody tr')
.find((row) => row.text().includes('crocs'))!
await findButton(crocsRow, '恢复')!.trigger('click')
await flushPromises()
expect(gatingApi.updateGatingStatus).toHaveBeenCalledTimes(1)
expect(gatingApi.updateGatingStatus).toHaveBeenCalledWith(2, 1)
// 品牌必填:空品牌提交不发请求
await findButton(wrapper, '新增')!.trigger('click')
await findButton(wrapper.get('.modal'), '保存')!.trigger('click')
await flushPromises()
expect(gatingApi.createGating).not.toHaveBeenCalled()
})
})