Files
canina/frontend/admin-panel/src/pages/B2BManager.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
3.0 KiB
TypeScript

import { fireEvent,render,screen,waitFor } from '@testing-library/react';
import { toast } from 'react-hot-toast';
import { beforeEach,describe,expect,it,vi } from 'vitest';
import api from '../services/api';
import B2BManager from './B2BManager';
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() }) }));
describe('B2BManager',()=>{
const inquiry = { id: 'i1', companyName: 'Clinic Alpha', contactName: 'Doctor A', phone: '09120000000', email: 'a@example.test', businessType: 'clinic', message: 'Bulk request', status: 'PENDING' };
beforeEach(() => { vi.resetAllMocks(); vi.mocked(api.get).mockImplementation(async url => ({ data: url === '/b2b/inquiries' ? [inquiry] : { data: [] } })); vi.mocked(api.patch).mockResolvedValue({ data: {} }); });
it('filters inquiries by status without losing the loaded list', async () => { render(<B2BManager />); await screen.findByText('Clinic Alpha'); fireEvent.click(screen.getByRole('button', { name: 'رد شده' })); expect(screen.queryByText('Clinic Alpha')).not.toBeInTheDocument(); fireEvent.click(screen.getByRole('button', { name: 'همه' })); expect(screen.getByText('Clinic Alpha')).toBeInTheDocument(); });
it('reviews an inquiry with trimmed notes and refreshes the list', async () => { render(<B2BManager />); fireEvent.click(await screen.findByRole('button', { name: 'تغییر وضعیت' })); fireEvent.change(document.querySelector('#inquiryForm select')!, { target: { value: 'APPROVED' } }); fireEvent.change(screen.getByRole('textbox'), { target: { value: ' approved after review ' } }); fireEvent.submit(document.querySelector('#inquiryForm')!); await waitFor(() => expect(api.patch).toHaveBeenCalledWith('/b2b/inquiries/i1', { status: 'APPROVED', adminNotes: 'approved after review' })); await waitFor(() => expect(api.get).toHaveBeenCalledTimes(2)); });
it('keeps failed review open and reports failure', async () => { vi.mocked(api.patch).mockRejectedValue(new Error('denied')); render(<B2BManager />); fireEvent.click(await screen.findByRole('button', { name: 'تغییر وضعیت' })); fireEvent.submit(document.querySelector('#inquiryForm')!); await waitFor(() => expect(toast.error).toHaveBeenCalledWith('خطا در بروزرسانی وضعیت درخواست B2B')); expect(document.querySelector('#inquiryForm')).toBeInTheDocument(); });
it('blocks whitespace-only partner identity before posting', async () => { render(<B2BManager />); await screen.findByText('Clinic Alpha'); fireEvent.click(screen.getByTestId('b2b-partners-tab')); fireEvent.click(await screen.findByRole('button', { name: 'افزودن همکار B2B جدید' })); fireEvent.change(screen.getByPlaceholderText('uuid-string-of-user'), { target: { value: ' ' } }); fireEvent.submit(document.querySelector('#partnerForm')!); expect(api.post).not.toHaveBeenCalled(); expect(toast.error).toHaveBeenCalledWith('شناسه کاربر و نام شرکت اجباری هستند'); });
});