Multichain NFT network badges (#19029)
* 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>
2023-06-02 17:01:51 +02:00
|
|
|
import React from 'react';
|
2023-07-17 18:43:26 +02:00
|
|
|
import { fireEvent } from '@testing-library/react';
|
2023-08-01 20:21:51 +02:00
|
|
|
import configureStore from '../../../store/store';
|
Multichain NFT network badges (#19029)
* 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>
2023-06-02 17:01:51 +02:00
|
|
|
import '@testing-library/jest-dom/extend-expect';
|
2023-07-17 18:43:26 +02:00
|
|
|
import mockState from '../../../../test/data/mock-state.json';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
Multichain NFT network badges (#19029)
* 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>
2023-06-02 17:01:51 +02:00
|
|
|
import { NftItem } from '.';
|
|
|
|
|
2023-08-01 20:21:51 +02:00
|
|
|
const store = configureStore({
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const noIpfsStore = configureStore({
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
ipfsGateway: '',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
Multichain NFT network badges (#19029)
* 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>
2023-06-02 17:01:51 +02:00
|
|
|
describe('NftItem component', () => {
|
2023-08-01 20:21:51 +02:00
|
|
|
jest.mock('../../../store/actions.ts', () => ({
|
|
|
|
getTokenStandardAndDetails: jest.fn().mockResolvedValue(),
|
|
|
|
}));
|
2023-07-17 18:43:26 +02:00
|
|
|
describe('render', () => {
|
|
|
|
const props = {
|
|
|
|
alt: 'Test Alt',
|
|
|
|
backgroundColor: 'red',
|
|
|
|
name: 'Test NFT',
|
|
|
|
src: 'test-src',
|
|
|
|
networkName: 'Test Network',
|
|
|
|
networkSrc: 'test-network-src',
|
|
|
|
tokenId: '1',
|
|
|
|
onClick: jest.fn(),
|
2023-08-01 20:21:51 +02:00
|
|
|
nftImageURL: '',
|
2023-07-17 18:43:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
it('renders correctly with an image source', () => {
|
|
|
|
const { getByTestId } = renderWithProvider(<NftItem {...props} />, store);
|
|
|
|
|
|
|
|
expect(getByTestId('nft-item')).toBeInTheDocument();
|
|
|
|
expect(getByTestId('nft-network-badge')).toBeInTheDocument();
|
|
|
|
expect(getByTestId('nft-image')).toBeInTheDocument();
|
|
|
|
expect(getByTestId('nft-image')).toHaveAttribute('src', 'test-src');
|
|
|
|
});
|
|
|
|
|
2023-08-01 20:21:51 +02:00
|
|
|
it('renders correctly with default image when no ipfs is off and no image is provided', () => {
|
2023-07-17 18:43:26 +02:00
|
|
|
const { getByTestId, queryByTestId } = renderWithProvider(
|
2023-08-01 20:21:51 +02:00
|
|
|
<NftItem
|
|
|
|
{...props}
|
|
|
|
nftImageURL="ipfs://QmTSZUNt8AKyDabkyXXXP4oHWDnaVXgNdXoJGEyaYzLbeL"
|
|
|
|
/>,
|
|
|
|
noIpfsStore,
|
2023-07-17 18:43:26 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(queryByTestId('nft-image')).not.toBeInTheDocument();
|
|
|
|
expect(getByTestId('nft-default-image')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls onClick when the NFT image is clicked', () => {
|
|
|
|
const { getByTestId } = renderWithProvider(<NftItem {...props} />, store);
|
|
|
|
|
|
|
|
fireEvent.click(getByTestId('nft-image'));
|
|
|
|
expect(props.onClick).toHaveBeenCalled();
|
|
|
|
});
|
Multichain NFT network badges (#19029)
* 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>
2023-06-02 17:01:51 +02:00
|
|
|
});
|
|
|
|
});
|