优化
This commit is contained in:
@@ -3,13 +3,13 @@ import { createPinia, setActivePinia } from 'pinia'
|
||||
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
getPlatformPartner,
|
||||
listPlatformPartners,
|
||||
type PlatformPartnerResource,
|
||||
} from '@/modules/master-data/counterparties/api/platformPartners'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { useAuthStore } from '@/core/auth/auth'
|
||||
import QueryToolbar from '@/shared/components/QueryToolbar.vue'
|
||||
import { listPlatformTenants, type PlatformTenantResource } from '../../../iam/api/platformIam'
|
||||
import PartnersView from './PartnersView.vue'
|
||||
|
||||
vi.mock('@/modules/master-data/counterparties/api/platformPartners', () => ({
|
||||
@@ -22,8 +22,6 @@ vi.mock('@/modules/master-data/counterparties/api/platformPartners', () => ({
|
||||
changePlatformPartnerStatus: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('../../../iam/api/platformIam', () => ({ listPlatformTenants: vi.fn() }))
|
||||
|
||||
class ResizeObserverStub implements ResizeObserver {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
@@ -44,8 +42,8 @@ function createMemoryStorage(): Storage {
|
||||
|
||||
const partner: PlatformPartnerResource = {
|
||||
id: '19001',
|
||||
tenantId: 10001,
|
||||
dataScopeId: 10001,
|
||||
tenantId: 0,
|
||||
dataScopeId: 0,
|
||||
partnerCode: 'CUS-001',
|
||||
partnerName: '深圳示例贸易有限公司',
|
||||
partnerType: 'CUSTOMER',
|
||||
@@ -64,16 +62,6 @@ const partner: PlatformPartnerResource = {
|
||||
updatedAt: '2026-07-30T22:45:00',
|
||||
}
|
||||
|
||||
const tenant = (id: number | string, tenantName: string): PlatformTenantResource => ({
|
||||
id, tenantCode: String(id), tenantName, status: 'ACTIVE', legalName: tenantName,
|
||||
legalRepresentative: null, unifiedSocialCreditCode: null, contactName: null,
|
||||
contactPhone: null, contactEmail: null, servicePackage: null, contactWechat: null,
|
||||
salesOwnerName: null, paymentTermDays: null, enterpriseType: null, establishedDate: null,
|
||||
registeredCapital: null, registeredCapitalCurrency: null, registeredAddress: null,
|
||||
internalRemark: null, createdAt: null, approvedAt: null,
|
||||
})
|
||||
const snowflakeTenantId = '9223372036854775806'
|
||||
|
||||
async function mountView() {
|
||||
vi.stubGlobal('localStorage', createMemoryStorage())
|
||||
vi.stubGlobal('sessionStorage', createMemoryStorage())
|
||||
@@ -103,22 +91,20 @@ describe('PartnersView real API integration', () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
document.body.innerHTML = ''
|
||||
vi.mocked(listPlatformTenants).mockReset().mockResolvedValue({
|
||||
records: [tenant(10001, '默认企业'), tenant(snowflakeTenantId, '雪花企业')], page: 1, size: 200, total: 2, pages: 1,
|
||||
})
|
||||
vi.mocked(listPlatformPartners).mockReset().mockResolvedValue({
|
||||
records: [partner], page: 1, size: 20, total: 1, pages: 1,
|
||||
})
|
||||
vi.mocked(getPlatformPartner).mockReset().mockResolvedValue(partner)
|
||||
})
|
||||
|
||||
it('loads all enterprises by default and renders the real partner fields', async () => {
|
||||
it('loads platform partner data and renders the real partner fields', async () => {
|
||||
const wrapper = await mountView()
|
||||
|
||||
expect(listPlatformPartners).toHaveBeenCalledWith(undefined, {
|
||||
expect(listPlatformPartners).toHaveBeenCalledWith({
|
||||
page: 1, size: 20, keyword: undefined, type: undefined, status: undefined,
|
||||
})
|
||||
expect(wrapper.find('input[aria-label="所属企业"]').exists()).toBe(true)
|
||||
expect(wrapper.text()).toContain('全部企业 · 共 1 个往来单位')
|
||||
expect(wrapper.find('input[aria-label="所属企业"]').exists()).toBe(false)
|
||||
expect(wrapper.text()).toContain('平台公共数据 · 共 1 个往来单位')
|
||||
expect(wrapper.text()).toContain('深圳示例贸易有限公司')
|
||||
expect(wrapper.text()).toContain('CUS-001')
|
||||
expect(wrapper.text()).toContain('contact@example.com')
|
||||
@@ -130,18 +116,30 @@ describe('PartnersView real API integration', () => {
|
||||
expect(wrapper.find('.table-panel').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('preserves a snowflake tenant id as a string when switching enterprises', async () => {
|
||||
it('opens the create form without selecting an enterprise', async () => {
|
||||
const wrapper = await mountView()
|
||||
|
||||
const toolbar = wrapper.findComponent(QueryToolbar)
|
||||
const model = { tenantId: snowflakeTenantId, keyword: '', type: '', status: '' }
|
||||
toolbar.vm.$emit('update:modelValue', model)
|
||||
toolbar.vm.$emit('search', model)
|
||||
const createButton = wrapper.findAll('button').find((button) => button.text().trim() === '新增往来单位')
|
||||
await createButton?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(listPlatformPartners).toHaveBeenLastCalledWith(snowflakeTenantId, {
|
||||
page: 1, size: 20, keyword: undefined, type: undefined, status: undefined,
|
||||
})
|
||||
expect(document.body.textContent).toContain('新增往来单位')
|
||||
expect(document.body.textContent).not.toContain('请先在筛选条件中选择所属企业')
|
||||
})
|
||||
|
||||
it('renders a padded detail layout without an empty data-scope cell', async () => {
|
||||
const wrapper = await mountView()
|
||||
const detailButton = wrapper.findAll('button').find((button) => button.text().trim() === '详情')
|
||||
await detailButton?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
const detailContent = document.querySelector<HTMLElement>('.detail-drawer .partner-detail')
|
||||
const sections = detailContent?.querySelectorAll('section')
|
||||
const otherInfo = sections?.item(sections.length - 1)
|
||||
expect(detailContent).not.toBeNull()
|
||||
expect(otherInfo?.querySelectorAll('.detail-grid > .detail-span')).toHaveLength(2)
|
||||
expect(otherInfo?.textContent).toContain('更新时间')
|
||||
expect(otherInfo?.textContent).toContain('长期合作单位')
|
||||
expect(document.body.textContent).not.toContain('数据范围')
|
||||
})
|
||||
|
||||
it('updates filters locally and only requests after search', async () => {
|
||||
@@ -158,7 +156,7 @@ describe('PartnersView real API integration', () => {
|
||||
await flushPromises()
|
||||
|
||||
expect(listPlatformPartners).toHaveBeenCalledTimes(2)
|
||||
expect(listPlatformPartners).toHaveBeenLastCalledWith(undefined, {
|
||||
expect(listPlatformPartners).toHaveBeenLastCalledWith({
|
||||
page: 1, size: 20, keyword: '深圳', type: undefined, status: undefined,
|
||||
})
|
||||
})
|
||||
@@ -166,7 +164,7 @@ describe('PartnersView real API integration', () => {
|
||||
it('shows useful placeholders and visible required markers in the create form', async () => {
|
||||
const wrapper = await mountView()
|
||||
const toolbar = wrapper.findComponent(QueryToolbar)
|
||||
const model = { tenantId: '10001', keyword: '', type: '', status: '' }
|
||||
const model = { keyword: '', type: '', status: '' }
|
||||
toolbar.vm.$emit('update:modelValue', model)
|
||||
toolbar.vm.$emit('search', model)
|
||||
await flushPromises()
|
||||
|
||||
Reference in New Issue
Block a user