优化
This commit is contained in:
@@ -30,9 +30,10 @@ describe('PlatformTenantSelector customer labels', () => {
|
||||
const wrapper = mountSelector({ modelValue: String(customer.id) })
|
||||
await flushPromises()
|
||||
|
||||
expect(listPlatformTenants).toHaveBeenCalledWith({ page: 1, size: 200 })
|
||||
expect(listPlatformTenants).toHaveBeenCalledWith({ page: 1, size: 200, status: 'ACTIVE' })
|
||||
expect(wrapper.text()).toContain('目标客户')
|
||||
expect(document.body.textContent).toContain('柏悦物流(CUS-008) · 启用')
|
||||
expect(document.body.textContent).toContain('柏悦物流 · 启用')
|
||||
expect(document.body.textContent).not.toContain('CUS-008')
|
||||
expect(document.body.textContent).not.toContain(String(customer.id))
|
||||
})
|
||||
|
||||
@@ -44,21 +45,33 @@ describe('PlatformTenantSelector customer labels', () => {
|
||||
expect(wrapper.text()).not.toContain(String(customer.id))
|
||||
})
|
||||
|
||||
it('keeps non-active customers out of the selectable options', async () => {
|
||||
vi.mocked(listPlatformTenants).mockResolvedValue({
|
||||
records: [customer, { ...customer, id: '9', tenantName: '停用客户', status: 'DISABLED' }],
|
||||
page: 1, size: 200, total: 2, pages: 1,
|
||||
})
|
||||
mountSelector({ modelValue: String(customer.id) })
|
||||
await flushPromises()
|
||||
|
||||
expect(document.body.textContent).toContain('柏悦物流 · 启用')
|
||||
expect(document.body.textContent).not.toContain('停用客户')
|
||||
})
|
||||
|
||||
it('safely degrades labels when customer name or code is missing', async () => {
|
||||
vi.mocked(listPlatformTenants).mockResolvedValue({
|
||||
records: [
|
||||
{ ...customer, id: '1', tenantName: '', tenantCode: 'CUS-001', status: 'PENDING' },
|
||||
{ ...customer, id: '2', tenantName: '远航供应链', tenantCode: '', status: 'REJECTED' },
|
||||
{ ...customer, id: '3', tenantName: '', tenantCode: '', status: 'UNKNOWN' },
|
||||
{ ...customer, id: '1', tenantName: '', tenantCode: 'CUS-001', status: 'ACTIVE' },
|
||||
{ ...customer, id: '2', tenantName: '远航供应链', tenantCode: '', status: 'ACTIVE' },
|
||||
{ ...customer, id: '3', tenantName: '', tenantCode: '', status: 'ACTIVE' },
|
||||
],
|
||||
page: 1, size: 200, total: 3, pages: 1,
|
||||
})
|
||||
mountSelector({ modelValue: '1' })
|
||||
await flushPromises()
|
||||
|
||||
expect(document.body.textContent).toContain('CUS-001 · 待审核')
|
||||
expect(document.body.textContent).toContain('远航供应链 · 已驳回')
|
||||
expect(document.body.textContent).toContain('未命名客户 · UNKNOWN')
|
||||
expect(document.body.textContent).toContain('未命名客户 · 启用')
|
||||
expect(document.body.textContent).toContain('远航供应链 · 启用')
|
||||
expect(document.body.textContent).not.toContain('CUS-001')
|
||||
expect(document.body.textContent).not.toMatch(/[((][123] ·/)
|
||||
})
|
||||
|
||||
|
||||
@@ -37,17 +37,15 @@ const statusLabels: Record<string, string> = {
|
||||
function tenantLabel(tenant: PlatformTenantResource) {
|
||||
const status = statusLabels[tenant.status] || tenant.status
|
||||
const name = tenant.tenantName?.trim()
|
||||
const code = tenant.tenantCode?.trim()
|
||||
const identity = name && code ? `${name}(${code})` : name || code || '未命名客户'
|
||||
return status ? `${identity} · ${status}` : identity
|
||||
return status ? `${name || '未命名客户'} · ${status}` : name || '未命名客户'
|
||||
}
|
||||
|
||||
async function loadTenants() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const result = await listPlatformTenants({ page: 1, size: 200 })
|
||||
tenants.value = result.records
|
||||
const result = await listPlatformTenants({ page: 1, size: 200, status: 'ACTIVE' })
|
||||
tenants.value = result.records.filter((tenant) => tenant.status === 'ACTIVE')
|
||||
if (!props.modelValue && result.records.length) {
|
||||
const preferred = result.records.find((tenant) => String(tenant.id) === '10001') || result.records[0]
|
||||
emit('update:modelValue', String(preferred.id))
|
||||
|
||||
Reference in New Issue
Block a user