-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66a02e6
commit f6a015c
Showing
3 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...ponents/Views/Snaps/components/KeyringAccountListItem/KeyringAccountListItem.constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...onents/Views/Snaps/components/KeyringAccountListItem/test/KeyringAccountListItem.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |