Skip to content

Commit

Permalink
chore: address sonarcloud alerts increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nickewansmith committed Jan 22, 2025
1 parent cf89994 commit 81f023a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ 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';

import { getStakingNavbar } from '../../../Navbar';
jest.mock('../../../Navbar');
jest.mock('../../hooks/useStakingEarningsHistory');

const mockNavigation = {
navigate: jest.fn(),
setOptions: jest.fn(),
};

jest.mock('@react-navigation/native', () => {
const actualNav = jest.requireActual('@react-navigation/native');
return {
...actualNav,
useNavigation: () => ({
navigate: jest.fn(),
setOptions: jest.fn(),
}),
useNavigation: () => mockNavigation,
};
});
jest.mock('react-native-svg-charts', () => {
Expand Down Expand Up @@ -59,4 +63,11 @@ describe('StakeEarningsHistoryView', () => {
fireLayoutEvent(renderedView.root);
expect(renderedView.toJSON()).toMatchSnapshot();
});

it('calls navigation setOptions to get staking navigation bar', () => {
const renderedView = render(earningsHistoryView);
fireLayoutEvent(renderedView.root);
expect(mockNavigation.setOptions).toHaveBeenCalled();
expect(getStakingNavbar).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const StakeEarningsHistoryView = ({ route }: StakeEarningsHistoryViewProps) => {
const navigation = useNavigation();
const { styles, theme } = useStyles(styleSheet, {});
const { asset } = route.params;
const ticker = asset.ticker || asset.symbol;
const ticker = asset.ticker ?? asset.symbol;

useEffect(() => {
navigation.setOptions(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render } from '@testing-library/react-native';
import { fireEvent, render } from '@testing-library/react-native';
import StakingEarningsHistory from './StakingEarningsHistory';
import useStakingEarningsHistory from '../../../hooks/useStakingEarningsHistory';
import { MOCK_STAKED_ETH_ASSET } from '../../../__mocks__/mockData';
Expand Down Expand Up @@ -143,4 +143,30 @@ describe('StakingEarningsHistory', () => {
expect(getByText('+ 0.00054 ETH')).toBeTruthy();
expect(queryByText('October')).toBeFalsy();
});

it('calls onTimePeriodChange and updates the selected time period', () => {
const { getByText } = render(
<StakingEarningsHistory asset={MOCK_STAKED_ETH_ASSET} />,
);

const timePeriodButton7D = getByText('7D');
fireEvent.press(timePeriodButton7D);

expect(getByText('December 31')).toBeTruthy();
expect(getByText('3000.00 USD')).toBeTruthy();
expect(getByText('+ 0.00044 ETH')).toBeTruthy();
expect(getByText('January 1')).toBeTruthy();
expect(getByText('6000.00 USD')).toBeTruthy();
expect(getByText('+ 0.00054 ETH')).toBeTruthy();

const timePeriodButtonY = getByText('Y');
fireEvent.press(timePeriodButtonY);

expect(getByText('2022')).toBeTruthy();
expect(getByText('3000.00 USD')).toBeTruthy();
expect(getByText('+ 0.00044 ETH')).toBeTruthy();
expect(getByText('2023')).toBeTruthy();
expect(getByText('6000.00 USD')).toBeTruthy();
expect(getByText('+ 0.00054 ETH')).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const getEntryTimePeriodGroupInfo = (
timePeriodInfo.listGroupLabel = yearLabel;
break;
default:
break;
throw new Error('Unsupported time period');
}
return timePeriodInfo;
};
Expand Down

0 comments on commit 81f023a

Please sign in to comment.