-
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.
UX Multichain: Added background color of test networks (#20032)
* added background color to token list item * updated badge color for nft-item * updated nft-item tests
- Loading branch information
Showing
5 changed files
with
74 additions
and
64 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
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,70 +1,49 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import configureStore from 'redux-mock-store'; | ||
import { fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import mockState from '../../../../test/data/mock-state.json'; | ||
import { renderWithProvider } from '../../../../test/lib/render-helpers'; | ||
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(); | ||
const store = configureStore()(mockState); | ||
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(), | ||
}; | ||
|
||
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'); | ||
}); | ||
|
||
it('renders correctly with default image when no image source is provided', () => { | ||
const { getByTestId, queryByTestId } = renderWithProvider( | ||
<NftItem {...props} src="" />, | ||
store, | ||
); | ||
|
||
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(); | ||
}); | ||
}); | ||
}); |
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