2023-02-07 19:06:37 +01:00
|
|
|
import { fireEvent, waitFor } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import copyToClipboard from 'copy-to-clipboard';
|
|
|
|
import { startNewDraftTransaction } from '../../../ducks/send';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
|
|
|
import mockState from '../../../../test/data/mock-state.json';
|
|
|
|
import { DEFAULT_ROUTE, SEND_ROUTE } from '../../../helpers/constants/routes';
|
|
|
|
import { AssetType } from '../../../../shared/constants/transaction';
|
|
|
|
import {
|
|
|
|
removeAndIgnoreNft,
|
2023-02-16 20:23:29 +01:00
|
|
|
setRemoveNftMessage,
|
2023-02-07 19:06:37 +01:00
|
|
|
} from '../../../store/actions';
|
2023-02-16 20:23:29 +01:00
|
|
|
import NftDetails from './nft-details';
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
jest.mock('copy-to-clipboard');
|
|
|
|
|
|
|
|
const mockHistoryPush = jest.fn();
|
|
|
|
jest.mock('react-router-dom', () => ({
|
|
|
|
...jest.requireActual('react-router-dom'),
|
|
|
|
useLocation: jest.fn(() => ({ search: '' })),
|
|
|
|
useHistory: () => ({
|
|
|
|
push: mockHistoryPush,
|
|
|
|
}),
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('../../../ducks/send/index.js', () => ({
|
|
|
|
...jest.requireActual('../../../ducks/send/index.js'),
|
|
|
|
startNewDraftTransaction: jest
|
|
|
|
.fn()
|
|
|
|
.mockReturnValue(jest.fn().mockResolvedValue()),
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('../../../store/actions.ts', () => ({
|
|
|
|
...jest.requireActual('../../../store/actions.ts'),
|
|
|
|
checkAndUpdateSingleNftOwnershipStatus: jest.fn().mockReturnValue(jest.fn()),
|
|
|
|
removeAndIgnoreNft: jest.fn().mockReturnValue(jest.fn()),
|
2023-02-16 20:23:29 +01:00
|
|
|
setRemoveNftMessage: jest.fn().mockReturnValue(jest.fn()),
|
2023-02-07 19:06:37 +01:00
|
|
|
}));
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
describe('NFT Details', () => {
|
2023-02-07 19:06:37 +01:00
|
|
|
const mockStore = configureMockStore([thunk])(mockState);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const nfts =
|
2023-03-07 15:46:02 +01:00
|
|
|
mockState.metamask.allNfts[mockState.metamask.selectedAddress][5];
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
const props = {
|
2023-02-16 20:23:29 +01:00
|
|
|
nft: nfts[5],
|
2023-02-07 19:06:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should match minimal props and state snapshot', () => {
|
|
|
|
const { container } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDetails {...props} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should route to '/' route when the back button is clicked`, () => {
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDetails {...props} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
|
|
|
const backButton = queryByTestId('asset__back');
|
|
|
|
|
|
|
|
fireEvent.click(backButton);
|
|
|
|
|
|
|
|
expect(mockHistoryPush).toHaveBeenCalledWith(DEFAULT_ROUTE);
|
|
|
|
});
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
it(`should call removeAndIgnoreNFT with proper nft details and route to '/' when removing nft`, () => {
|
2023-02-07 19:06:37 +01:00
|
|
|
const { queryByTestId } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDetails {...props} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOptionMenuButton = queryByTestId('nft-options__button');
|
2023-02-07 19:06:37 +01:00
|
|
|
fireEvent.click(openOptionMenuButton);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const removeNftButton = queryByTestId('nft-item-remove');
|
|
|
|
fireEvent.click(removeNftButton);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
expect(removeAndIgnoreNft).toHaveBeenCalledWith(
|
2023-02-16 20:23:29 +01:00
|
|
|
nfts[5].address,
|
|
|
|
nfts[5].tokenId,
|
2023-02-07 19:06:37 +01:00
|
|
|
);
|
2023-02-16 20:23:29 +01:00
|
|
|
expect(setRemoveNftMessage).toHaveBeenCalledWith('success');
|
2023-02-07 19:06:37 +01:00
|
|
|
expect(mockHistoryPush).toHaveBeenCalledWith(DEFAULT_ROUTE);
|
|
|
|
});
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
it('should copy nft address', async () => {
|
2023-02-07 19:06:37 +01:00
|
|
|
const { queryByTestId } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDetails {...props} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const copyAddressButton = queryByTestId('nft-address-copy');
|
2023-02-07 19:06:37 +01:00
|
|
|
fireEvent.click(copyAddressButton);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
expect(copyToClipboard).toHaveBeenCalledWith(nfts[5].address);
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should navigate to draft transaction send route with ERC721 data', async () => {
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDetails {...props} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const nftSendButton = queryByTestId('nft-send-button');
|
|
|
|
fireEvent.click(nftSendButton);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(startNewDraftTransaction).toHaveBeenCalledWith({
|
|
|
|
type: AssetType.NFT,
|
2023-02-16 20:23:29 +01:00
|
|
|
details: nfts[5],
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(mockHistoryPush).toHaveBeenCalledWith(SEND_ROUTE);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render send button if isCurrentlyOwned is false', () => {
|
2023-02-16 20:23:29 +01:00
|
|
|
const sixthNftProps = {
|
|
|
|
nft: nfts[6],
|
2023-02-07 19:06:37 +01:00
|
|
|
};
|
2023-02-16 20:23:29 +01:00
|
|
|
nfts[6].isCurrentlyOwned = false;
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDetails {...sixthNftProps} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const nftSendButton = queryByTestId('nft-send-button');
|
|
|
|
expect(nftSendButton).not.toBeInTheDocument();
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe(`Alternative Networks' OpenSea Links`, () => {
|
|
|
|
it('should open opeasea link with goeli testnet chainId', async () => {
|
|
|
|
global.platform = { openTab: jest.fn() };
|
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDetails {...props} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOptionMenuButton = queryByTestId('nft-options__button');
|
2023-02-07 19:06:37 +01:00
|
|
|
fireEvent.click(openOptionMenuButton);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOpenSea = queryByTestId('nft-options__view-on-opensea');
|
2023-02-07 19:06:37 +01:00
|
|
|
fireEvent.click(openOpenSea);
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(global.platform.openTab).toHaveBeenCalledWith({
|
2023-02-16 20:23:29 +01:00
|
|
|
url: `https://testnets.opensea.io/assets/${nfts[5].address}/${nfts[5].tokenId}`,
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
it('should open tab to mainnet opensea url with nft info', async () => {
|
2023-02-07 19:06:37 +01:00
|
|
|
global.platform = { openTab: jest.fn() };
|
|
|
|
|
|
|
|
const mainnetState = {
|
|
|
|
...mockState,
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
provider: {
|
|
|
|
chainId: '0x1',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const mainnetMockStore = configureMockStore([thunk])(mainnetState);
|
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDetails {...props} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
mainnetMockStore,
|
|
|
|
);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOptionMenuButton = queryByTestId('nft-options__button');
|
2023-02-07 19:06:37 +01:00
|
|
|
fireEvent.click(openOptionMenuButton);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOpenSea = queryByTestId('nft-options__view-on-opensea');
|
2023-02-07 19:06:37 +01:00
|
|
|
fireEvent.click(openOpenSea);
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(global.platform.openTab).toHaveBeenCalledWith({
|
2023-02-16 20:23:29 +01:00
|
|
|
url: `https://opensea.io/assets/${nfts[5].address}/${nfts[5].tokenId}`,
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
it('should open tab to polygon opensea url with nft info', async () => {
|
2023-02-07 19:06:37 +01:00
|
|
|
const polygonState = {
|
|
|
|
...mockState,
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
provider: {
|
|
|
|
chainId: '0x89',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const polygonMockStore = configureMockStore([thunk])(polygonState);
|
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDetails {...props} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
polygonMockStore,
|
|
|
|
);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOptionMenuButton = queryByTestId('nft-options__button');
|
2023-02-07 19:06:37 +01:00
|
|
|
fireEvent.click(openOptionMenuButton);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOpenSea = queryByTestId('nft-options__view-on-opensea');
|
2023-02-07 19:06:37 +01:00
|
|
|
fireEvent.click(openOpenSea);
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(global.platform.openTab).toHaveBeenCalledWith({
|
2023-02-16 20:23:29 +01:00
|
|
|
url: `https://opensea.io/assets/matic/${nfts[5].address}/${nfts[5].tokenId}`,
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
it('should open tab to sepolia opensea url with nft info', async () => {
|
2023-02-07 19:06:37 +01:00
|
|
|
const sepoliaState = {
|
|
|
|
...mockState,
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
provider: {
|
|
|
|
chainId: '0xaa36a7',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const sepoliaMockStore = configureMockStore([thunk])(sepoliaState);
|
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDetails {...props} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
sepoliaMockStore,
|
|
|
|
);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOptionMenuButton = queryByTestId('nft-options__button');
|
2023-02-07 19:06:37 +01:00
|
|
|
fireEvent.click(openOptionMenuButton);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOpenSea = queryByTestId('nft-options__view-on-opensea');
|
2023-02-07 19:06:37 +01:00
|
|
|
fireEvent.click(openOpenSea);
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(global.platform.openTab).toHaveBeenCalledWith({
|
2023-02-16 20:23:29 +01:00
|
|
|
url: `https://testnets.opensea.io/assets/${nfts[5].address}/${nfts[5].tokenId}`,
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render opensea redirect button', async () => {
|
|
|
|
const randomNetworkState = {
|
|
|
|
...mockState,
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
provider: {
|
|
|
|
chainId: '0x99',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const randomNetworkMockStore = configureMockStore([thunk])(
|
|
|
|
randomNetworkState,
|
|
|
|
);
|
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
2023-02-16 20:23:29 +01:00
|
|
|
<NftDetails {...props} />,
|
2023-02-07 19:06:37 +01:00
|
|
|
randomNetworkMockStore,
|
|
|
|
);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOptionMenuButton = queryByTestId('nft-options__button');
|
2023-02-07 19:06:37 +01:00
|
|
|
fireEvent.click(openOptionMenuButton);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOpenSea = queryByTestId('nft-options__view-on-opensea');
|
2023-02-07 19:06:37 +01:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(openOpenSea).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|