Skip to content

Commit

Permalink
chore: Cleanup, and queryByTestID for test stability
Browse files Browse the repository at this point in the history
  • Loading branch information
gambinish committed Oct 23, 2024
1 parent 784c39f commit 6a4a64e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import BottomSheetDialog from './BottomSheetDialog';
import { BottomSheetDialogRef } from './BottomSheetDialog.types';

jest.mock('react-native-safe-area-context', () => {
// using disting digits for mock rects to make sure they are not mixed up
const inset = { top: 1, right: 2, bottom: 3, left: 4 };
const frame = { width: 5, height: 6, x: 7, y: 8 };
return {
Expand Down Expand Up @@ -94,5 +93,4 @@ describe('BottomSheetDialog', () => {

expect(onCloseMock).toHaveBeenCalled();
});
// Note: Add Gesture tests when react-native-gesture-handler gets updated
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useSelector } from 'react-redux';
import Engine from '../../../../core/Engine';
import { selectTokenSortConfig } from '../../../../selectors/preferencesController';
import { selectCurrentCurrency } from '../../../../selectors/currencyRateController';
import { WalletViewSelectorsIDs } from '../../../../../e2e/selectors/wallet/WalletView.selectors';

jest.mock('react-redux', () => ({
useSelector: jest.fn(),
Expand Down Expand Up @@ -67,17 +68,23 @@ describe('TokenSortBottomSheet', () => {
});

it('renders correctly with the default sort option selected', () => {
const { getByText } = render(<TokenSortBottomSheet />);

expect(getByText('Sort By')).toBeTruthy();
expect(getByText('Declining balance (USD high-low)')).toBeTruthy();
expect(getByText('Alphabetically (A-Z)')).toBeTruthy();
const { getByText, queryByTestId } = render(<TokenSortBottomSheet />);

Check failure on line 71 in app/components/UI/Tokens/TokensBottomSheet/TokenSortBottomSheet.test.tsx

View workflow job for this annotation

GitHub Actions / scripts (lint)

'getByText' is assigned a value but never used

expect(queryByTestId(WalletViewSelectorsIDs.SORT_BY)).toBeTruthy();
expect(
queryByTestId(WalletViewSelectorsIDs.SORT_DECLINING_BALANCE),
).toBeTruthy();
expect(
queryByTestId(WalletViewSelectorsIDs.SORT_ALPHABETICAL),
).toBeTruthy();
});

it('triggers PreferencesController to sort by token fiat amount when first cell is pressed', async () => {
const { getByText } = render(<TokenSortBottomSheet />);
const { queryByTestId } = render(<TokenSortBottomSheet />);

fireEvent.press(getByText('Declining balance (USD high-low)'));
fireEvent.press(
queryByTestId(WalletViewSelectorsIDs.SORT_DECLINING_BALANCE),
);

await waitFor(() => {
expect(
Expand All @@ -91,9 +98,9 @@ describe('TokenSortBottomSheet', () => {
});

it('triggers PreferencesController to sort alphabetically when the second cell is pressed', async () => {
const { getByText } = render(<TokenSortBottomSheet />);
const { queryByTestId } = render(<TokenSortBottomSheet />);

fireEvent.press(getByText('Alphabetically (A-Z)'));
fireEvent.press(queryByTestId(WalletViewSelectorsIDs.SORT_ALPHABETICAL));

await waitFor(() => {
expect(
Expand All @@ -114,8 +121,10 @@ describe('TokenSortBottomSheet', () => {
return null;
});

const { getByText } = render(<TokenSortBottomSheet />);
const { queryByTestId } = render(<TokenSortBottomSheet />);

expect(getByText('Alphabetically (A-Z)')).toBeTruthy();
expect(
queryByTestId(WalletViewSelectorsIDs.SORT_ALPHABETICAL),
).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import currencySymbols from '../../../../util/currency-symbols.json';
import Cell, {
CellVariant,
} from '../../../../component-library/components/Cells/Cell';
import { WalletViewSelectorsIDs } from '../../../../../e2e/selectors/wallet/WalletView.selectors';

const TokenSortBottomSheet = () => {
const { colors } = useTheme();
Expand Down Expand Up @@ -48,10 +49,15 @@ const TokenSortBottomSheet = () => {
return (
<BottomSheet shouldNavigateBack>
<View style={styles.bottomSheetWrapper}>
<Text variant={TextVariant.HeadingMD} style={styles.bottomSheetTitle}>
Sort By
<Text
testID={WalletViewSelectorsIDs.SORT_BY}
variant={TextVariant.HeadingMD}
style={styles.bottomSheetTitle}
>
{strings('wallet.sort_by')}
</Text>
<Cell
testID={WalletViewSelectorsIDs.SORT_DECLINING_BALANCE}
variant={CellVariant.Select}
title={strings('wallet.declining_balance', {
currency:
Expand All @@ -63,6 +69,7 @@ const TokenSortBottomSheet = () => {
onPress={() => onSortControlsActionSheetPress(0)}
/>
<Cell
testID={WalletViewSelectorsIDs.SORT_ALPHABETICAL}
variant={CellVariant.Select}
title={strings('wallet.alphabetically')}
isSelected={tokenSortConfig.key !== 'tokenFiatAmount'}
Expand Down
1 change: 0 additions & 1 deletion app/components/UI/Tokens/TokensBottomSheet/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Routes from '../../../../constants/navigation/Routes';
import { createNavigationDetails } from '../../../../util/navigation/navUtils';
// import { TokenSortBottomSheetParams } from './AccountSelector.types';

export const createTokensBottomSheetNavDetails = createNavigationDetails(
Routes.MODAL.ROOT_MODAL_FLOW,
Expand Down
3 changes: 3 additions & 0 deletions e2e/selectors/wallet/WalletView.selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const WalletViewSelectorsIDs = {
TEST_COLLECTIBLE: 'collectible-Test Dapp NFTs #1-1',
COLLECTIBLE_FALLBACK: 'fallback-nft-with-token-id',
IMPORT_TOKEN_FOOTER_LINK: 'import-token-footer-link',
SORT_DECLINING_BALANCE: 'sort-declining-balance',
SORT_ALPHABETICAL: 'sort-alphabetical',
SORT_BY: 'sort-by',
};

export const WalletViewSelectorsText = {
Expand Down

0 comments on commit 6a4a64e

Please sign in to comment.