Files
canina/frontend/admin-panel/src/pages/Reports.test.tsx
T
devops ddbf1ca026
Deploy Canina / deploy (push) Successful in 4m1s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s
test: comprehensive test suites and quality gates pass across backend, storefront and admin
- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation.
- Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings.
- Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors.
- Fixed unmount lifecycle guards, promise error handling, and component edge cases.
2026-10-13 16:01:00 +00:00

16 lines
2.4 KiB
TypeScript

import { fireEvent,render,screen,waitFor } from '@testing-library/react';
import { beforeEach,describe,expect,it,vi } from 'vitest';
import api from '../services/api';
import Reports from './Reports';
vi.mock('../services/api', () => ({ default: { get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn() } }));
vi.mock('react-hot-toast', () => ({ toast: Object.assign(vi.fn(), { success: vi.fn(), error: vi.fn() }) }));
vi.mock('recharts', () => { const Box=({children}:{children?: import('react').ReactNode})=><div>{children}</div>; return { AreaChart:Box, Area:()=>null, XAxis:()=>null, YAxis:()=>null, CartesianGrid:()=>null, Tooltip:()=>null, ResponsiveContainer:Box, BarChart:Box, Bar:()=>null, PieChart:Box, Pie:Box, Cell:()=>null, Legend:()=>null }; });
describe('Reports',()=>{
const report={overview:{totalRevenue:1000,totalCharity:0,productSalesRevenue:1000,totalCostOfGoods:600,totalTax:0,totalDiscounts:0,netProfit:400,totalOrders:2,b2bRevenue:0,b2cRevenue:1000},salesTimeline:[],bestSellers:[],categoryDistribution:[],topCoupons:[]};
beforeEach(()=>{vi.resetAllMocks();vi.mocked(api.get).mockResolvedValue({data:{success:true,data:report}});});
const load=async()=>{render(<Reports/>);await screen.findByText('گزارشات و تحلیل‌های مالی پیشرفته');};
it('requests a bounded default date range and renders revenue',async()=>{await load();expect(api.get).toHaveBeenCalledWith('/admin/reports',{params:{startDate:expect.any(String)}});expect(screen.getAllByText('1,000').length).toBeGreaterThan(0);});
it('clears date bounds for all history and sends B2B role filter',async()=>{await load();fireEvent.click(screen.getByRole('button',{name:'کل تاریخچه'}));await waitFor(()=>expect(api.get).toHaveBeenLastCalledWith('/admin/reports',{params:{}}));fireEvent.change(screen.getByRole('combobox'),{target:{value:'B2B'}});await waitFor(()=>expect(api.get).toHaveBeenLastCalledWith('/admin/reports',{params:{role:'B2B'}}));});
it('sends custom date bounds rather than the default range',async()=>{await load();fireEvent.click(screen.getByRole('button',{name:'بازه سفارشی'}));const dates=document.querySelectorAll('input[type=date]');fireEvent.change(dates[0],{target:{value:'2026-01-01'}});fireEvent.change(dates[1],{target:{value:'2026-01-31'}});await waitFor(()=>expect(api.get).toHaveBeenLastCalledWith('/admin/reports',{params:{startDate:'2026-01-01',endDate:'2026-01-31'}}));});
});