mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 10:30:04 +01:00
4f8c4820d2
* adding badges for nfts * fixing default nft styling issue * adding multichain flag, making borderRadius inline * Apply suggestions from code review Co-authored-by: George Marshall <george.marshall@consensys.net> * fixing imports * removing nullcheck for guaranteed fields * moving badgewrapper UI into multichain component * using Box for button, removing inline style, border-radius for NFT default image * adding nft badges to NFT Details page * nits, snap update * fixing/refactoring nftdefaultimage display, adding clickable, removing handleimageclick, refactor NFTItem, required props * editing nft-default-image story, test, and snap * Updating to fix positioning, use Box props to reduce CSS and BEM naming conventions * moving minor styling to Box props, adding comment * display block typo --------- Co-authored-by: George Marshall <george.marshall@consensys.net>
71 lines
2.0 KiB
JavaScript
71 lines
2.0 KiB
JavaScript
import React from 'react';
|
|
import { render, fireEvent } from '@testing-library/react';
|
|
import '@testing-library/jest-dom/extend-expect';
|
|
import { NftItem } from '.';
|
|
|
|
describe('NftItem component', () => {
|
|
const mockOnClick = jest.fn();
|
|
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('renders correctly with an image source', () => {
|
|
const { getByTestId } = render(
|
|
<NftItem
|
|
alt="Test Alt"
|
|
backgroundColor="red"
|
|
name="Test NFT"
|
|
src="test-src"
|
|
networkName="Test Network"
|
|
networkSrc="test-network-src"
|
|
tokenId="1"
|
|
onClick={mockOnClick}
|
|
/>,
|
|
);
|
|
|
|
expect(getByTestId('nft-item')).toBeInTheDocument();
|
|
expect(getByTestId('nft-network-badge')).toBeInTheDocument();
|
|
expect(getByTestId('nft-image')).toBeInTheDocument();
|
|
expect(getByTestId('nft-image')).toHaveAttribute('src', 'test-src');
|
|
});
|
|
|
|
it('renders correctly with default image when no image source is provided', () => {
|
|
const { getByTestId, queryByTestId } = render(
|
|
<NftItem
|
|
alt="Test Alt"
|
|
backgroundColor="red"
|
|
name="Test NFT"
|
|
src=""
|
|
networkName="Test Network"
|
|
networkSrc="test-network-src"
|
|
tokenId="1"
|
|
onClick={mockOnClick}
|
|
/>,
|
|
);
|
|
|
|
expect(getByTestId('nft-item')).toBeInTheDocument();
|
|
expect(getByTestId('nft-network-badge')).toBeInTheDocument();
|
|
expect(queryByTestId('nft-image')).not.toBeInTheDocument();
|
|
expect(getByTestId('nft-default-image')).toBeInTheDocument();
|
|
});
|
|
|
|
it('calls onClick when the NFT image is clicked', () => {
|
|
const { getByTestId } = render(
|
|
<NftItem
|
|
alt="Test Alt"
|
|
backgroundColor="red"
|
|
name="Test NFT"
|
|
src="test-src"
|
|
networkName="Test Network"
|
|
networkSrc="test-network-src"
|
|
tokenId="1"
|
|
onClick={mockOnClick}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(getByTestId('nft-image'));
|
|
expect(mockOnClick).toHaveBeenCalled();
|
|
});
|
|
});
|