Files
canina/frontend/admin-panel/src/pages/SeoSettingsPage.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

20 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 SeoSettingsPage from './SeoSettingsPage';
vi.mock('../services/api', () => ({ default: { get: vi.fn(), patch: vi.fn(), put: vi.fn(), post: vi.fn() } }));
vi.mock('react-hot-toast', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
const submit = () => fireEvent.submit(document.querySelector('form')!);
describe('SeoSettingsPage', () => {
beforeEach(() => { vi.resetAllMocks(); vi.mocked(api.get).mockResolvedValue({ data: { data: { brand_name_fa: 'Test Brand', brand_name_en: 'Brand EN', title_separator: '-', title_position: 'prefix', ga_measurement_id: 'G-TEST', enableGoogleAnalytics: false } } }); vi.mocked(api.patch).mockResolvedValue({ data: {} }); });
const load = async () => { render(<SeoSettingsPage />); await screen.findByDisplayValue('Test Brand'); };
it('hydrates legacy keys and updates title preview with position and separator', async () => { await load(); expect(screen.getByText('Test Brand - فروشگاه مکمل‌های تخصصی سگ و گربه')).toBeInTheDocument(); fireEvent.click(screen.getByRole('button', { name: '•' })); expect(screen.getByText('Test Brand • فروشگاه مکمل‌های تخصصی سگ و گربه')).toBeInTheDocument(); fireEvent.change(screen.getByRole('combobox'), { target: { value: 'none' } }); expect(screen.getByText('فروشگاه مکمل‌های تخصصی سگ و گربه')).toBeInTheDocument(); });
it('saves edited title configuration and disabled analytics', async () => { await load(); fireEvent.change(screen.getByDisplayValue('Test Brand'), { target: { value: 'New Brand' } }); submit(); await waitFor(() => expect(api.patch).toHaveBeenCalledWith('/settings/seo', expect.objectContaining({ brandNameFa: 'New Brand', googleAnalyticsId: 'G-TEST', enableGoogleAnalytics: false }))); expect(toast.success).toHaveBeenCalled(); });
it('requires brand before native submit', async () => { await load(); const brand = screen.getByDisplayValue('Test Brand') as HTMLInputElement; fireEvent.change(brand, { target: { value: '' } }); expect(brand.checkValidity()).toBe(false); fireEvent.click(document.querySelector('button[type=submit]')!); expect(api.patch).not.toHaveBeenCalled(); });
it('retains edits and reports rejected save', async () => { await load(); vi.mocked(api.patch).mockRejectedValueOnce(new Error('offline')); submit(); await waitFor(() => expect(toast.error).toHaveBeenCalledWith('خطا در بروزرسانی تنظیمات سئو')); expect(screen.getByDisplayValue('Test Brand')).toBeInTheDocument(); expect(toast.success).not.toHaveBeenCalled(); submit(); await waitFor(() => expect(toast.success).toHaveBeenCalled()); });
it('uses default editable SEO after fetch rejection', async () => { vi.mocked(api.get).mockRejectedValueOnce(new Error('offline')); render(<SeoSettingsPage />); await screen.findByDisplayValue('کنینا ایران'); expect(api.patch).not.toHaveBeenCalled(); });
});