Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
usamaidrsk committed Nov 7, 2024
1 parent ae366cd commit 8a2d02e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({
return priceData.entry[0].resource.propertyGroup[0]?.priceComponent[0]?.amount;
}, [priceData]);

const formatPrice = (amount: { value: number; currency: string }, locale = 'en'): string => {
const formatedPrice = useMemo((): string => {
if (!amount) return '';
try {
new Intl.NumberFormat(locale, {
Expand All @@ -42,7 +42,7 @@ const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({
maximumFractionDigits: 2,
}).format(amount.value)} ${amount.currency}`;
}
};
}, [locale, amount]);

if (isLoading) {
return <SkeletonText width="100px" role="progressbar" />;
Expand All @@ -55,7 +55,7 @@ const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({
return (
<div className={styles.priceDetailsContainer}>
<span className={styles.priceLabel}>{t('price', 'Price')}:</span>
{formatPrice(amount)}
{formatedPrice}
<Tooltip
align="bottom-left"
className={styles.priceToolTip}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@ import { screen } from '@testing-library/react';
import OrderPriceDetailsComponent from './order-price-details.component';
import { useOrderPrice } from '../hooks/useOrderPrice';
import { renderWithSwr } from 'tools';
import { useTranslation } from 'react-i18next';
import { mockOrderPriceData } from '__mocks__';
import { getLocale } from '@openmrs/esm-framework';

const mockGetLocale = jest.mocked(getLocale);
const mockUseOrderPrice = jest.mocked(useOrderPrice);

jest.mock('../hooks/useOrderPrice', () => ({
useOrderPrice: jest.fn(),
}));
jest.mock('react-i18next', () => ({
useTranslation: jest.fn(),
}));

const mockUseTranslation = useTranslation as jest.Mock;

describe('OrderPriceDetailsComponent', () => {
const mockOrderItemUuid = 'test-uuid';

beforeEach(() => {
jest.resetAllMocks();
mockUseTranslation.mockImplementation(() => ({
t: (key: string, fallback: string) => fallback,
i18n: { language: 'en-US' },
}));
mockGetLocale.mockReturnValue('en-US');
});

it('renders loading skeleton when data is loading', () => {
Expand Down Expand Up @@ -74,10 +67,7 @@ describe('OrderPriceDetailsComponent', () => {
});

// Change to German locale for this test
mockUseTranslation.mockImplementation(() => ({
t: (key: string, fallback: string) => fallback,
i18n: { language: 'de-DE' },
}));
mockGetLocale.mockReturnValue('de-DE');

renderWithSwr(<OrderPriceDetailsComponent orderItemUuid={mockOrderItemUuid} />);

Expand Down

0 comments on commit 8a2d02e

Please sign in to comment.