CRM/frontend/e2e/reports-layout.spec.ts

48 خطوط
2.7 KiB
TypeScript

import { expect, test } from './fixtures'
test('KPI trend keeps the sales-agent leaderboard readable at wide desktop widths', async ({ page }) => {
await page.setViewportSize({ width: 1624, height: 720 })
await page.route('**/api/**', async (route) => {
const url = new URL(route.request().url())
if (!url.pathname.startsWith('/api/')) return route.continue()
if (url.pathname === '/api/auth/me') return route.fulfill({ json: { data: {
id: 1,
name: 'مدیر گزارش',
email: 'admin@example.test',
roles: ['admin'],
permissions: ['view_admin_dashboard', 'view_reports', 'view_pipelines'],
is_active: true,
} } })
if (url.pathname === '/api/settings/public') return route.fulfill({ json: { data: {} } })
if (url.pathname === '/api/notifications/unread-count') return route.fulfill({ json: { data: 0 } })
if (url.pathname === '/api/agents') return route.fulfill({ json: [] })
if (url.pathname === '/api/campaigns') return route.fulfill({ json: { data: [], current_page: 1, last_page: 1, per_page: 100, total: 0, from: 0, to: 0 } })
if (url.pathname === '/api/reports/kpi') return route.fulfill({ json: {
range: { date_from: '2026-06-22', date_to: '2026-07-23', working_days: 27 },
kpis: [],
trend: Array.from({ length: 31 }, (_, index) => ({ date: `2026-07-${String(index + 1).padStart(2, '0')}`, calls: index % 7 === 0 ? 10 : 0, successful_calls: index % 7 === 0 ? 3 : 0, follow_ups: 0, won: 0 })),
leaderboard: [
{ agent_id: 1, agent_name: 'کارشناس فروش شماره یک', calls: 20, successful_calls: 6, conversion_rate: 30, won_value: 0 },
{ agent_id: 2, agent_name: 'کارشناس فروش شماره دو', calls: 10, successful_calls: 2, conversion_rate: 20, won_value: 0 },
],
updated_at: '2026-07-23T10:00:00Z',
} })
return route.fulfill({ json: { data: [] } })
})
await page.goto('/reports')
const leaderboard = page.getByRole('heading', { name: 'رتبه کارشناسان' }).locator('..')
const trend = page.getByRole('heading', { name: 'روند روزانه تماس' }).locator('..')
await expect(leaderboard).toBeVisible()
await expect(page.getByText('کارشناس فروش شماره یک')).toBeVisible()
const leaderboardBox = await leaderboard.boundingBox()
const trendBox = await trend.boundingBox()
expect(leaderboardBox?.width).toBeGreaterThanOrEqual(280)
expect(trendBox?.width).toBeGreaterThan(leaderboardBox?.width ?? 0)
expect((leaderboardBox?.x ?? -1) + (leaderboardBox?.width ?? 0)).toBeLessThanOrEqual(1624)
await expect(page.getByRole('link', { name: /فرصت‌های فروش/ })).toHaveCount(0)
await expect(page.getByRole('link', { name: 'گزارشات', exact: true })).toBeVisible()
})