Skip to content

Commit

Permalink
refactor: money tests (#7353)
Browse files Browse the repository at this point in the history
  • Loading branch information
niloofar-deriv authored and vinu-deriv committed Jan 17, 2023
1 parent 14490b4 commit 0680ab0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 61 deletions.
49 changes: 49 additions & 0 deletions packages/components/src/components/money/__tests__/money.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import Money from '../money';

describe('Money', () => {
it('should have the "className" when passed in', () => {
render(<Money className='test-class' />);
expect(screen.getByTestId('dt_span')).toHaveClass('test-class');
});

it('should return correct text based on the props when "amount" is > 0 and "has_sign" is "true"', () => {
render(<Money has_sign amount={+10} />);
expect(screen.getByText('+')).toBeInTheDocument();
expect(screen.getByText('10.00')).toBeInTheDocument();
});

it('should return correct text based on the props when "amount" is < 0 and "has_sign" is "true"', () => {
render(<Money has_sign amount={-10} />);
expect(screen.getByText('-')).toBeInTheDocument();
expect(screen.getByText('10.00')).toBeInTheDocument();
});

it('should return correct text based on the props when "amount" is 0 and "has_sign" is "true"', () => {
render(<Money has_sign amount={0} />);
expect(screen.getByText('0.00')).toBeInTheDocument();
});

it('should return correct text based on the props when "amount" is > 0 and "has_sign" is "true" and "should_format" is "false")', () => {
render(<Money has_sign amount={+10} should_format={false} />);
expect(screen.getByText('+')).toBeInTheDocument();
expect(screen.getByText('10')).toBeInTheDocument();
});

it('should return correct text based on the props when "amount" is < 0 and "has_sign" is "true" and "should_format" is "false"', () => {
render(<Money has_sign amount={-10.5} should_format={false} />);
expect(screen.getByText('-')).toBeInTheDocument();
expect(screen.getByText('10.5')).toBeInTheDocument();
});

it('should return correct text based on the props when "amount" is 0 and "has_sign" is "true" and "should_format" is "false"', () => {
render(<Money has_sign should_format={false} amount={0} />);
expect(screen.getByText('0')).toBeInTheDocument();
});

it('should show the currency when "show_currency" passed', () => {
render(<Money amount={0} show_currency />);
expect(screen.getByText('0.00 USD')).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion packages/components/src/components/money/money.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Money = ({
return (
<React.Fragment>
{has_sign && sign}
<span className={className}>
<span data-testid='dt_span' className={className}>
{final_amount} {show_currency && getCurrencyDisplayCode(currency)}
</span>
</React.Fragment>
Expand Down

This file was deleted.

0 comments on commit 0680ab0

Please sign in to comment.