feat(subscription): display jalali expiry date and handle no expiry case in current plan card
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { screen, fireEvent, within } from '@testing-library/react';
|
||||
import { renderWithProviders } from '../test/utils';
|
||||
import { formatRial } from '../lib/utils';
|
||||
import { formatRial, formatDate } from '../lib/utils';
|
||||
|
||||
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
||||
vi.mock('../lib/api', () => ({
|
||||
@@ -67,6 +67,27 @@ describe('SubscriptionPage', () => {
|
||||
expect(await screen.findByText(/روز تا پایان اشتراک/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the jalali expiry date on the current-plan card', async () => {
|
||||
// 1767225600 = 2026-01-01T00:00:00Z → ۱۴۰۴/۱۰/۱۱ in Tehran
|
||||
mockApi({ my: { ...DEFAULT_MY, subscription: { ...DEFAULT_MY.subscription, expires_at: 1767225600 } } });
|
||||
renderWithProviders(<SubscriptionPage />, { route: '/admin/subscription' });
|
||||
|
||||
expect(await screen.findByText('زمان پایان اشتراک:')).toBeInTheDocument();
|
||||
expect(screen.getByText(formatDate(1767225600))).toBeInTheDocument();
|
||||
expect(screen.getByText(/روز مانده/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('falls back to «بدون تاریخ انقضا» when the subscription has no expiry', async () => {
|
||||
renderWithProviders(<SubscriptionPage />, { route: '/admin/subscription' });
|
||||
expect(await screen.findByText('بدون تاریخ انقضا')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders the current-plan card right-to-left', async () => {
|
||||
renderWithProviders(<SubscriptionPage />, { route: '/admin/subscription' });
|
||||
const label = await screen.findByText('پلن فعلی شما:');
|
||||
expect(label.closest('[dir]')).toHaveAttribute('dir', 'rtl');
|
||||
});
|
||||
|
||||
it('shows the expired message when no days remain', async () => {
|
||||
mockApi({ my: { ...DEFAULT_MY, subscription: { ...DEFAULT_MY.subscription, days_remaining: 0 } } });
|
||||
renderWithProviders(<SubscriptionPage />, { route: '/admin/subscription' });
|
||||
|
||||
Reference in New Issue
Block a user