import { flushPromises, mount } from '@vue/test-utils' import { beforeEach, describe, expect, it, vi } from 'vitest' import DashboardView from './DashboardView.vue' vi.mock('../api/dashboard', () => ({ getTodayNewOrderCount: vi.fn().mockResolvedValue(12), getActiveCustomerCount: vi.fn().mockResolvedValue(8), getDashboardOperationalMetrics: vi.fn().mockResolvedValue({ inTransitContainerCount: 3, inTransitTeu: 4.25, unknownContainerTypeCount: 1, pendingCustomsOrderCount: 7, asOf: '2026-09-11T12:00:00', }), })) describe('DashboardView', () => { beforeEach(() => vi.clearAllMocks()) it('renders only the four live metrics', async () => { const wrapper = mount(DashboardView) await flushPromises() expect(wrapper.text()).toContain('核心指标来自实时业务数据') expect(wrapper.text()).toContain('数据更新时间:2026-09-11 12:00') expect(wrapper.findAll('.dashboard-metric')).toHaveLength(4) expect(wrapper.text()).toContain('12 票') expect(wrapper.text()).toContain('4.25 TEU') expect(wrapper.text()).toContain('8 家') expect(wrapper.text()).toContain('7 票') expect(wrapper.text()).toContain('1 柜箱型未知') expect(wrapper.text()).not.toContain('近 30 天运单量趋势') expect(wrapper.text()).not.toContain('运单状态分布') expect(wrapper.text()).not.toContain('TOP10 航线货量') expect(wrapper.text()).not.toContain('收入构成') expect(wrapper.text()).not.toContain('待办事项') expect(wrapper.text()).not.toContain('静态演示数据') }) })