|
| 1 | +import { system } from '@/ui/theme/theme'; |
| 2 | +import { ChakraProvider } from '@chakra-ui/react'; |
| 3 | +import '@testing-library/jest-dom'; |
| 4 | +import { render, screen } from '@testing-library/react'; |
| 5 | +import { ReactNode } from 'react'; |
| 6 | + |
| 7 | +import { useSuspenseStxSupply } from '../../../../../common/queries/useStxSupply'; |
| 8 | +import { StxSupply } from '../index'; |
| 9 | + |
| 10 | +jest.mock('../../../../../common/queries/useStxSupply', () => ({ |
| 11 | + useSuspenseStxSupply: jest.fn(), |
| 12 | +})); |
| 13 | +jest.mock('../../../../../common/context/useGlobalContext', () => ({ |
| 14 | + useGlobalContext: () => ({ activeNetwork: { mode: 'mainnet' } }), |
| 15 | +})); |
| 16 | +jest.mock('../../../../../ui/Tooltip', () => ({ |
| 17 | + Tooltip: ({ content, children }: { content: string; children: ReactNode }) => ( |
| 18 | + <div title={content}>{children}</div> |
| 19 | + ), |
| 20 | +})); |
| 21 | +jest.mock('../../StatSection', () => ({ |
| 22 | + StatSection: (props: Record<string, ReactNode>) => ( |
| 23 | + <div> |
| 24 | + {props.title} |
| 25 | + <span data-testid="main">{props.bodyMainText}</span> |
| 26 | + <span data-testid="secondary">{props.bodySecondaryText}</span> |
| 27 | + <span data-testid="caption">{props.caption}</span> |
| 28 | + </div> |
| 29 | + ), |
| 30 | +})); |
| 31 | +jest.mock('../../../ErrorBoundary', () => ({ |
| 32 | + ExplorerErrorBoundary: ({ children }: { children: ReactNode }) => <>{children}</>, |
| 33 | +})); |
| 34 | + |
| 35 | +const mockSupply = useSuspenseStxSupply as jest.MockedFunction<typeof useSuspenseStxSupply>; |
| 36 | + |
| 37 | +test('renders the v3 µSTX total as both circulating and total supply', () => { |
| 38 | + mockSupply.mockReturnValue({ |
| 39 | + data: { total: '1874370687477029', projected_total_2050: '2318000000000000' }, |
| 40 | + } as ReturnType<typeof useSuspenseStxSupply>); |
| 41 | + |
| 42 | + render( |
| 43 | + <ChakraProvider value={system}> |
| 44 | + <StxSupply /> |
| 45 | + </ChakraProvider> |
| 46 | + ); |
| 47 | + |
| 48 | + expect(screen.getByTestId('main')).toHaveTextContent('1.87B'); |
| 49 | + expect(screen.getByTestId('secondary')).toHaveTextContent('1.87B'); |
| 50 | + expect(screen.getByTestId('caption')).toHaveTextContent('100% of total supply is circulating'); |
| 51 | + expect(screen.getByTitle(/Year 2050 supply is ~2.32B/)).toBeInTheDocument(); |
| 52 | +}); |
0 commit comments