2024-07-01 15:56:44 +00:00
import QtQuick 2.15
import QtQuick . Controls 2.15
import QtTest 1.15
import QtQml 2.15
import Models 1.0
import StatusQ . Core . Utils 0.1 as SQUtils
import AppLayouts . Wallet . popups . swap 1.0
import utils 1.0
Item {
id: root
width: 600
height: 400
Component {
id: componentUnderTest
SwapSignModal {
anchors.centerIn: parent
2024-07-31 10:04:51 +00:00
formatBigNumber: ( number , symbol , noSymbolOption ) = > parseFloat ( number ) . toLocaleString ( Qt . locale ( ) , 'f' , 2 ) + ( noSymbolOption ? "" : " " + symbol )
2024-07-17 16:03:36 +00:00
2024-07-01 15:56:44 +00:00
fromTokenSymbol: "DAI"
fromTokenAmount: "100.07"
fromTokenContractAddress: "0x6B175474E89094C44Da98b954EedeAC495271d0F"
toTokenSymbol: "USDT"
toTokenAmount: "142.07"
toTokenContractAddress: "0xdAC17F958D2ee523a2206206994597C13D831ec7"
accountName: "Hot wallet (generated)"
accountAddress: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881"
accountEmoji: "🚗"
accountColor: Utils . getColorForId ( Constants . walletAccountColors . primary )
networkShortName: Constants . networkShortChainNames . mainnet
networkName: "Mainnet"
networkIconPath: Style . svg ( "network/Network=Ethereum" )
networkBlockExplorerUrl: "https://etherscan.io/"
2024-07-17 08:16:02 +00:00
serviceProviderName: Constants . swap . paraswapName
2024-08-08 13:52:19 +00:00
serviceProviderURL: Constants . swap . paraswapUrl
serviceProviderTandCUrl: Constants . swap . paraswapTermsAndConditionUrl
2024-07-22 16:22:33 +00:00
2024-07-10 18:35:24 +00:00
fiatFees: "1.54 EUR"
cryptoFees: "0.001 ETH"
2024-07-01 15:56:44 +00:00
slippage: 0.2
loginType: Constants . LoginType . Password
}
}
SignalSpy {
id: signalSpyAccepted
target: controlUnderTest
signalName: "accepted"
}
SignalSpy {
id: signalSpyRejected
target: controlUnderTest
signalName: "rejected"
}
property SwapSignModal controlUnderTest: null
TestCase {
name: "SwapSignModal"
when: windowShown
function init ( ) {
controlUnderTest = createTemporaryObject ( componentUnderTest , root )
signalSpyAccepted . clear ( )
signalSpyRejected . clear ( )
}
function test_basicGeometry ( ) {
verify ( ! ! controlUnderTest )
verify ( controlUnderTest . width > 0 )
verify ( controlUnderTest . height > 0 )
}
2024-07-10 18:35:24 +00:00
function test_fromToProps_data ( ) {
return [
{ tag: "ETH" , toTokenSymbol: "ETH" } ,
{ tag: "DAI" , toTokenSymbol: "DAI" } ,
]
}
function test_fromToProps ( data ) {
2024-07-01 15:56:44 +00:00
verify ( ! ! controlUnderTest )
controlUnderTest . fromTokenSymbol = "SNT"
controlUnderTest . fromTokenAmount = "1000.123456789"
controlUnderTest . fromTokenContractAddress = "Oxdeadbeef"
2024-07-10 18:35:24 +00:00
controlUnderTest . toTokenSymbol = data . toTokenSymbol
2024-07-01 15:56:44 +00:00
controlUnderTest . toTokenAmount = "1.42"
controlUnderTest . toTokenContractAddress = "0xdeadcaff"
2024-10-08 15:28:33 +00:00
// subtitle
2024-07-31 10:04:51 +00:00
compare ( controlUnderTest . subtitle , qsTr ( "%1 to %2" ) . arg ( controlUnderTest . formatBigNumber ( controlUnderTest . fromTokenAmount , controlUnderTest . fromTokenSymbol ) )
. arg ( controlUnderTest . formatBigNumber ( controlUnderTest . toTokenAmount , controlUnderTest . toTokenSymbol ) ) )
2024-07-01 15:56:44 +00:00
// info box
const headerText = findChild ( controlUnderTest . contentItem , "headerText" )
verify ( ! ! headerText )
2024-07-31 10:04:51 +00:00
compare ( headerText . text , qsTr ( "Swap 1,000.12 SNT to 1.42 %3 in %1 on %2" ) . arg ( controlUnderTest . accountName ) . arg ( controlUnderTest . networkName ) . arg ( data . toTokenSymbol ) )
2024-07-11 21:00:15 +00:00
const fromImage = findChild ( controlUnderTest . contentItem , "fromImageIdenticon" )
2024-07-01 15:56:44 +00:00
verify ( ! ! fromImage )
2024-07-11 21:00:15 +00:00
compare ( fromImage . asset . name , Constants . tokenIcon ( controlUnderTest . fromTokenSymbol ) )
const toImage = findChild ( controlUnderTest . contentItem , "toImageIdenticon" )
2024-07-01 15:56:44 +00:00
verify ( ! ! toImage )
2024-07-11 21:00:15 +00:00
compare ( toImage . asset . name , Constants . tokenIcon ( controlUnderTest . toTokenSymbol ) )
2024-07-01 15:56:44 +00:00
// pay box
const payBox = findChild ( controlUnderTest . contentItem , "payBox" )
verify ( ! ! payBox )
compare ( payBox . caption , qsTr ( "Pay" ) )
2024-07-31 10:04:51 +00:00
compare ( payBox . primaryText , "1,000.12 SNT" )
2024-07-01 15:56:44 +00:00
compare ( payBox . secondaryText , SQUtils . Utils . elideAndFormatWalletAddress ( controlUnderTest . fromTokenContractAddress ) )
// receive box
const receiveBox = findChild ( controlUnderTest . contentItem , "receiveBox" )
verify ( ! ! receiveBox )
compare ( receiveBox . caption , qsTr ( "Receive" ) )
compare ( receiveBox . primaryText , "%1 %2" . arg ( controlUnderTest . toTokenAmount ) . arg ( controlUnderTest . toTokenSymbol ) )
2024-07-10 18:35:24 +00:00
compare ( receiveBox . secondaryText ,
data . toTokenSymbol === "ETH" ? ""
: SQUtils . Utils . elideAndFormatWalletAddress ( controlUnderTest . toTokenContractAddress ) )
2024-07-01 15:56:44 +00:00
}
function test_accountInfo ( ) {
verify ( ! ! controlUnderTest )
// account box
const accountBox = findChild ( controlUnderTest . contentItem , "accountBox" )
verify ( ! ! accountBox )
compare ( accountBox . caption , qsTr ( "In account" ) )
compare ( accountBox . primaryText , controlUnderTest . accountName )
compare ( accountBox . secondaryText , SQUtils . Utils . elideAndFormatWalletAddress ( controlUnderTest . accountAddress ) )
compare ( accountBox . asset . emoji , controlUnderTest . accountEmoji )
compare ( accountBox . asset . color , controlUnderTest . accountColor )
}
function test_networkInfo ( ) {
verify ( ! ! controlUnderTest )
// network box
const networkBox = findChild ( controlUnderTest . contentItem , "networkBox" )
verify ( ! ! networkBox )
compare ( networkBox . caption , qsTr ( "Network" ) )
compare ( networkBox . primaryText , controlUnderTest . networkName )
compare ( networkBox . icon , controlUnderTest . networkIconPath )
}
function test_feesInfo ( ) {
verify ( ! ! controlUnderTest )
2024-07-04 11:55:16 +00:00
// fees box
2024-07-01 15:56:44 +00:00
const feesBox = findChild ( controlUnderTest . contentItem , "feesBox" )
verify ( ! ! feesBox )
compare ( feesBox . caption , qsTr ( "Fees" ) )
compare ( feesBox . primaryText , qsTr ( "Max. fees on %1" ) . arg ( controlUnderTest . networkName ) )
const fiatFeesText = findChild ( feesBox , "fiatFeesText" )
verify ( ! ! fiatFeesText )
2024-07-10 18:35:24 +00:00
compare ( fiatFeesText . text , controlUnderTest . fiatFees )
2024-07-01 15:56:44 +00:00
const cryptoFeesText = findChild ( feesBox , "cryptoFeesText" )
verify ( ! ! cryptoFeesText )
2024-07-10 18:35:24 +00:00
compare ( cryptoFeesText . text , controlUnderTest . cryptoFees )
2024-07-01 15:56:44 +00:00
}
function test_loginType_data ( ) {
return [
{ tag: "password" , loginType: Constants . LoginType . Password , iconName: "password" } ,
{ tag: "touchId" , loginType: Constants . LoginType . Biometrics , iconName: "touch-id" } ,
{ tag: "keycard" , loginType: Constants . LoginType . Keycard , iconName: "keycard" }
]
}
function test_loginType ( data ) {
const loginType = data . loginType
const iconName = data . iconName
verify ( ! ! controlUnderTest )
controlUnderTest . loginType = loginType
const signButton = findChild ( controlUnderTest . footer , "signButton" )
verify ( ! ! signButton )
compare ( signButton . icon . name , iconName )
}
function test_loading ( ) {
verify ( ! ! controlUnderTest )
compare ( controlUnderTest . feesLoading , false )
const signButton = findChild ( controlUnderTest . footer , "signButton" )
verify ( ! ! signButton )
compare ( signButton . interactive , true )
2024-07-04 11:55:16 +00:00
const footerFiatFeesText = findChild ( controlUnderTest . footer , "footerFiatFeesText" )
verify ( ! ! footerFiatFeesText )
compare ( footerFiatFeesText . loading , false )
const fiatFeesText = findChild ( controlUnderTest . contentItem , "fiatFeesText" )
2024-07-01 15:56:44 +00:00
verify ( ! ! fiatFeesText )
compare ( fiatFeesText . loading , false )
2024-07-04 11:55:16 +00:00
const cryptoFeesText = findChild ( controlUnderTest . contentItem , "cryptoFeesText" )
verify ( ! ! cryptoFeesText )
compare ( cryptoFeesText . loading , false )
2024-07-01 15:56:44 +00:00
controlUnderTest . feesLoading = true
compare ( signButton . interactive , false )
2024-07-04 11:55:16 +00:00
compare ( footerFiatFeesText . loading , true )
2024-07-01 15:56:44 +00:00
compare ( fiatFeesText . loading , true )
2024-07-04 11:55:16 +00:00
compare ( cryptoFeesText . loading , true )
2024-07-01 15:56:44 +00:00
}
function test_footerInfo ( ) {
verify ( ! ! controlUnderTest )
const fiatFeesText = findChild ( controlUnderTest . footer , "footerFiatFeesText" )
verify ( ! ! fiatFeesText )
2024-07-10 18:35:24 +00:00
compare ( fiatFeesText . text , controlUnderTest . fiatFees )
2024-07-01 15:56:44 +00:00
const maxSlippageText = findChild ( controlUnderTest . footer , "footerMaxSlippageText" )
verify ( ! ! maxSlippageText )
compare ( maxSlippageText . text , "%1%" . arg ( controlUnderTest . slippage ) )
}
function test_signButton ( ) {
verify ( ! ! controlUnderTest )
const signButton = findChild ( controlUnderTest . footer , "signButton" )
verify ( ! ! signButton )
compare ( signButton . interactive , true )
signButton . clicked ( )
compare ( signalSpyAccepted . count , 1 )
compare ( controlUnderTest . opened , false )
compare ( controlUnderTest . result , Dialog . Accepted )
}
function test_rejectButton ( ) {
verify ( ! ! controlUnderTest )
const rejectButton = findChild ( controlUnderTest . footer , "rejectButton" )
verify ( ! ! rejectButton )
compare ( rejectButton . interactive , true )
rejectButton . clicked ( )
compare ( signalSpyRejected . count , 1 )
compare ( controlUnderTest . opened , false )
compare ( controlUnderTest . result , Dialog . Rejected )
}
}
}