Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
  • Loading branch information
owencraston committed Oct 2, 2024
1 parent 66a02e6 commit f6a015c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
export const KEYRING_ACCOUNT_LIST_ITEM = 'keyring-account-list-item';
export const KEYRING_ACCOUNT_LIST_ITEM_BUTTON = 'keyring-account-list-item-button';
///: END:ONLY_INCLUDE_IF
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import Text, {
TextVariant,
} from '../../../../../component-library/components/Texts/Text';
import { strings } from '../../../../../../locales/i18n';
import { KEYRING_ACCOUNT_LIST_ITEM } from './KeyringAccountListItem.constants';
import { KEYRING_ACCOUNT_LIST_ITEM, KEYRING_ACCOUNT_LIST_ITEM_BUTTON } from './KeyringAccountListItem.constants';
interface KeyringAccountListItemProps {
account: InternalAccount;
snapUrl: string;
}

export default function KeyringAccountListItem({
const KeyringAccountListItem = ({
account,
snapUrl,
}: KeyringAccountListItemProps) {
}: KeyringAccountListItemProps) => {
const { styles } = useStyles(stylesheet, {});

return (
Expand All @@ -50,6 +50,7 @@ export default function KeyringAccountListItem({
</View>
<View style={styles.buttonContainer}>
<ButtonIcon
testID={KEYRING_ACCOUNT_LIST_ITEM_BUTTON}
iconName={IconName.Export}
iconColor={IconColor.Primary}
size={ButtonIconSizes.Lg}
Expand All @@ -60,4 +61,6 @@ export default function KeyringAccountListItem({
</View>
);
}

export default React.memo(KeyringAccountListItem);
///: END:ONLY_INCLUDE_IF
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import KeyringAccountListItem from '../KeyringAccountListItem';
import { Linking } from 'react-native';
import { toChecksumHexAddress } from '@metamask/controller-utils';
import { KEYRING_ACCOUNT_LIST_ITEM, KEYRING_ACCOUNT_LIST_ITEM_BUTTON } from '../KeyringAccountListItem.constants';
import { MOCK_ADDRESS_1, createMockSnapInternalAccount } from '../../../../../../util/test/accountsControllerTestUtils';

jest.mock('react-native/Libraries/Linking/Linking', () => ({
openURL: jest.fn(),
}));

describe('KeyringAccountListItem', () => {

const mockInternalAccount = createMockSnapInternalAccount(
MOCK_ADDRESS_1,
'Snap Account 1',
);

const mockSnapUrl = `https://etherscan.io/address/${MOCK_ADDRESS_1.toLowerCase()}`;

it('renders correctly', () => {
const { getByTestId, getByText } = render(
<KeyringAccountListItem account={mockInternalAccount} snapUrl={mockSnapUrl} />,
);

expect(getByTestId(KEYRING_ACCOUNT_LIST_ITEM)).toBeTruthy();
expect(getByText('Snap Account 1')).toBeTruthy();
expect(getByText(toChecksumHexAddress(MOCK_ADDRESS_1))).toBeTruthy();
});

it('opens snap URL when export button is pressed', () => {
const { getByTestId } = render(
<KeyringAccountListItem account={mockInternalAccount} snapUrl={mockSnapUrl} />,
);

const exportButton = getByTestId(KEYRING_ACCOUNT_LIST_ITEM_BUTTON);
fireEvent.press(exportButton);

expect(Linking.openURL).toHaveBeenCalledWith(mockSnapUrl);
});
});

0 comments on commit f6a015c

Please sign in to comment.