This commit is contained in:
2026-08-26 11:10:48 +08:00
parent 53c92d4d37
commit c38e538a95
14 changed files with 301 additions and 235 deletions
@@ -45,6 +45,28 @@ describe('PlatformTenantSelector customer labels', () => {
expect(wrapper.text()).not.toContain(String(customer.id))
})
it('selects the first active customer without preferring a fixed customer id', async () => {
vi.mocked(listPlatformTenants).mockResolvedValue({
records: [
{ ...customer, id: '9', tenantName: '停用客户', status: 'DISABLED' },
{ ...customer, id: '20002', tenantName: '首个客户' },
{ ...customer, id: '10001', tenantName: '后续客户' },
],
page: 1, size: 200, total: 3, pages: 1,
})
const wrapper = mountSelector()
await flushPromises()
expect(wrapper.emitted('update:modelValue')).toEqual([['20002']])
})
it('preserves an explicitly selected customer', async () => {
const wrapper = mountSelector({ modelValue: String(customer.id) })
await flushPromises()
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
})
it('keeps non-active customers out of the selectable options', async () => {
vi.mocked(listPlatformTenants).mockResolvedValue({
records: [customer, { ...customer, id: '9', tenantName: '停用客户', status: 'DISABLED' }],
@@ -47,9 +47,8 @@ async function loadTenants() {
try {
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))
if (!props.modelValue && tenants.value.length) {
emit('update:modelValue', String(tenants.value[0].id))
}
} catch (reason) {
error.value = reason instanceof Error ? reason.message : '客户列表加载失败,请重试'