-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Showing
3 changed files
with
37 additions
and
36 deletions.
There are no files selected for viewing
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
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: 16 additions & 26 deletions
42
ui/components/app/permission-connect-header/permission-connect-header.test.js
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,47 +1,37 @@ | ||
import React from 'react'; | ||
import { screen } from '@testing-library/react'; | ||
import { screen, within } from '@testing-library/react'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import { renderWithProvider } from '../../../../test/jest'; | ||
import PermissionConnectHeader from './permission-connect-header'; | ||
|
||
const STORE_MOCK = configureMockStore()({ metamask: { pendingApprovals: {} } }); | ||
|
||
describe('Permission Connect Header', () => { | ||
const mockOriginData = { | ||
const targetSubjectMetadata = { | ||
name: 'E2E Test Dapp', | ||
origin: 'https://metamask.github.io', | ||
iconUrl: 'https://metamask.github.io/test-dapp/metamask-fox.svg', | ||
}; | ||
const expectedTitle = 'github.io'; | ||
const expectedAltImageText = 'github.io logo'; | ||
const expectedOrigin = 'https://metamask.github.io'; | ||
const expectedAltImageText = 'E2E Test Dapp logo'; | ||
|
||
it('renders permission connect header', () => { | ||
const { getByAltText } = renderWithProvider( | ||
it('renders permission connect header with correct origin and icon', () => { | ||
renderWithProvider( | ||
<PermissionConnectHeader | ||
origin={mockOriginData.origin} | ||
iconUrl={mockOriginData.iconUrl} | ||
requestId="12345" | ||
subjectMetadata={targetSubjectMetadata} | ||
/>, | ||
STORE_MOCK, | ||
); | ||
|
||
expect(screen.getByText(expectedTitle)).toBeInTheDocument(); | ||
expect(screen.getByText(mockOriginData.origin)).toBeInTheDocument(); | ||
expect(getByAltText(expectedAltImageText)).toBeInTheDocument(); | ||
|
||
const imgTag = getByAltText(expectedAltImageText); | ||
expect(imgTag).toHaveAttribute('src', mockOriginData.iconUrl); | ||
}); | ||
const originElements = screen.getAllByText(expectedOrigin); | ||
expect(originElements).toHaveLength(2); | ||
|
||
it('renders permission connect header with fallback icon', () => { | ||
renderWithProvider( | ||
<PermissionConnectHeader | ||
origin={mockOriginData.origin} | ||
iconUrl={undefined} | ||
/>, | ||
STORE_MOCK, | ||
); | ||
const imgTag = screen.getByAltText(expectedAltImageText); | ||
expect(imgTag).toBeInTheDocument(); | ||
expect(imgTag).toHaveAttribute('src', targetSubjectMetadata.iconUrl); | ||
|
||
expect(screen.getByText(expectedTitle)).toBeInTheDocument(); | ||
expect(screen.getByText(mockOriginData.origin)).toBeInTheDocument(); | ||
expect(screen.getByText(expectedTitle.charAt(0))).toBeInTheDocument(); | ||
const originElement = screen.getByTestId('origin-text'); | ||
expect(originElement).toHaveTextContent(expectedOrigin); | ||
}); | ||
}); |