2023-02-07 19:06:37 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { fireEvent } from '@testing-library/react';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
2023-02-16 20:23:29 +01:00
|
|
|
import NftDefaultImage from '.';
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
describe('NFT Default Image', () => {
|
2023-02-07 19:06:37 +01:00
|
|
|
it('should render with no props', () => {
|
2023-02-16 20:23:29 +01:00
|
|
|
const { container } = renderWithProvider(<NftDefaultImage />);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should match snapshot with all provided props', () => {
|
|
|
|
const props = {
|
2023-02-16 20:23:29 +01:00
|
|
|
name: 'NFT Name',
|
2023-02-07 19:06:37 +01:00
|
|
|
tokenId: '123',
|
|
|
|
handleImageClick: jest.fn(),
|
|
|
|
};
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const { container } = renderWithProvider(<NftDefaultImage {...props} />);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should match snapshot with missing image click handler', () => {
|
|
|
|
const props = {
|
2023-02-16 20:23:29 +01:00
|
|
|
name: 'NFT Name',
|
2023-02-07 19:06:37 +01:00
|
|
|
tokenId: '123',
|
|
|
|
};
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const { container } = renderWithProvider(<NftDefaultImage {...props} />);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
it('should render NFT name', () => {
|
2023-02-07 19:06:37 +01:00
|
|
|
const props = {
|
2023-02-16 20:23:29 +01:00
|
|
|
name: 'NFT Name',
|
2023-02-07 19:06:37 +01:00
|
|
|
};
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const { queryByText } = renderWithProvider(<NftDefaultImage {...props} />);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const nftElement = queryByText(`${props.name} #`);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
expect(nftElement).toBeInTheDocument();
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
it('should render NFT name and tokenId', () => {
|
2023-02-07 19:06:37 +01:00
|
|
|
const props = {
|
2023-02-16 20:23:29 +01:00
|
|
|
name: 'NFT Name',
|
2023-02-07 19:06:37 +01:00
|
|
|
tokenId: '123',
|
|
|
|
};
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const { queryByText } = renderWithProvider(<NftDefaultImage {...props} />);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const nftElement = queryByText(`${props.name} #${props.tokenId}`);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
expect(nftElement).toBeInTheDocument();
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle image click', () => {
|
|
|
|
const props = {
|
|
|
|
handleImageClick: jest.fn(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDefaultImage {...props} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const nftImageElement = queryByTestId('nft-default-image');
|
|
|
|
fireEvent.click(nftImageElement);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
expect(props.handleImageClick).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|