104 lines
4.6 KiB
TypeScript
104 lines
4.6 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { MemoryRouter } from 'react-router-dom';
|
|
import type { ClientSmsSignature } from '@/api/adminApi';
|
|
import { EnterpriseSignaturesTable } from './EnterpriseSignaturesTable';
|
|
|
|
const signature = {
|
|
id: 'signature-1',
|
|
tenantId: 'tenant-1',
|
|
applicationId: 'app-1',
|
|
name: '【聆界科技】',
|
|
auditStatus: 'approved',
|
|
createdAt: '2026-09-01T00:00:00.000Z',
|
|
updatedAt: '2026-09-01T01:00:00.000Z',
|
|
pendingReportDetailCount: 4,
|
|
tenant: { id: 'tenant-1', name: '深圳市聆界科技有限公司', status: 'active' },
|
|
application: { id: 'app-1', tenantId: 'tenant-1', name: '营销通知应用', status: 'active' },
|
|
carrierReportSummary: {
|
|
mobile: { status: 'approved', approved: 3, total: 3 },
|
|
unicom: { status: 'reporting', approved: 2, total: 3 },
|
|
telecom: { status: 'abandoned', approved: 0, total: 3 },
|
|
},
|
|
drainageInfo: {
|
|
links: [{ id: 'drainage-1', siteName: 'www.lisglo.com', url: 'www.lisglo.com', auditStatus: 'approved' }],
|
|
},
|
|
drainageCarrierReportSummary: {
|
|
'drainage-1': {
|
|
mobile: { status: 'approved', approved: 3, total: 3 },
|
|
unicom: { status: 'reporting', approved: 1, total: 3 },
|
|
telecom: { status: 'waiting_material', approved: 0, total: 3 },
|
|
},
|
|
},
|
|
} as unknown as ClientSmsSignature;
|
|
|
|
function renderTable(overrides: Partial<Parameters<typeof EnterpriseSignaturesTable>[0]> = {}) {
|
|
const props: Parameters<typeof EnterpriseSignaturesTable>[0] = {
|
|
appliedDrainageKeyword: '',
|
|
currentPage: 1,
|
|
expandedSignatureId: signature.id,
|
|
filteredSignatures: [signature],
|
|
visibleSignatures: [signature],
|
|
total: 1,
|
|
totalPages: 1,
|
|
loadData: vi.fn().mockResolvedValue(undefined),
|
|
onAddDrainage: vi.fn(),
|
|
onEditDrainage: vi.fn(),
|
|
onOpenDrainageReport: vi.fn(),
|
|
onEditSignature: vi.fn(),
|
|
onOpenSignatureReport: vi.fn(),
|
|
setDeleteTarget: vi.fn(),
|
|
setExpandedSignatureId: vi.fn(),
|
|
setPage: vi.fn(),
|
|
setSignatureSort: vi.fn(),
|
|
signatureSort: 'asc',
|
|
...overrides,
|
|
};
|
|
return {
|
|
...render(
|
|
<MemoryRouter>
|
|
<EnterpriseSignaturesTable {...props} />
|
|
</MemoryRouter>,
|
|
),
|
|
props,
|
|
};
|
|
}
|
|
|
|
describe('EnterpriseSignaturesTable dense presentation', () => {
|
|
it('uses compact headers, bracketed signatures, carrier statuses with counts and only the requested row actions', () => {
|
|
renderTable();
|
|
expect(screen.getByText('【聆界科技】')).toBeVisible();
|
|
expect(screen.getAllByText('审核状态')).toHaveLength(2);
|
|
expect(screen.queryByText('签名名称')).not.toBeInTheDocument();
|
|
expect(screen.queryByText('签名审核')).not.toBeInTheDocument();
|
|
expect(screen.queryByText('报备详情')).not.toBeInTheDocument();
|
|
expect(screen.getAllByLabelText('全部通过,已报备通过3个,总通道数3个')).toHaveLength(2);
|
|
expect(screen.getByLabelText('部分通过,已报备通过2个,总通道数3个')).toHaveTextContent('部分通过2/3');
|
|
expect(screen.getByLabelText('放弃报备,已报备通过0个,总通道数3个')).toHaveTextContent('放弃报备0/3');
|
|
expect(screen.getByLabelText('资料待补充,已报备通过0个,总通道数3个')).toHaveTextContent('资料待补充0/3');
|
|
expect(screen.getAllByRole('button', { name: '报备状态' })).toHaveLength(2);
|
|
expect(screen.getAllByRole('button', { name: '编辑' })).toHaveLength(2);
|
|
expect(screen.getAllByRole('button', { name: '删除' })).toHaveLength(2);
|
|
expect(screen.getAllByRole('button', { name: /报备状态|编辑|删除/ })).toHaveLength(6);
|
|
screen.getAllByRole('button', { name: /报备状态|编辑|删除/ }).forEach((button) => {
|
|
expect(button).toHaveClass('ui-button--sm', 'enterprise-signature-action-button');
|
|
});
|
|
expect(screen.getByRole('button', { name: '4 条' })).toBeVisible();
|
|
});
|
|
|
|
it('requests a real descending sort from the signature column control', async () => {
|
|
const setSignatureSort = vi.fn();
|
|
renderTable({ expandedSignatureId: '', setSignatureSort });
|
|
await userEvent.click(screen.getByRole('button', { name: '签名降序' }));
|
|
expect(setSignatureSort).toHaveBeenCalledWith('desc');
|
|
expect(screen.getByRole('button', { name: '签名升序' }).querySelector('.lucide-triangle')).toBeInTheDocument();
|
|
expect(
|
|
screen
|
|
.getByRole('button', { name: '签名降序' })
|
|
.querySelector('.enterprise-signature-table__sort-triangle--down'),
|
|
).toBeInTheDocument();
|
|
expect(document.querySelector('.lucide-arrow-up, .lucide-arrow-down')).not.toBeInTheDocument();
|
|
});
|
|
});
|