2026-09-11 17:20:58 +08:00
|
|
|
import { flushPromises, mount } from '@vue/test-utils'
|
|
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
2026-08-05 15:54:59 +08:00
|
|
|
import DashboardView from './DashboardView.vue'
|
|
|
|
|
|
2026-09-11 17:20:58 +08:00
|
|
|
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',
|
|
|
|
|
}),
|
|
|
|
|
}))
|
2026-08-05 15:54:59 +08:00
|
|
|
|
2026-09-11 17:20:58 +08:00
|
|
|
describe('DashboardView', () => {
|
|
|
|
|
beforeEach(() => vi.clearAllMocks())
|
|
|
|
|
|
2026-09-14 13:48:15 +08:00
|
|
|
it('renders only the four live metrics', async () => {
|
2026-09-11 17:20:58 +08:00
|
|
|
const wrapper = mount(DashboardView)
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
2026-09-14 13:48:15 +08:00
|
|
|
expect(wrapper.text()).toContain('核心指标来自实时业务数据')
|
2026-09-11 17:20:58 +08:00
|
|
|
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 柜箱型未知')
|
2026-09-14 13:48:15 +08:00
|
|
|
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('静态演示数据')
|
2026-08-05 15:54:59 +08:00
|
|
|
})
|
|
|
|
|
})
|