fix(cart): hide prices, discount coupon, and totals in cart when prices are disabled in catalog mode
Deploy Canina / deploy (push) Successful in 2m21s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 6s

This commit is contained in:
parsa aghaei committed 2026-09-13 08:57:44 +03:30
1 parent ef0731ffac
commit e7ded849f6
13 files changed
+11243 -10585

No files matched your search

@@ -16,6 +16,18 @@ vi.mock('../../lib/services/productService', () => ({
},
}));
vi.mock('../../lib/useCatalogMode', () => ({
useCatalogMode: vi.fn(() => ({
isCatalogOnly: false,
showPrices: true,
allowCart: true,
allowCheckout: true,
showPreorderBtn: false,
})),
}));
import { useCatalogMode } from '../../lib/useCatalogMode';
const mockProduct = {
id: 'canhydrox-gag',
name: 'Canhydrox GAG',
@@ -29,6 +41,18 @@ describe('CartDrawer', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(productService.getProducts).mockResolvedValue({ data: [], total: 0 });
vi.mocked(useCatalogMode).mockReturnValue({
isCatalogOnly: false,
showPrices: true,
allowCart: true,
allowCheckout: true,
showPreorderBtn: false,
showOrders: true,
showWallet: true,
showCharity: true,
orderDisabledTitle: '',
orderDisabledMessage: '',
});
});
it('renders empty cart state when no items in cart', () => {
@@ -99,4 +123,41 @@ describe('CartDrawer', () => {
fireEvent.click(minusBtn);
expect(mockUpdateQuantity).toHaveBeenCalledWith('canhydrox-gag', 1);
});
it('hides prices, total and coupon code when showPrices is false in catalog mode', () => {
vi.mocked(useCatalogMode).mockReturnValue({
isCatalogOnly: true,
showPrices: false,
allowCart: true,
allowCheckout: true,
showPreorderBtn: false,
showOrders: false,
showWallet: false,
showCharity: false,
orderDisabledTitle: '',
orderDisabledMessage: '',
});
vi.mocked(useCartStore).mockReturnValue({
items: [{ product: mockProduct, quantity: 2 }],
updateQuantity: vi.fn(),
removeItem: vi.fn(),
isSubscribed: false,
toggleSubscription: vi.fn(),
getTotal: () => 2000,
getSubtotal: () => 2000,
getDiscount: () => 0,
coupon: null,
applyCoupon: vi.fn(),
addItem: vi.fn(),
} as unknown as ReturnType<typeof useCartStore>);
render(<CartDrawer isOpen={true} onClose={vi.fn()} onCheckout={vi.fn()} />);
expect(screen.getByText('Canhydrox GAG')).toBeInTheDocument();
expect(screen.queryByText('کد تخفیف اختصاصی')).not.toBeInTheDocument();
expect(screen.queryByText('مجموع قابل پرداخت')).not.toBeInTheDocument();
expect(screen.getByText('تعداد کل اقلام انتخابی')).toBeInTheDocument();
expect(screen.getByText('۲ قلم کالا')).toBeInTheDocument();
});
});