2024-07-31 19:01:45 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { renderWithProviders } from '@/lib/rendering';
|
2024-08-10 19:06:25 +02:00
|
|
|
import { Product, pricePerUnitDisplay } from '@/lib/product';
|
2024-07-31 19:01:45 +02:00
|
|
|
import ProductList from '@/components/ProductList';
|
|
|
|
import initialProducts from '@/__fixtures__/initialProducts';
|
|
|
|
import { screen } from '@testing-library/react-native';
|
|
|
|
|
|
|
|
describe('ProductList', () => {
|
|
|
|
it('renders without crashing', () => {
|
|
|
|
const { getByTestId } = renderWithProviders(<ProductList />, {
|
|
|
|
products: initialProducts,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(screen.getByLabelText('product list')).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders products correctly', () => {
|
2024-08-10 19:06:25 +02:00
|
|
|
const mockProduct = initialProducts[0] as Product;
|
|
|
|
const label = `${mockProduct.attributes?.name} (${pricePerUnitDisplay(mockProduct)})`;
|
2024-07-31 19:01:45 +02:00
|
|
|
|
|
|
|
const { getByText } = renderWithProviders(<ProductList />, {
|
|
|
|
products: [mockProduct],
|
|
|
|
});
|
2024-08-10 19:06:25 +02:00
|
|
|
|
|
|
|
expect(getByText(label)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders only area_rug products', () => {
|
|
|
|
const areaRug = initialProducts.find(p => p.type == "area_rug") as Product;
|
|
|
|
const label = `${areaRug?.attributes?.name} (${pricePerUnitDisplay(areaRug)})`;
|
|
|
|
|
|
|
|
renderWithProviders(<ProductList productType='area_rug' />, {
|
|
|
|
products: initialProducts,
|
|
|
|
});
|
2024-07-31 19:01:45 +02:00
|
|
|
|
2024-08-10 19:06:25 +02:00
|
|
|
expect(screen.getByText(label)).toBeTruthy();
|
2024-07-31 19:01:45 +02:00
|
|
|
});
|
|
|
|
});
|