Skip to content

Commit

Permalink
chore: clean up and add unit tests for user earnings history bar char…
Browse files Browse the repository at this point in the history
…t and list
  • Loading branch information
nickewansmith committed Jan 12, 2025
1 parent ce5a43a commit 6072e09
Show file tree
Hide file tree
Showing 19 changed files with 824 additions and 905 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render } from '@testing-library/react-native';
import StakeEarningsHistoryView from './StakeEarningsHistoryView';
import useStakingEarningsHistory from '../../hooks/useStakingEarningsHistory';
import { MOCK_STAKED_ETH_ASSET } from '../../__mocks__/mockData';
import { fireLayoutEvent } from '../../../../../util/testUtils/react-native-svg-charts';

jest.mock('../../hooks/useStakingEarningsHistory');
jest.mock('@react-navigation/native', () => {
Expand All @@ -15,40 +16,47 @@ jest.mock('@react-navigation/native', () => {
}),
};
});
jest.mock('react-native-svg-charts', () => {
const reactNativeSvgCharts = jest.requireActual('react-native-svg-charts'); // Get the actual Grid component
return {
...reactNativeSvgCharts,
Grid: () => <></>,
};
});

describe('StakeEarningsHistoryView', () => {
beforeEach(() => {
(useStakingEarningsHistory as jest.Mock).mockReturnValue({
earningsHistory: [
{
dateStr: '2023-01-01',
dailyRewards: '1.0',
dailyRewardsUsd: '3000',
sumRewards: '10.0',
},
{
dateStr: '2023-01-02',
dailyRewards: '2.0',
dailyRewardsUsd: '6000',
sumRewards: '20.0',
},
],
isLoading: false,
error: null,
});
});
(useStakingEarningsHistory as jest.Mock).mockReturnValue({
earningsHistory: [
{
dateStr: '2023-01-01',
dailyRewards: '10000000000000',
dailyRewardsUsd: '3000',
sumRewards: '10000000000000',
},
{
dateStr: '2023-01-02',
dailyRewards: '10000000000000',
dailyRewardsUsd: '6000',
sumRewards: '20000000000000',
},
],
isLoading: false,
error: null,
});

it('renders correctly and matches snapshot', () => {
const { toJSON } = render(
<StakeEarningsHistoryView
route={{
key: '1',
name: 'params',
params: { asset: MOCK_STAKED_ETH_ASSET },
}}
/>,
);
const earningsHistoryView = (
<StakeEarningsHistoryView
route={{
key: '1',
name: 'params',
params: { asset: MOCK_STAKED_ETH_ASSET },
}}
/>
);

expect(toJSON()).toMatchSnapshot();
describe('StakeEarningsHistoryView', () => {
it('renders correctly and matches snapshot', () => {
const renderedView = render(earningsHistoryView);
fireLayoutEvent(renderedView.root);
expect(renderedView.toJSON()).toMatchSnapshot();
});
});
Loading

0 comments on commit 6072e09

Please sign in to comment.