Skip to content

Commit

Permalink
updated tests and storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
NidhiKJha committed Jan 23, 2025
1 parent da1756c commit 0dc265a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ const PermissionConnectHeader = ({ requestId, subjectMetadata }) => {
display={Display.Flex}
flexDirection={FlexDirection.Column}
style={{ overflow: 'hidden' }}
data-testid="permission-connect-header-origin"
>
<Text ellipsis fontWeight={FontWeight.Medium}>
<Text
ellipsis
data-testid="origin-text"
fontWeight={FontWeight.Medium}
>
{origin}
</Text>
<Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,33 @@ export const DefaultStory = (args) => <PermissionConnectHeader {...args} />;
DefaultStory.storyName = 'Default';

DefaultStory.args = {
title: 'E2E Test Dapp',
origin: 'https://metamask.github.io',
iconUrl: 'https://metamask.github.io/test-dapp/metamask-fox.svg',
subjectMetaData: {
name: 'E2E Test Dapp',
origin: 'https://metamask.github.io',
iconUrl: 'https://metamask.github.io/test-dapp/metamask-fox.svg',
},
};

export const HeaderWithFallbackIcon = (args) => (
<PermissionConnectHeader {...args} />
);

HeaderWithFallbackIcon.args = {
title: 'E2E Test Dapp',
origin: 'https://metamask.github.io',
iconUrl: '',
subjectMetaData: {
name: 'E2E Test Dapp',
origin: 'https://metamask.github.io',
iconUrl: '',
},
};

export const HeaderWithFallbackTitle = (args) => (
<PermissionConnectHeader {...args} />
);

HeaderWithFallbackTitle.args = {
title: 'https://metamask.github.io',
origin: 'https://metamask.github.io',
iconUrl: '',
subjectMetaData: {
name: 'https://metamask.github.io',
origin: 'https://metamask.github.io',
iconUrl: '',
},
};
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';

Check failure on line 2 in ui/components/app/permission-connect-header/permission-connect-header.test.js

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

'within' is defined but never used
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);
});
});

0 comments on commit 0dc265a

Please sign in to comment.