2021-10-28 21:16:03 +02:00
import React from 'react' ;
import configureMockStore from 'redux-mock-store' ;
import { fireEvent } from '@testing-library/react' ;
import { renderWithProvider } from '../../../../test/jest/rendering' ;
2023-01-18 15:47:29 +01:00
import { TokenStandard } from '../../../../shared/constants/transaction' ;
2021-10-28 21:16:03 +02:00
import ConfirmApproveContent from '.' ;
const renderComponent = ( props ) => {
2022-08-10 03:26:25 +02:00
const store = configureMockStore ( [ ] ) ( {
metamask : { provider : { chainId : '0x0' } } ,
} ) ;
2021-10-28 21:16:03 +02:00
return renderWithProvider ( < ConfirmApproveContent { ... props } / > , store ) ;
} ;
const props = {
siteImage : 'https://metamask.github.io/test-dapp/metamask-fox.svg' ,
origin : 'https://metamask.github.io/test-dapp/' ,
2023-01-23 17:19:55 +01:00
tokenSymbol : 'TestDappCollectibles (#1)' ,
assetStandard : TokenStandard . ERC721 ,
2021-10-28 21:16:03 +02:00
tokenImage : 'https://metamask.github.io/test-dapp/metamask-fox.svg' ,
showCustomizeGasModal : jest . fn ( ) ,
2022-07-31 20:26:40 +02:00
data : '0x095ea7b30000000000000000000000009bc5baf874d2da8d216ae9f137804184ee5afef40000000000000000000000000000000000000000000000000000000000011170' ,
2021-10-28 21:16:03 +02:00
toAddress : '0x9bc5baf874d2da8d216ae9f137804184ee5afef4' ,
2023-02-03 18:13:19 +01:00
currentCurrency : 'usd' ,
2021-10-28 21:16:03 +02:00
nativeCurrency : 'ETH' ,
ethTransactionTotal : '20' ,
fiatTransactionTotal : '10' ,
useNonceField : true ,
nextNonce : 1 ,
customNonceValue : '2' ,
2023-02-02 00:14:09 +01:00
txData : { simulationFails : null } ,
userAcknowledgedGasMissing : false ,
setUserAcknowledgedGasMissing : jest . fn ( ) ,
renderSimulationFailureWarning : false ,
2021-10-28 21:16:03 +02:00
showCustomizeNonceModal : jest . fn ( ) ,
chainId : '1337' ,
rpcPrefs : { } ,
isContract : true ,
2023-02-03 18:13:19 +01:00
useCurrencyRateCheck : true ,
2023-03-20 18:05:48 +01:00
isSetApproveForAll : false ,
isApprovalOrRejection : true ,
2021-10-28 21:16:03 +02:00
} ;
describe ( 'ConfirmApproveContent Component' , ( ) => {
it ( 'should render Confirm approve page correctly' , ( ) => {
2022-08-02 20:38:15 +02:00
const { queryByText , getByText , getAllByText , getByTestId } =
renderComponent ( props ) ;
2022-08-24 18:02:18 +02:00
expect (
queryByText ( 'https://metamask.github.io/test-dapp/' ) ,
) . toBeInTheDocument ( ) ;
2022-08-02 20:38:15 +02:00
expect ( getByTestId ( 'confirm-approve-title' ) . textContent ) . toStrictEqual (
2023-01-23 17:19:55 +01:00
' Allow access to and transfer of your TestDappCollectibles (#1)? ' ,
2022-08-02 20:38:15 +02:00
) ;
2021-10-28 21:16:03 +02:00
expect (
queryByText (
2023-01-23 17:19:55 +01:00
'This allows a third party to access and transfer the following NFTs without further notice until you revoke its access.' ,
2021-10-28 21:16:03 +02:00
) ,
) . toBeInTheDocument ( ) ;
2023-04-11 05:19:42 +02:00
expect ( queryByText ( 'Verify third-party details' ) ) . toBeInTheDocument ( ) ;
2023-02-02 00:14:09 +01:00
expect (
queryByText (
'We were not able to estimate gas. There might be an error in the contract and this transaction may fail.' ,
) ,
) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'I want to proceed anyway' ) ) . not . toBeInTheDocument ( ) ;
2022-09-06 15:36:02 +02:00
expect ( queryByText ( 'View full transaction details' ) ) . toBeInTheDocument ( ) ;
2021-10-28 21:16:03 +02:00
const editButtons = getAllByText ( 'Edit' ) ;
2021-11-15 23:04:09 +01:00
expect ( queryByText ( 'Transaction fee' ) ) . toBeInTheDocument ( ) ;
2021-10-28 21:16:03 +02:00
expect (
queryByText ( 'A fee is associated with this request.' ) ,
) . toBeInTheDocument ( ) ;
expect ( queryByText ( ` ${ props . ethTransactionTotal } ETH ` ) ) . toBeInTheDocument ( ) ;
2023-02-03 18:13:19 +01:00
expect ( queryByText ( ` $ 10.00 ` ) ) . toBeInTheDocument ( ) ;
2021-10-28 21:16:03 +02:00
fireEvent . click ( editButtons [ 0 ] ) ;
expect ( props . showCustomizeGasModal ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( queryByText ( 'Nonce' ) ) . toBeInTheDocument ( ) ;
expect ( queryByText ( '2' ) ) . toBeInTheDocument ( ) ;
fireEvent . click ( editButtons [ 1 ] ) ;
expect ( props . showCustomizeNonceModal ) . toHaveBeenCalledTimes ( 1 ) ;
2021-11-02 23:15:05 +01:00
2022-09-06 15:36:02 +02:00
const showViewTxDetails = getByText ( 'View full transaction details' ) ;
2023-02-02 00:14:09 +01:00
expect ( queryByText ( 'Permission request' ) ) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'Approved asset:' ) ) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'Granted to:' ) ) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'Data' ) ) . not . toBeInTheDocument ( ) ;
fireEvent . click ( showViewTxDetails ) ;
expect ( getByText ( 'Hide full transaction details' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Permission request' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Approved asset:' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Granted to:' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Contract (0x9bc5baF8...fEF4)' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Data' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Function: Approve' ) ) . toBeInTheDocument ( ) ;
expect (
getByText (
'0x095ea7b30000000000000000000000009bc5baf874d2da8d216ae9f137804184ee5afef40000000000000000000000000000000000000000000000000000000000011170' ,
) ,
) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should render Confirm approve page correctly and simulation error message without I want to procced anyway link' , ( ) => {
const { queryByText , getByText , getAllByText , getByTestId } =
2023-02-03 18:13:19 +01:00
renderComponent ( {
... props ,
userAcknowledgedGasMissing : true ,
renderSimulationFailureWarning : true ,
} ) ;
2023-02-02 00:14:09 +01:00
expect (
queryByText ( 'https://metamask.github.io/test-dapp/' ) ,
) . toBeInTheDocument ( ) ;
expect ( getByTestId ( 'confirm-approve-title' ) . textContent ) . toStrictEqual (
' Allow access to and transfer of your TestDappCollectibles (#1)? ' ,
) ;
expect (
queryByText (
'This allows a third party to access and transfer the following NFTs without further notice until you revoke its access.' ,
) ,
) . toBeInTheDocument ( ) ;
2023-04-11 05:19:42 +02:00
expect ( queryByText ( 'Verify third-party details' ) ) . toBeInTheDocument ( ) ;
2023-02-02 00:14:09 +01:00
expect (
queryByText (
'We were not able to estimate gas. There might be an error in the contract and this transaction may fail.' ,
) ,
) . toBeInTheDocument ( ) ;
expect ( queryByText ( 'I want to proceed anyway' ) ) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'View full transaction details' ) ) . toBeInTheDocument ( ) ;
const editButtons = getAllByText ( 'Edit' ) ;
expect ( queryByText ( 'Transaction fee' ) ) . toBeInTheDocument ( ) ;
expect (
queryByText ( 'A fee is associated with this request.' ) ,
) . toBeInTheDocument ( ) ;
expect ( queryByText ( ` ${ props . ethTransactionTotal } ETH ` ) ) . toBeInTheDocument ( ) ;
fireEvent . click ( editButtons [ 0 ] ) ;
expect ( props . showCustomizeGasModal ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( queryByText ( 'Nonce' ) ) . toBeInTheDocument ( ) ;
expect ( queryByText ( '2' ) ) . toBeInTheDocument ( ) ;
fireEvent . click ( editButtons [ 1 ] ) ;
expect ( props . showCustomizeNonceModal ) . toHaveBeenCalledTimes ( 2 ) ;
const showViewTxDetails = getByText ( 'View full transaction details' ) ;
expect ( queryByText ( 'Permission request' ) ) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'Approved asset:' ) ) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'Granted to:' ) ) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'Data' ) ) . not . toBeInTheDocument ( ) ;
fireEvent . click ( showViewTxDetails ) ;
expect ( getByText ( 'Hide full transaction details' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Permission request' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Approved asset:' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Granted to:' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Contract (0x9bc5baF8...fEF4)' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Data' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Function: Approve' ) ) . toBeInTheDocument ( ) ;
expect (
getByText (
'0x095ea7b30000000000000000000000009bc5baf874d2da8d216ae9f137804184ee5afef40000000000000000000000000000000000000000000000000000000000011170' ,
) ,
) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should render Confirm approve page correctly and simulation error message with I want to procced anyway link' , ( ) => {
const { queryByText , getByText , getAllByText , getByTestId } =
2023-02-03 18:13:19 +01:00
renderComponent ( {
... props ,
userAcknowledgedGasMissing : false ,
renderSimulationFailureWarning : true ,
} ) ;
2023-02-02 00:14:09 +01:00
expect (
queryByText ( 'https://metamask.github.io/test-dapp/' ) ,
) . toBeInTheDocument ( ) ;
expect ( getByTestId ( 'confirm-approve-title' ) . textContent ) . toStrictEqual (
' Allow access to and transfer of your TestDappCollectibles (#1)? ' ,
) ;
expect (
queryByText (
'This allows a third party to access and transfer the following NFTs without further notice until you revoke its access.' ,
) ,
) . toBeInTheDocument ( ) ;
2023-04-11 05:19:42 +02:00
expect ( queryByText ( 'Verify third-party details' ) ) . toBeInTheDocument ( ) ;
2023-02-02 00:14:09 +01:00
expect (
queryByText (
'We were not able to estimate gas. There might be an error in the contract and this transaction may fail.' ,
) ,
) . toBeInTheDocument ( ) ;
expect ( queryByText ( 'I want to proceed anyway' ) ) . toBeInTheDocument ( ) ;
expect ( queryByText ( 'View full transaction details' ) ) . toBeInTheDocument ( ) ;
const editButtons = getAllByText ( 'Edit' ) ;
expect ( queryByText ( 'Transaction fee' ) ) . toBeInTheDocument ( ) ;
expect (
queryByText ( 'A fee is associated with this request.' ) ,
) . toBeInTheDocument ( ) ;
expect ( queryByText ( ` ${ props . ethTransactionTotal } ETH ` ) ) . toBeInTheDocument ( ) ;
fireEvent . click ( editButtons [ 0 ] ) ;
expect ( props . showCustomizeGasModal ) . toHaveBeenCalledTimes ( 3 ) ;
expect ( queryByText ( 'Nonce' ) ) . toBeInTheDocument ( ) ;
expect ( queryByText ( '2' ) ) . toBeInTheDocument ( ) ;
fireEvent . click ( editButtons [ 1 ] ) ;
expect ( props . showCustomizeNonceModal ) . toHaveBeenCalledTimes ( 3 ) ;
const showViewTxDetails = getByText ( 'View full transaction details' ) ;
2023-02-03 18:13:19 +01:00
expect ( queryByText ( 'Permission request' ) ) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'Approved asset:' ) ) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'Granted to:' ) ) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'Data' ) ) . not . toBeInTheDocument ( ) ;
fireEvent . click ( showViewTxDetails ) ;
expect ( getByText ( 'Hide full transaction details' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Permission request' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Approved asset:' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Granted to:' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Contract (0x9bc5baF8...fEF4)' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Data' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Function: Approve' ) ) . toBeInTheDocument ( ) ;
expect (
getByText (
'0x095ea7b30000000000000000000000009bc5baf874d2da8d216ae9f137804184ee5afef40000000000000000000000000000000000000000000000000000000000011170' ,
) ,
) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should render Confirm approve page correctly when the fiat conversion is OFF' , ( ) => {
const { queryByText , getByText , getAllByText , getByTestId } =
renderComponent ( { ... props , useCurrencyRateCheck : false } ) ;
expect (
queryByText ( 'https://metamask.github.io/test-dapp/' ) ,
) . toBeInTheDocument ( ) ;
expect ( getByTestId ( 'confirm-approve-title' ) . textContent ) . toStrictEqual (
' Allow access to and transfer of your TestDappCollectibles (#1)? ' ,
) ;
expect (
queryByText (
'This allows a third party to access and transfer the following NFTs without further notice until you revoke its access.' ,
) ,
) . toBeInTheDocument ( ) ;
2023-04-11 05:19:42 +02:00
expect ( queryByText ( 'Verify third-party details' ) ) . toBeInTheDocument ( ) ;
2023-02-03 18:13:19 +01:00
expect (
queryByText (
'We were not able to estimate gas. There might be an error in the contract and this transaction may fail.' ,
) ,
) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'I want to proceed anyway' ) ) . not . toBeInTheDocument ( ) ;
expect ( queryByText ( 'View full transaction details' ) ) . toBeInTheDocument ( ) ;
const editButtons = getAllByText ( 'Edit' ) ;
expect ( queryByText ( 'Transaction fee' ) ) . toBeInTheDocument ( ) ;
expect (
queryByText ( 'A fee is associated with this request.' ) ,
) . toBeInTheDocument ( ) ;
expect ( queryByText ( ` ${ props . ethTransactionTotal } ETH ` ) ) . toBeInTheDocument ( ) ;
expect ( queryByText ( ` $ 10.00 ` ) ) . not . toBeInTheDocument ( ) ;
fireEvent . click ( editButtons [ 0 ] ) ;
expect ( props . showCustomizeGasModal ) . toHaveBeenCalledTimes ( 4 ) ;
expect ( queryByText ( 'Nonce' ) ) . toBeInTheDocument ( ) ;
expect ( queryByText ( '2' ) ) . toBeInTheDocument ( ) ;
fireEvent . click ( editButtons [ 1 ] ) ;
expect ( props . showCustomizeNonceModal ) . toHaveBeenCalledTimes ( 4 ) ;
const showViewTxDetails = getByText ( 'View full transaction details' ) ;
2022-04-26 17:21:52 +02:00
expect ( queryByText ( 'Permission request' ) ) . not . toBeInTheDocument ( ) ;
2023-01-23 17:19:55 +01:00
expect ( queryByText ( 'Approved asset:' ) ) . not . toBeInTheDocument ( ) ;
2022-04-26 17:21:52 +02:00
expect ( queryByText ( 'Granted to:' ) ) . not . toBeInTheDocument ( ) ;
2023-01-23 17:19:55 +01:00
expect ( queryByText ( 'Data' ) ) . not . toBeInTheDocument ( ) ;
2022-09-06 15:36:02 +02:00
fireEvent . click ( showViewTxDetails ) ;
expect ( getByText ( 'Hide full transaction details' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Permission request' ) ) . toBeInTheDocument ( ) ;
2023-01-23 17:19:55 +01:00
expect ( getByText ( 'Approved asset:' ) ) . toBeInTheDocument ( ) ;
2022-09-06 15:36:02 +02:00
expect ( getByText ( 'Granted to:' ) ) . toBeInTheDocument ( ) ;
2023-01-23 17:19:55 +01:00
expect ( getByText ( 'Contract (0x9bc5baF8...fEF4)' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Data' ) ) . toBeInTheDocument ( ) ;
expect ( getByText ( 'Function: Approve' ) ) . toBeInTheDocument ( ) ;
expect (
getByText (
'0x095ea7b30000000000000000000000009bc5baf874d2da8d216ae9f137804184ee5afef40000000000000000000000000000000000000000000000000000000000011170' ,
) ,
) . toBeInTheDocument ( ) ;
2021-10-28 21:16:03 +02:00
} ) ;
2023-03-20 18:05:48 +01:00
it ( 'should render Confirm approve page correctly and display fallback copy for when we are able to retrieve a erc721 or erc1155 name in the setApprovalForAll screen and when giving a setApprovalForAll allowance' , ( ) => {
const { container } = renderComponent ( {
... props ,
tokenSymbol : 'ZenAcademy' ,
isSetApproveForAll : true ,
} ) ;
expect ( container ) . toMatchSnapshot ( ) ;
} ) ;
it ( 'should render Confirm approve page correctly and display fallback copy for when we are not able to retrieve a erc721 or erc1155 name in the setApprovalForAll screen and when giving a setApprovalForAll allowance' , ( ) => {
const { container } = renderComponent ( {
... props ,
tokenSymbol : '' ,
isSetApproveForAll : true ,
} ) ;
expect ( container ) . toMatchSnapshot ( ) ;
} ) ;
it ( 'should render Confirm approve page correctly and display fallback copy for when we are able to retrieve a erc721 or erc1155 name in the setApprovalForAll screen and when revoking a setApprovalForAll allowance' , ( ) => {
const { container } = renderComponent ( {
... props ,
tokenSymbol : 'ZenAcademy' ,
isSetApproveForAll : true ,
isApprovalOrRejection : false ,
} ) ;
expect ( container ) . toMatchSnapshot ( ) ;
} ) ;
it ( 'should render Confirm approve page correctly and display fallback copy for when we are not able to retrieve a erc721 or erc1155 name in the setApprovalForAll screen and when revoking a setApprovalForAll allowance' , ( ) => {
const { container } = renderComponent ( {
... props ,
tokenSymbol : '' ,
isSetApproveForAll : true ,
isApprovalOrRejection : false ,
} ) ;
expect ( container ) . toMatchSnapshot ( ) ;
} ) ;
2021-10-28 21:16:03 +02:00
} ) ;