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.
This commit is contained in:
1 parent
1e73715169
commit
ddbf1ca026
439 files changed
+32911
-6107
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import { fireEvent,render,screen } from '@testing-library/react';
|
||||
import { describe,expect,it,vi } from 'vitest';
|
||||
import Button from './Button';
|
||||
|
||||
describe('Button Component', () => {
|
||||
it('renders children correctly', () => {
|
||||
render(<Button>کلیک کنید</Button>);
|
||||
expect(screen.getByRole('button', { name: 'کلیک کنید' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders with different variants and size styling classes', () => {
|
||||
const { rerender } = render(<Button variant="danger" size="sm">حذف</Button>);
|
||||
let btn = screen.getByRole('button');
|
||||
expect(btn.className).toContain('bg-rose-600');
|
||||
expect(btn.className).toContain('px-3');
|
||||
|
||||
rerender(<Button variant="success" size="lg">تایید</Button>);
|
||||
btn = screen.getByRole('button');
|
||||
expect(btn.className).toContain('bg-emerald-600');
|
||||
expect(btn.className).toContain('px-5');
|
||||
});
|
||||
|
||||
it('handles click events when enabled', () => {
|
||||
const handleClick = vi.fn();
|
||||
render(<Button onClick={handleClick}>کلیک</Button>);
|
||||
|
||||
fireEvent.click(screen.getByRole('button'));
|
||||
expect(handleClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('shows spinner and disables button when isLoading is true', () => {
|
||||
const handleClick = vi.fn();
|
||||
render(<Button isLoading onClick={handleClick}>ارسال</Button>);
|
||||
|
||||
const btn = screen.getByRole('button');
|
||||
expect(btn).toBeDisabled();
|
||||
expect(screen.queryByText('ارسال')).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.click(btn);
|
||||
expect(handleClick).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('renders startIcon, endIcon, badge, and info tooltip correctly', () => {
|
||||
const MockIcon = ({ className }: { className?: string }) => <svg data-testid="mock-icon" className={className} />;
|
||||
|
||||
render(
|
||||
<Button
|
||||
startIcon={MockIcon}
|
||||
endIcon={MockIcon}
|
||||
badge={5}
|
||||
info="اطلاعات کمکی"
|
||||
>
|
||||
آیتم
|
||||
</Button>
|
||||
);
|
||||
|
||||
const icons = screen.getAllByTestId('mock-icon');
|
||||
expect(icons.length).toBe(2);
|
||||
expect(screen.getByText('5')).toBeInTheDocument();
|
||||
expect(screen.getByTitle('اطلاعات کمکی')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { Info } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import Spinner from './Spinner';
|
||||
|
||||
export type ButtonVariant =
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import { fireEvent,render,screen } from '@testing-library/react';
|
||||
import { describe,expect,it,vi } from 'vitest';
|
||||
import ConfirmModal from './ConfirmModal';
|
||||
|
||||
describe('ConfirmModal Component', () => {
|
||||
const defaultProps = {
|
||||
isOpen: true,
|
||||
title: 'حذف آیتم',
|
||||
message: 'آیا از حذف این آیتم اطمینان دارید؟',
|
||||
onConfirm: vi.fn(),
|
||||
onCancel: vi.fn(),
|
||||
};
|
||||
|
||||
it('does not render when isOpen is false', () => {
|
||||
const { container } = render(<ConfirmModal {...defaultProps} isOpen={false} />);
|
||||
expect(container.firstChild).toBeNull();
|
||||
});
|
||||
|
||||
it('renders title, message, and default button texts when isOpen is true', () => {
|
||||
render(<ConfirmModal {...defaultProps} />);
|
||||
|
||||
expect(screen.getByText('حذف آیتم')).toBeInTheDocument();
|
||||
expect(screen.getByText('آیا از حذف این آیتم اطمینان دارید؟')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'تایید' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'لغو' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onConfirm when confirm button is clicked', () => {
|
||||
const onConfirmMock = vi.fn();
|
||||
render(<ConfirmModal {...defaultProps} onConfirm={onConfirmMock} />);
|
||||
|
||||
const confirmButton = screen.getByRole('button', { name: 'تایید' });
|
||||
fireEvent.click(confirmButton);
|
||||
|
||||
expect(onConfirmMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls onCancel when cancel button or close X is clicked', () => {
|
||||
const onCancelMock = vi.fn();
|
||||
render(<ConfirmModal {...defaultProps} onCancel={onCancelMock} />);
|
||||
|
||||
const cancelButton = screen.getByRole('button', { name: 'لغو' });
|
||||
fireEvent.click(cancelButton);
|
||||
expect(onCancelMock).toHaveBeenCalledTimes(1);
|
||||
|
||||
const buttons = screen.getAllByRole('button');
|
||||
const closeIconButton = buttons[0];
|
||||
fireEvent.click(closeIconButton);
|
||||
expect(onCancelMock).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('renders custom confirm and cancel texts', () => {
|
||||
render(
|
||||
<ConfirmModal
|
||||
{...defaultProps}
|
||||
confirmText="بله، حذف کن"
|
||||
cancelText="انصراف"
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByRole('button', { name: 'بله، حذف کن' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'انصراف' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('disables buttons and shows loading text when isLoading is true', () => {
|
||||
const onConfirmMock = vi.fn();
|
||||
const onCancelMock = vi.fn();
|
||||
|
||||
render(
|
||||
<ConfirmModal
|
||||
{...defaultProps}
|
||||
isLoading={true}
|
||||
onConfirm={onConfirmMock}
|
||||
onCancel={onCancelMock}
|
||||
/>
|
||||
);
|
||||
|
||||
const confirmButton = screen.getByRole('button', { name: 'در حال پردازش...' });
|
||||
const cancelButton = screen.getByRole('button', { name: 'لغو' });
|
||||
|
||||
expect(confirmButton).toBeDisabled();
|
||||
expect(cancelButton).toBeDisabled();
|
||||
|
||||
fireEvent.click(confirmButton);
|
||||
fireEvent.click(cancelButton);
|
||||
|
||||
expect(onConfirmMock).not.toHaveBeenCalled();
|
||||
expect(onCancelMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('applies non-destructive styling when isDestructive is false', () => {
|
||||
render(<ConfirmModal {...defaultProps} isDestructive={false} />);
|
||||
|
||||
const confirmButton = screen.getByRole('button', { name: 'تایید' });
|
||||
expect(confirmButton.className).toContain('bg-purple-600');
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { X, AlertTriangle } from 'lucide-react';
|
||||
import { AlertTriangle,X } from 'lucide-react';
|
||||
|
||||
interface ConfirmModalProps {
|
||||
isOpen: boolean;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { HelpCircle } from 'lucide-react';
|
||||
import React from 'react';
|
||||
|
||||
export interface FormFieldProps {
|
||||
label?: string;
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
import React, { useState, useMemo } from 'react';
|
||||
import {
|
||||
X,
|
||||
Search,
|
||||
Check,
|
||||
Smile,
|
||||
Pill,
|
||||
ShieldCheck,
|
||||
HeartPulse,
|
||||
Sparkles,
|
||||
ShoppingBag,
|
||||
User,
|
||||
Building2,
|
||||
PhoneCall,
|
||||
Activity,
|
||||
Heart,
|
||||
Dog,
|
||||
BookOpen,
|
||||
FileText,
|
||||
Video,
|
||||
Award,
|
||||
Star,
|
||||
Truck,
|
||||
HelpCircle,
|
||||
MessageSquare,
|
||||
Globe,
|
||||
Settings,
|
||||
Flame,
|
||||
CheckCircle2,
|
||||
AlertCircle,
|
||||
ThumbsUp,
|
||||
Package,
|
||||
Layers,
|
||||
Compass,
|
||||
MapPin,
|
||||
Mail,
|
||||
Send,
|
||||
Zap,
|
||||
Tag,
|
||||
Gift,
|
||||
Clock,
|
||||
Activity,
|
||||
AlertCircle,
|
||||
Award,
|
||||
BookOpen,
|
||||
Building2,
|
||||
Check,
|
||||
CheckCircle2,
|
||||
Clock,
|
||||
Compass,
|
||||
Dog,
|
||||
FileText,
|
||||
Flame,
|
||||
Gift,
|
||||
Globe,
|
||||
Heart,
|
||||
HeartPulse,
|
||||
HelpCircle,
|
||||
Layers,
|
||||
Mail,
|
||||
MapPin,
|
||||
MessageSquare,
|
||||
Package,
|
||||
PhoneCall,
|
||||
Pill,
|
||||
Search,
|
||||
Send,
|
||||
Settings,
|
||||
ShieldCheck,
|
||||
ShoppingBag,
|
||||
Smile,
|
||||
Sparkles,
|
||||
Star,
|
||||
Tag,
|
||||
ThumbsUp,
|
||||
Truck,
|
||||
User,
|
||||
Video,
|
||||
X,
|
||||
Zap,
|
||||
} from 'lucide-react';
|
||||
import React,{ useMemo,useState } from 'react';
|
||||
|
||||
interface IconPickerModalProps {
|
||||
isOpen: boolean;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { X, ZoomIn, ZoomOut, Download, ExternalLink } from 'lucide-react';
|
||||
import { ExternalLink,X,ZoomIn,ZoomOut } from 'lucide-react';
|
||||
import React,{ useEffect } from 'react';
|
||||
|
||||
export interface ImagePreviewModalProps {
|
||||
isOpen: boolean;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
import React,{ forwardRef } from 'react';
|
||||
|
||||
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
||||
error?: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Eye, EyeOff, Copy, Check } from 'lucide-react';
|
||||
import { Check,Copy,Eye,EyeOff } from 'lucide-react';
|
||||
import React,{ useState } from 'react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
|
||||
interface MaskableFieldProps {
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
import { fireEvent,render,screen,waitFor } from '@testing-library/react';
|
||||
import { beforeEach,describe,expect,it,vi } from 'vitest';
|
||||
import api from '../../services/api';
|
||||
import MediaSelector from './MediaSelector';
|
||||
|
||||
vi.mock('../../services/api', () => ({
|
||||
default: {
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
},
|
||||
BASE_DOMAIN: 'https://test.canina.ir',
|
||||
}));
|
||||
|
||||
describe('MediaSelector Modal Component', () => {
|
||||
const mockMediaData = [
|
||||
{
|
||||
id: 'media-1',
|
||||
url: '/uploads/product-1.jpg',
|
||||
filename: 'product-1.jpg',
|
||||
createdAt: '2025-01-01T10:00:00Z',
|
||||
mimetype: 'image/jpeg',
|
||||
},
|
||||
{
|
||||
id: 'media-2',
|
||||
url: '/uploads/guide-video.mp4',
|
||||
filename: 'guide-video.mp4',
|
||||
createdAt: '2025-01-02T10:00:00Z',
|
||||
mimetype: 'video/mp4',
|
||||
},
|
||||
{
|
||||
id: 'media-3',
|
||||
url: '/uploads/catalog.pdf',
|
||||
filename: 'catalog.pdf',
|
||||
createdAt: '2025-01-03T10:00:00Z',
|
||||
mimetype: 'application/pdf',
|
||||
},
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(api.get).mockResolvedValue({
|
||||
data: { success: true, data: mockMediaData },
|
||||
});
|
||||
});
|
||||
|
||||
it('renders nothing when isOpen is false', () => {
|
||||
const { container } = render(
|
||||
<MediaSelector isOpen={false} onClose={vi.fn()} onSelect={vi.fn()} />
|
||||
);
|
||||
expect(container.firstChild).toBeNull();
|
||||
});
|
||||
|
||||
it('fetches and displays media items when isOpen is true', async () => {
|
||||
render(
|
||||
<MediaSelector isOpen={true} onClose={vi.fn()} onSelect={vi.fn()} />
|
||||
);
|
||||
|
||||
expect(await screen.findByText('گالری و مدیریت رسانه')).toBeInTheDocument();
|
||||
expect(await screen.findByText('product-1.jpg')).toBeInTheDocument();
|
||||
expect(screen.getByText('guide-video.mp4')).toBeInTheDocument();
|
||||
expect(screen.getByText('catalog.pdf')).toBeInTheDocument();
|
||||
expect(api.get).toHaveBeenCalledWith('/admin/media');
|
||||
});
|
||||
|
||||
it('filters media list by file type tabs', async () => {
|
||||
render(
|
||||
<MediaSelector isOpen={true} onClose={vi.fn()} onSelect={vi.fn()} />
|
||||
);
|
||||
|
||||
expect(await screen.findByText('product-1.jpg')).toBeInTheDocument();
|
||||
|
||||
// Click 'ویدئوها' tab
|
||||
const videoTab = screen.getByRole('button', { name: 'ویدئوها' });
|
||||
fireEvent.click(videoTab);
|
||||
|
||||
// Only video should remain visible
|
||||
expect(screen.getByText('guide-video.mp4')).toBeInTheDocument();
|
||||
expect(screen.queryByText('product-1.jpg')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('catalog.pdf')).not.toBeInTheDocument();
|
||||
|
||||
// Click 'اسناد PDF' tab
|
||||
const pdfTab = screen.getByRole('button', { name: 'اسناد PDF' });
|
||||
fireEvent.click(pdfTab);
|
||||
|
||||
expect(screen.getByText('catalog.pdf')).toBeInTheDocument();
|
||||
expect(screen.queryByText('guide-video.mp4')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('selects an item on click and confirms selection with the footer button', async () => {
|
||||
const onSelect = vi.fn();
|
||||
const onClose = vi.fn();
|
||||
|
||||
render(
|
||||
<MediaSelector isOpen={true} onClose={onClose} onSelect={onSelect} />
|
||||
);
|
||||
|
||||
expect(await screen.findByText('product-1.jpg')).toBeInTheDocument();
|
||||
|
||||
const submitBtn = screen.getByRole('button', { name: /انتخاب و ثبت فایل/i });
|
||||
expect(submitBtn).toBeDisabled();
|
||||
|
||||
// Click on the product card
|
||||
const cardText = screen.getByText('product-1.jpg');
|
||||
fireEvent.click(cardText);
|
||||
|
||||
// Now submit button should be enabled
|
||||
expect(submitBtn).not.toBeDisabled();
|
||||
expect(screen.getByText(/۱ فایل انتخاب شد/i)).toBeInTheDocument();
|
||||
|
||||
// Click submit
|
||||
fireEvent.click(submitBtn);
|
||||
|
||||
expect(onSelect).toHaveBeenCalledWith('https://test.canina.ir/uploads/product-1.jpg');
|
||||
expect(onClose).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('immediately confirms and closes on card double-click', async () => {
|
||||
const onSelect = vi.fn();
|
||||
const onClose = vi.fn();
|
||||
|
||||
render(
|
||||
<MediaSelector isOpen={true} onClose={onClose} onSelect={onSelect} />
|
||||
);
|
||||
|
||||
const cardText = await screen.findByText('product-1.jpg');
|
||||
fireEvent.doubleClick(cardText);
|
||||
|
||||
expect(onSelect).toHaveBeenCalledWith('https://test.canina.ir/uploads/product-1.jpg');
|
||||
expect(onClose).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('opens preview modal when eye button is clicked', async () => {
|
||||
render(
|
||||
<MediaSelector isOpen={true} onClose={vi.fn()} onSelect={vi.fn()} />
|
||||
);
|
||||
|
||||
expect(await screen.findByText('product-1.jpg')).toBeInTheDocument();
|
||||
|
||||
const eyeButtons = screen.getAllByTitle('مشاهده');
|
||||
expect(eyeButtons.length).toBeGreaterThan(0);
|
||||
fireEvent.click(eyeButtons[0]);
|
||||
|
||||
// Modal or preview image should be triggered
|
||||
await waitFor(() => {
|
||||
const previewImg = document.querySelector('img[src="https://test.canina.ir/uploads/product-1.jpg"]');
|
||||
expect(previewImg).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('triggers delete confirm modal and executes delete on confirmation', async () => {
|
||||
vi.mocked(api.delete).mockResolvedValueOnce({ data: { success: true } });
|
||||
|
||||
render(
|
||||
<MediaSelector isOpen={true} onClose={vi.fn()} onSelect={vi.fn()} />
|
||||
);
|
||||
|
||||
expect(await screen.findByText('product-1.jpg')).toBeInTheDocument();
|
||||
|
||||
const deleteButtons = screen.getAllByTitle('حذف فایل');
|
||||
fireEvent.click(deleteButtons[0]);
|
||||
|
||||
expect(await screen.findByText('حذف تصویر')).toBeInTheDocument();
|
||||
expect(screen.getByText(/آیا از حذف این تصویر مطمئن هستید؟/i)).toBeInTheDocument();
|
||||
|
||||
// Confirm deletion
|
||||
const confirmBtn = screen.getByRole('button', { name: /تایید/i });
|
||||
fireEvent.click(confirmBtn);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(api.delete).toHaveBeenCalledWith('/admin/media/media-1');
|
||||
expect(screen.queryByText('product-1.jpg')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('calls onClose when clicking close icon or cancel button', async () => {
|
||||
const onClose = vi.fn();
|
||||
render(
|
||||
<MediaSelector isOpen={true} onClose={onClose} onSelect={vi.fn()} />
|
||||
);
|
||||
|
||||
await screen.findByText('گالری و مدیریت رسانه');
|
||||
|
||||
const cancelBtn = screen.getByRole('button', { name: 'انصراف' });
|
||||
fireEvent.click(cancelBtn);
|
||||
expect(onClose).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { X, Upload, Image as ImageIcon, Trash2, CheckCircle2, Clipboard, Eye, Video, FileText, Music, Play } from 'lucide-react';
|
||||
import { CheckCircle2,Clipboard,Eye,FileText,Image as ImageIcon,Music,Play,Trash2,Upload,X } from 'lucide-react';
|
||||
import { useCallback,useEffect,useRef,useState } from 'react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import api, { BASE_DOMAIN } from '../../services/api';
|
||||
import Spinner from './Spinner';
|
||||
import Pagination from './Pagination';
|
||||
import api,{ BASE_DOMAIN } from '../../services/api';
|
||||
import ConfirmModal from './ConfirmModal';
|
||||
import ImagePreviewModal from './ImagePreviewModal';
|
||||
import Pagination from './Pagination';
|
||||
import Spinner from './Spinner';
|
||||
|
||||
interface Media {
|
||||
id: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { X } from 'lucide-react';
|
||||
import React,{ useEffect } from 'react';
|
||||
|
||||
export interface ModalProps {
|
||||
isOpen: boolean;
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import { fireEvent,render,screen } from '@testing-library/react';
|
||||
import { describe,expect,it,vi } from 'vitest';
|
||||
import Pagination from './Pagination';
|
||||
|
||||
describe('Pagination Component', () => {
|
||||
it('renders nothing when totalPages is 1 or less', () => {
|
||||
const { container: c1 } = render(
|
||||
<Pagination currentPage={1} totalPages={1} onPageChange={vi.fn()} />
|
||||
);
|
||||
expect(c1.firstChild).toBeNull();
|
||||
|
||||
const { container: c0 } = render(
|
||||
<Pagination currentPage={1} totalPages={0} onPageChange={vi.fn()} />
|
||||
);
|
||||
expect(c0.firstChild).toBeNull();
|
||||
});
|
||||
|
||||
it('renders navigation buttons and page numbers when totalPages > 1', () => {
|
||||
render(
|
||||
<Pagination currentPage={2} totalPages={5} onPageChange={vi.fn()} />
|
||||
);
|
||||
|
||||
expect(screen.getByTitle('صفحه اول')).toBeInTheDocument();
|
||||
expect(screen.getByTitle('صفحه قبلی')).toBeInTheDocument();
|
||||
expect(screen.getByTitle('صفحه بعدی')).toBeInTheDocument();
|
||||
expect(screen.getByTitle('صفحه آخر')).toBeInTheDocument();
|
||||
|
||||
// Check Persian digit representation of current page 2 ('۲')
|
||||
const page2Button = screen.getByRole('button', { name: (2).toLocaleString('fa-IR') });
|
||||
expect(page2Button).toBeInTheDocument();
|
||||
expect(page2Button.className).toContain('bg-purple-600');
|
||||
});
|
||||
|
||||
it('disables first and previous buttons on the first page', () => {
|
||||
render(
|
||||
<Pagination currentPage={1} totalPages={5} onPageChange={vi.fn()} />
|
||||
);
|
||||
|
||||
const firstBtn = screen.getByTitle('صفحه اول');
|
||||
const prevBtn = screen.getByTitle('صفحه قبلی');
|
||||
const nextBtn = screen.getByTitle('صفحه بعدی');
|
||||
const lastBtn = screen.getByTitle('صفحه آخر');
|
||||
|
||||
expect(firstBtn).toBeDisabled();
|
||||
expect(prevBtn).toBeDisabled();
|
||||
expect(nextBtn).not.toBeDisabled();
|
||||
expect(lastBtn).not.toBeDisabled();
|
||||
});
|
||||
|
||||
it('disables next and last buttons on the last page', () => {
|
||||
render(
|
||||
<Pagination currentPage={5} totalPages={5} onPageChange={vi.fn()} />
|
||||
);
|
||||
|
||||
const firstBtn = screen.getByTitle('صفحه اول');
|
||||
const prevBtn = screen.getByTitle('صفحه قبلی');
|
||||
const nextBtn = screen.getByTitle('صفحه بعدی');
|
||||
const lastBtn = screen.getByTitle('صفحه آخر');
|
||||
|
||||
expect(firstBtn).not.toBeDisabled();
|
||||
expect(prevBtn).not.toBeDisabled();
|
||||
expect(nextBtn).toBeDisabled();
|
||||
expect(lastBtn).toBeDisabled();
|
||||
});
|
||||
|
||||
it('calls onPageChange with correct page numbers when navigation buttons are clicked', () => {
|
||||
const handlePageChange = vi.fn();
|
||||
render(
|
||||
<Pagination currentPage={3} totalPages={10} onPageChange={handlePageChange} />
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByTitle('صفحه اول'));
|
||||
expect(handlePageChange).toHaveBeenCalledWith(1);
|
||||
|
||||
fireEvent.click(screen.getByTitle('صفحه قبلی'));
|
||||
expect(handlePageChange).toHaveBeenCalledWith(2);
|
||||
|
||||
fireEvent.click(screen.getByTitle('صفحه بعدی'));
|
||||
expect(handlePageChange).toHaveBeenCalledWith(4);
|
||||
|
||||
fireEvent.click(screen.getByTitle('صفحه آخر'));
|
||||
expect(handlePageChange).toHaveBeenCalledWith(10);
|
||||
});
|
||||
|
||||
it('navigates directly via jump input form', () => {
|
||||
const handlePageChange = vi.fn();
|
||||
render(
|
||||
<Pagination currentPage={2} totalPages={10} onPageChange={handlePageChange} />
|
||||
);
|
||||
|
||||
const input = screen.getByPlaceholderText('2');
|
||||
const submitBtn = screen.getByRole('button', { name: /برو/ });
|
||||
|
||||
// Valid jump
|
||||
fireEvent.change(input, { target: { value: '7' } });
|
||||
fireEvent.click(submitBtn);
|
||||
expect(handlePageChange).toHaveBeenCalledWith(7);
|
||||
|
||||
// Invalid jump (out of range > totalPages)
|
||||
handlePageChange.mockClear();
|
||||
fireEvent.change(input, { target: { value: '15' } });
|
||||
fireEvent.click(submitBtn);
|
||||
expect(handlePageChange).not.toHaveBeenCalled();
|
||||
|
||||
// Invalid jump (<= 0)
|
||||
handlePageChange.mockClear();
|
||||
fireEvent.change(input, { target: { value: '0' } });
|
||||
fireEvent.click(submitBtn);
|
||||
expect(handlePageChange).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from 'lucide-react';
|
||||
import { ChevronLeft,ChevronRight,ChevronsLeft,ChevronsRight } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
|
||||
interface PaginationProps {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React,{ useEffect,useState } from 'react';
|
||||
|
||||
interface PriceInputProps {
|
||||
value: number | string;
|
||||
@@ -38,7 +38,6 @@ export default function PriceInput({
|
||||
suffix = 'تومان',
|
||||
disabled = false,
|
||||
required = false,
|
||||
min,
|
||||
max,
|
||||
name,
|
||||
id,
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
import React, { useRef, useEffect, useState, useCallback } from 'react';
|
||||
import {
|
||||
Bold,
|
||||
Italic,
|
||||
Underline,
|
||||
Heading1,
|
||||
Heading2,
|
||||
Heading3,
|
||||
Heading4,
|
||||
List,
|
||||
ListOrdered,
|
||||
Link as LinkIcon,
|
||||
AlignRight,
|
||||
AlignCenter,
|
||||
AlignLeft,
|
||||
Palette,
|
||||
PaintBucket,
|
||||
Undo,
|
||||
Redo,
|
||||
Code,
|
||||
RemoveFormatting,
|
||||
Image as ImageIcon,
|
||||
Video,
|
||||
Music,
|
||||
Table as TableIcon,
|
||||
Quote,
|
||||
Minus,
|
||||
Maximize2,
|
||||
Minimize2,
|
||||
AlignCenter,
|
||||
AlignLeft,
|
||||
AlignRight,
|
||||
Bold,
|
||||
Code,
|
||||
Heading1,
|
||||
Heading2,
|
||||
Heading3,
|
||||
Heading4,
|
||||
Image as ImageIcon,
|
||||
Italic,
|
||||
Link as LinkIcon,
|
||||
List,
|
||||
ListOrdered,
|
||||
Maximize2,
|
||||
Minimize2,
|
||||
Minus,
|
||||
Music,
|
||||
PaintBucket,
|
||||
Palette,
|
||||
Quote,
|
||||
Redo,
|
||||
RemoveFormatting,
|
||||
Table as TableIcon,
|
||||
Underline,
|
||||
Undo,
|
||||
Video,
|
||||
} from 'lucide-react';
|
||||
import { useCallback,useEffect,useRef,useState } from 'react';
|
||||
import MediaSelector from './MediaSelector';
|
||||
|
||||
interface RichTextEditorProps {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
import { ChevronDown } from 'lucide-react';
|
||||
import React,{ forwardRef } from 'react';
|
||||
|
||||
export interface SelectOption {
|
||||
value: string | number;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
import React,{ forwardRef } from 'react';
|
||||
|
||||
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
|
||||
error?: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ArrowDown,ArrowUp,ArrowUpDown } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { ArrowUpDown, ArrowUp, ArrowDown } from 'lucide-react';
|
||||
|
||||
export interface ThSortProps {
|
||||
column: string;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import React from 'react';
|
||||
|
||||
export interface ToggleSwitchProps {
|
||||
checked: boolean;
|
||||
|
||||
Reference in new issue
Block a user