import React from 'react' import { render, screen } from '../utilities/test-utils' import Currency from './_currency' test('abbreviate prop returns proper abbreviated amount', () => { render( <> ) expect(screen.getByTestId('test-thousands')).toHaveTextContent('$3.2K') expect(screen.getByTestId('test-millions')).toHaveTextContent('$3.2M') expect(screen.getByTestId('test-billions')).toHaveTextContent('$3.2B') expect(screen.getByTestId('test-trillions')).toHaveTextContent('$3.2T') }) test('decimals matching prop returns decimals as title text', () => { render( ) const currencyKit = screen.getByTestId('test-decimals-matching') expect(currencyKit.querySelector('.pb_currency_value')).toHaveTextContent('320.20') expect(currencyKit.querySelector('.unit')).toHaveTextContent('') }) test('decimals default prop returns decimals as body text', () => { render( ) const currencyKit = screen.getByTestId('test-decimals-default') expect(currencyKit.querySelector('.pb_currency_value')).toHaveTextContent('320') expect(currencyKit.querySelector('.unit')).toHaveTextContent('.20') }) test('commaSeparator prop returns comma separated amount', () => { render( ) expect(screen.getByTestId('comma-test')).toHaveTextContent('1,234,567,890') }) test('commaSeparator prop returns comma separated amount with decimals', () => { render( ) expect(screen.getByTestId('comma-test-decimals')).toHaveTextContent('1,234,567,890.12') }) test('commaSeparator prop returns comma separated amount with decimals="matching"', () => { render( ) expect(screen.getByTestId('comma-test-decimals-matching')).toHaveTextContent('1,234,567,890.12') }) test('handles negative amounts correctly', () => { render( <> ) expect(screen.getByTestId('test-negative-default')).toHaveTextContent('-$320') expect(screen.getByTestId('test-negative-millions')).toHaveTextContent('-$3.2M') expect(screen.getByTestId('test-negative-comma-decimals')).toHaveTextContent('-$123,456.78') expect(screen.getByTestId('test-negative-no-symbol')).toHaveTextContent('-400.50') expect(screen.getByTestId('test-negative-medium-size')).toHaveTextContent('$-500.55') })