2024-05-28 17:39:41 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtTest 1.15
|
|
|
|
|
|
|
|
import StatusQ 0.1
|
2024-06-14 11:34:20 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
2024-06-13 00:45:33 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
2024-05-28 17:39:41 +00:00
|
|
|
|
|
|
|
import AppLayouts.Wallet.stores 1.0
|
|
|
|
import AppLayouts.Wallet.panels 1.0
|
|
|
|
import AppLayouts.Wallet.popups.swap 1.0
|
2024-06-18 22:51:49 +00:00
|
|
|
import AppLayouts.Wallet.adaptors 1.0
|
2024-05-28 17:39:41 +00:00
|
|
|
|
|
|
|
import shared.stores 1.0
|
|
|
|
|
|
|
|
import Models 1.0
|
|
|
|
import Storybook 1.0
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
width: 600
|
|
|
|
height: 400
|
|
|
|
|
2024-06-25 13:37:42 +00:00
|
|
|
ListModel {
|
|
|
|
id: plainTokensModel
|
|
|
|
ListElement {
|
|
|
|
key: "aave"
|
|
|
|
name: "Aave"
|
|
|
|
symbol: "AAVE"
|
|
|
|
image: "https://cryptologos.cc/logos/aave-aave-logo.png"
|
|
|
|
communityId: ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-28 17:39:41 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
2024-07-03 16:29:30 +00:00
|
|
|
readonly property int goOptChainId: 420
|
2024-05-28 17:39:41 +00:00
|
|
|
|
|
|
|
readonly property SwapModalAdaptor adaptor: SwapModalAdaptor {
|
|
|
|
swapStore: SwapStore {
|
|
|
|
readonly property var accounts: WalletAccountsModel {}
|
|
|
|
readonly property var flatNetworks: NetworksModel.flatNetworks
|
2024-06-10 10:37:39 +00:00
|
|
|
readonly property bool areTestNetworksEnabled: true
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
|
|
|
walletAssetsStore: WalletAssetsStore {
|
|
|
|
id: thisWalletAssetStore
|
|
|
|
walletTokensStore: TokensStore {
|
|
|
|
plainTokensBySymbolModel: TokensBySymbolModel {}
|
|
|
|
}
|
|
|
|
readonly property var baseGroupedAccountAssetModel: GroupedAccountsAssetsModel {}
|
|
|
|
assetsWithFilteredBalances: thisWalletAssetStore.groupedAccountsAssetsModel
|
|
|
|
}
|
|
|
|
currencyStore: CurrenciesStore {}
|
2024-06-13 00:45:33 +00:00
|
|
|
swapFormData: SwapInputParamsForm {
|
|
|
|
selectedAccountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
|
|
|
|
}
|
2024-06-06 14:05:31 +00:00
|
|
|
swapOutputData: SwapOutputData {}
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
2024-06-18 22:51:49 +00:00
|
|
|
|
|
|
|
readonly property var tokenSelectorAdaptor: TokenSelectorViewAdaptor {
|
|
|
|
assetsModel: d.adaptor.walletAssetsStore.groupedAccountAssetsModel
|
2024-06-25 13:37:42 +00:00
|
|
|
plainTokensBySymbolModel: plainTokensModel
|
2024-06-18 22:51:49 +00:00
|
|
|
flatNetworksModel: d.adaptor.swapStore.flatNetworks
|
|
|
|
currentCurrency: d.adaptor.currencyStore.currentCurrency
|
|
|
|
|
|
|
|
accountAddress: d.adaptor.swapFormData.selectedAccountAddress
|
2024-07-03 16:29:30 +00:00
|
|
|
enabledChainIds: [d.goOptChainId]
|
2024-06-18 22:51:49 +00:00
|
|
|
}
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: componentUnderTest
|
|
|
|
SwapInputPanel {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
|
|
|
currencyStore: d.adaptor.currencyStore
|
2024-06-18 22:51:49 +00:00
|
|
|
flatNetworksModel: d.adaptor.swapStore.flatNetworks
|
|
|
|
processedAssetsModel: d.adaptor.walletAssetsStore.groupedAccountAssetsModel
|
2024-06-25 13:37:42 +00:00
|
|
|
plainTokensBySymbolModel: plainTokensModel
|
2024-07-03 16:29:30 +00:00
|
|
|
selectedAccountAddress: d.adaptor.swapFormData.selectedAccountAddress
|
|
|
|
selectedNetworkChainId: d.goOptChainId
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
property SwapInputPanel controlUnderTest: null
|
|
|
|
|
|
|
|
TestCase {
|
|
|
|
name: "SwapInputPanel"
|
|
|
|
when: windowShown
|
|
|
|
|
|
|
|
function test_basicSetupAndDefaults() {
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root)
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
verify(controlUnderTest.width > 0)
|
|
|
|
verify(controlUnderTest.height > 0)
|
|
|
|
|
|
|
|
tryCompare(controlUnderTest, "swapSide", SwapInputPanel.SwapSide.Pay)
|
|
|
|
tryCompare(controlUnderTest, "caption", qsTr("Pay"))
|
|
|
|
tryCompare(controlUnderTest, "selectedHoldingId", "")
|
2024-06-14 11:34:20 +00:00
|
|
|
tryCompare(controlUnderTest, "value", 0)
|
|
|
|
tryCompare(controlUnderTest, "rawValue", "0")
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_basicSetupReceiveSide() {
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root, {swapSide: SwapInputPanel.SwapSide.Receive})
|
|
|
|
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
verify(controlUnderTest.width > 0)
|
|
|
|
verify(controlUnderTest.height > 0)
|
|
|
|
|
|
|
|
tryCompare(controlUnderTest, "swapSide", SwapInputPanel.SwapSide.Receive)
|
|
|
|
tryCompare(controlUnderTest, "caption", qsTr("Receive"))
|
|
|
|
tryCompare(controlUnderTest, "selectedHoldingId", "")
|
2024-06-14 11:34:20 +00:00
|
|
|
tryCompare(controlUnderTest, "value", 0)
|
|
|
|
tryCompare(controlUnderTest, "rawValue", "0")
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_basicSetupWithInitialProperties() {
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root,
|
|
|
|
{
|
|
|
|
swapSide: SwapInputPanel.SwapSide.Pay,
|
|
|
|
tokenKey: "STT",
|
|
|
|
tokenAmount: "10000000.0000001"
|
|
|
|
})
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
waitForRendering(controlUnderTest)
|
|
|
|
|
|
|
|
tryCompare(controlUnderTest, "swapSide", SwapInputPanel.SwapSide.Pay)
|
|
|
|
tryCompare(controlUnderTest, "selectedHoldingId", "STT")
|
2024-06-14 11:34:20 +00:00
|
|
|
tryCompare(controlUnderTest, "value", 10000000.0000001)
|
|
|
|
verify(controlUnderTest.valueValid)
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_setTokenKeyAndAmounts_data() {
|
|
|
|
return [
|
|
|
|
{ tag: "1.42", tokenAmount: "1.42", valid: true },
|
|
|
|
{ tag: "0.00001", tokenAmount: "0.00001", valid: true },
|
|
|
|
{ tag: "1234567890", tokenAmount: "1234567890", valid: true },
|
|
|
|
{ tag: "1234567890.1234567890", tokenAmount: "1234567890.1234567890", valid: true },
|
|
|
|
{ tag: "abc", tokenAmount: "abc", valid: false },
|
2024-06-18 22:51:49 +00:00
|
|
|
{ tag: "NaN", tokenAmount: NaN, valid: false },
|
|
|
|
{ tag: "<empty>", tokenAmount: "", valid: false }
|
2024-05-28 17:39:41 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_setTokenKeyAndAmounts(data) {
|
|
|
|
const valid = data.valid
|
|
|
|
const tokenAmount = data.tokenAmount
|
|
|
|
const tokenSymbol = "STT"
|
|
|
|
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root)
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
controlUnderTest.tokenKey = tokenSymbol
|
|
|
|
controlUnderTest.tokenAmount = tokenAmount
|
|
|
|
|
|
|
|
tryCompare(controlUnderTest, "selectedHoldingId", tokenSymbol)
|
|
|
|
if (!valid)
|
|
|
|
expectFail(data.tag, "Invalid data expected to fail: %1".arg(tokenAmount))
|
2024-06-14 11:34:20 +00:00
|
|
|
tryCompare(controlUnderTest, "value", parseFloat(tokenAmount))
|
|
|
|
tryCompare(controlUnderTest, "valueValid", true)
|
2024-05-28 17:39:41 +00:00
|
|
|
|
|
|
|
const holdingSelector = findChild(controlUnderTest, "holdingSelector")
|
|
|
|
verify(!!holdingSelector)
|
2024-06-18 22:51:49 +00:00
|
|
|
tryCompare(holdingSelector, "currentTokensKey", tokenSymbol)
|
2024-05-28 17:39:41 +00:00
|
|
|
|
|
|
|
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
|
|
|
|
verify(!!amountToSendInput)
|
2024-08-14 13:04:28 +00:00
|
|
|
tryCompare(amountToSendInput, "text", AmountsArithmetic.fromString(tokenAmount).toLocaleString(Qt.locale(), 'f', -128))
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_enterTokenAmountLocalizedNumber() {
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root, {tokenKey: "STT"})
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
waitForRendering(controlUnderTest)
|
|
|
|
tryCompare(controlUnderTest, "selectedHoldingId", "STT")
|
|
|
|
|
|
|
|
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
mouseClick(amountToSendInput)
|
|
|
|
waitForRendering(amountToSendInput)
|
2024-08-14 13:04:28 +00:00
|
|
|
verify(amountToSendInput.cursorVisible)
|
2024-05-28 17:39:41 +00:00
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
amountToSendInput.locale = Qt.locale("cs_CZ")
|
|
|
|
compare(amountToSendInput.locale.name, "cs_CZ")
|
2024-05-28 17:39:41 +00:00
|
|
|
|
|
|
|
// manually entering "1000000,00000042" meaning "1000000,00000042"; `,` being the decimal separator
|
|
|
|
keyClick(Qt.Key_1)
|
|
|
|
for (let i = 0; i < 6; i++)
|
|
|
|
keyClick(Qt.Key_0)
|
|
|
|
keyClick(Qt.Key_Comma)
|
|
|
|
for (let i = 0; i < 6; i++)
|
|
|
|
keyClick(Qt.Key_0)
|
|
|
|
keyClick(Qt.Key_4)
|
|
|
|
keyClick(Qt.Key_2)
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
tryCompare(amountToSendInput, "text", "1000000,00000042")
|
2024-06-14 11:34:20 +00:00
|
|
|
tryCompare(controlUnderTest, "value", 1000000.00000042)
|
|
|
|
verify(controlUnderTest.valueValid)
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_selectSTTHoldingAndTypeAmount() {
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root)
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
|
|
|
|
const holdingSelector = findChild(controlUnderTest, "holdingSelector")
|
|
|
|
verify(!!holdingSelector)
|
|
|
|
mouseClick(holdingSelector)
|
|
|
|
waitForRendering(holdingSelector)
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
const assetSelectorList = findChild(holdingSelector, "tokenSelectorListview")
|
2024-05-28 17:39:41 +00:00
|
|
|
verify(!!assetSelectorList)
|
|
|
|
waitForRendering(assetSelectorList)
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
const sttDelegate = findChild(assetSelectorList, "tokenSelectorAssetDelegate_STT")
|
2024-05-28 17:39:41 +00:00
|
|
|
verify(!!sttDelegate)
|
2024-06-18 22:51:49 +00:00
|
|
|
mouseClick(sttDelegate)
|
2024-05-28 17:39:41 +00:00
|
|
|
|
|
|
|
tryCompare(controlUnderTest, "selectedHoldingId", "STT")
|
|
|
|
|
|
|
|
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
mouseClick(amountToSendInput)
|
|
|
|
waitForRendering(amountToSendInput)
|
2024-08-14 13:04:28 +00:00
|
|
|
verify(amountToSendInput.cursorVisible)
|
2024-05-28 17:39:41 +00:00
|
|
|
|
|
|
|
keyClick(Qt.Key_1)
|
|
|
|
keyClick(Qt.Key_Period)
|
|
|
|
keyClick(Qt.Key_4)
|
|
|
|
keyClick(Qt.Key_2)
|
|
|
|
|
2024-06-14 11:34:20 +00:00
|
|
|
tryCompare(controlUnderTest, "value", 1.42)
|
|
|
|
verify(controlUnderTest.valueValid)
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
|
|
|
|
2024-06-10 10:37:39 +00:00
|
|
|
// verify that when "fiatInputInteractive" mode is on, the Max send button text shows fiat currency symbol (e.g. "1.2 USD")
|
|
|
|
function test_maxButtonFiatCurrencySymbol() {
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root, {tokenKey: "ETH"})
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
waitForRendering(controlUnderTest)
|
|
|
|
controlUnderTest.fiatInputInteractive = true
|
|
|
|
|
|
|
|
const maxTagButton = findChild(controlUnderTest, "maxTagButton")
|
|
|
|
verify(!!maxTagButton)
|
|
|
|
waitForRendering(maxTagButton)
|
|
|
|
verify(maxTagButton.visible)
|
|
|
|
verify(!maxTagButton.text.endsWith("ETH"))
|
2024-06-14 11:34:20 +00:00
|
|
|
compare(maxTagButton.type, StatusBaseButton.Type.Normal)
|
2024-06-10 10:37:39 +00:00
|
|
|
mouseClick(maxTagButton)
|
|
|
|
|
|
|
|
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
waitForRendering(amountToSendInput)
|
|
|
|
|
|
|
|
const bottomItemText = findChild(amountToSendInput, "bottomItemText")
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
verify(bottomItemText.visible)
|
|
|
|
mouseClick(bottomItemText)
|
|
|
|
waitForRendering(amountToSendInput)
|
|
|
|
|
|
|
|
verify(maxTagButton.text.endsWith("USD"))
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify that in default mode, the Max send button text doesn't show the currency symbol for crypto (e.g. "1.2" for ETH)
|
|
|
|
function test_maxButtonNoCryptoCurrencySymbol() {
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root, {tokenKey: "ETH"})
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
waitForRendering(controlUnderTest)
|
|
|
|
|
|
|
|
const maxTagButton = findChild(controlUnderTest, "maxTagButton")
|
|
|
|
verify(!!maxTagButton)
|
|
|
|
waitForRendering(maxTagButton)
|
|
|
|
verify(maxTagButton.visible)
|
2024-06-14 11:34:20 +00:00
|
|
|
compare(maxTagButton.type, StatusBaseButton.Type.Normal)
|
2024-06-10 10:37:39 +00:00
|
|
|
verify(!maxTagButton.text.endsWith("ETH"))
|
|
|
|
}
|
|
|
|
|
2024-07-24 23:20:27 +00:00
|
|
|
// FIXME: This should be enabled after #15709 is resolved
|
2024-05-28 17:39:41 +00:00
|
|
|
function test_clickingMaxButton() {
|
2024-08-14 13:04:28 +00:00
|
|
|
skip("maxTabButton is disabled")
|
2024-05-28 17:39:41 +00:00
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root, {tokenKey: "ETH"})
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
waitForRendering(controlUnderTest)
|
|
|
|
tryCompare(controlUnderTest, "selectedHoldingId", "ETH")
|
|
|
|
|
|
|
|
const maxTagButton = findChild(controlUnderTest, "maxTagButton")
|
|
|
|
verify(!!maxTagButton)
|
|
|
|
waitForRendering(maxTagButton)
|
|
|
|
verify(maxTagButton.visible)
|
2024-06-14 11:34:20 +00:00
|
|
|
compare(maxTagButton.type, StatusBaseButton.Type.Normal)
|
2024-05-28 17:39:41 +00:00
|
|
|
mouseClick(maxTagButton)
|
|
|
|
|
|
|
|
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
waitForRendering(amountToSendInput)
|
2024-08-14 13:04:28 +00:00
|
|
|
const maxValue = maxTagButton.maxSafeValue
|
2024-05-28 17:39:41 +00:00
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
tryCompare(amountToSendInput, "text", maxValue.toLocaleString(Qt.locale(), 'f', -128))
|
2024-06-14 11:34:20 +00:00
|
|
|
tryCompare(controlUnderTest, "value", maxValue)
|
|
|
|
verify(controlUnderTest.valueValid)
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_loadingState() {
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root)
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
|
2024-06-14 11:34:20 +00:00
|
|
|
controlUnderTest.mainInputLoading = true
|
|
|
|
controlUnderTest.bottomTextLoading = true
|
2024-05-28 17:39:41 +00:00
|
|
|
|
|
|
|
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
const amountInput = findChild(amountToSendInput, "amountToSend_textField")
|
2024-05-28 17:39:41 +00:00
|
|
|
verify(!!amountInput)
|
|
|
|
verify(!amountInput.visible)
|
|
|
|
|
|
|
|
const topAmountToSendInputLoadingComponent = findChild(amountToSendInput, "topAmountToSendInputLoadingComponent")
|
|
|
|
verify(!!topAmountToSendInputLoadingComponent)
|
|
|
|
verify(topAmountToSendInputLoadingComponent.visible)
|
|
|
|
|
|
|
|
const bottomItemText = findChild(amountToSendInput, "bottomItemText")
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
verify(!bottomItemText.visible)
|
|
|
|
|
|
|
|
const bottomItemTextLoadingComponent = findChild(amountToSendInput, "bottomItemTextLoadingComponent")
|
|
|
|
verify(!!bottomItemTextLoadingComponent)
|
|
|
|
verify(bottomItemTextLoadingComponent.visible)
|
|
|
|
}
|
2024-06-14 11:34:20 +00:00
|
|
|
|
|
|
|
function test_max_button_when_different_tokens_clicked() {
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root)
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
|
|
|
|
const maxTagButton = findChild(controlUnderTest, "maxTagButton")
|
|
|
|
verify(!!maxTagButton)
|
|
|
|
verify(!maxTagButton.visible)
|
|
|
|
|
|
|
|
const holdingSelector = findChild(controlUnderTest, "holdingSelector")
|
|
|
|
verify(!!holdingSelector)
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
const assetSelectorList = findChild(holdingSelector, "tokenSelectorListview")
|
2024-06-14 11:34:20 +00:00
|
|
|
verify(!!assetSelectorList)
|
|
|
|
|
|
|
|
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
|
|
|
const bottomItemText = findChild(amountToSendInput, "bottomItemText")
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
for (let i= 0; i < d.tokenSelectorAdaptor.outputAssetsModel.count; i++) {
|
|
|
|
let modelItemToTest = ModelUtils.get(d.tokenSelectorAdaptor.outputAssetsModel, i)
|
|
|
|
mouseClick(holdingSelector)
|
2024-06-14 11:34:20 +00:00
|
|
|
waitForRendering(assetSelectorList)
|
|
|
|
|
|
|
|
let delToTest = assetSelectorList.itemAtIndex(i)
|
|
|
|
verify(!!delToTest)
|
2024-06-18 22:51:49 +00:00
|
|
|
mouseClick(delToTest)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
waitForRendering(controlUnderTest)
|
2024-06-14 11:34:20 +00:00
|
|
|
verify(maxTagButton.visible)
|
2024-08-14 13:04:28 +00:00
|
|
|
// FIXME: maxTagButton should be enabled after #15709 is resolved
|
2024-07-24 23:20:27 +00:00
|
|
|
verify(!maxTagButton.enabled)
|
2024-06-14 11:34:20 +00:00
|
|
|
verify(!maxTagButton.text.endsWith(modelItemToTest.symbol))
|
2024-06-18 22:51:49 +00:00
|
|
|
tryCompare(maxTagButton, "type", modelItemToTest.currentBalance === 0 ? StatusBaseButton.Type.Danger : StatusBaseButton.Type.Normal)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
|
|
|
// check input value and state
|
2024-07-24 23:20:27 +00:00
|
|
|
if (maxTagButton.enabled) {
|
|
|
|
mouseClick(maxTagButton)
|
|
|
|
waitForRendering(amountToSendInput)
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
tryCompare(amountToSendInput, "text", modelItemToTest.currentBalance === 0 ? "" : maxTagButton.maxSafeValue.toString())
|
|
|
|
tryCompare(controlUnderTest, "value", maxTagButton.maxSafeValue)
|
2024-07-24 23:20:27 +00:00
|
|
|
verify(modelItemToTest.currentBalance === 0 ? !controlUnderTest.valueValid : controlUnderTest.valueValid)
|
2024-08-14 13:04:28 +00:00
|
|
|
const marketPrice = amountToSendInput.price
|
2024-07-24 23:20:27 +00:00
|
|
|
compare(bottomItemText.text, d.adaptor.formatCurrencyAmount(
|
|
|
|
maxTagButton.maxSafeValue * marketPrice,
|
|
|
|
d.adaptor.currencyStore.currentCurrency))
|
|
|
|
}
|
2024-08-14 13:04:28 +00:00
|
|
|
amountToSendInput.clear()
|
2024-06-14 11:34:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_input_greater_than_max_balance() {
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root)
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
|
|
|
|
const maxTagButton = findChild(controlUnderTest, "maxTagButton")
|
|
|
|
verify(!!maxTagButton)
|
|
|
|
verify(!maxTagButton.visible)
|
|
|
|
|
|
|
|
const holdingSelector = findChild(controlUnderTest, "holdingSelector")
|
|
|
|
verify(!!holdingSelector)
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
const assetSelectorList = findChild(holdingSelector, "tokenSelectorListview")
|
2024-06-14 11:34:20 +00:00
|
|
|
verify(!!assetSelectorList)
|
|
|
|
|
|
|
|
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
|
|
|
const bottomItemText = findChild(amountToSendInput, "bottomItemText")
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
mouseClick(amountToSendInput)
|
2024-06-14 11:34:20 +00:00
|
|
|
// enter 5.42 as entered amount
|
|
|
|
keyClick(Qt.Key_5)
|
|
|
|
keyClick(Qt.Key_Period)
|
|
|
|
keyClick(Qt.Key_4)
|
|
|
|
keyClick(Qt.Key_2)
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
let numberTested = 5.42
|
|
|
|
tryCompare(amountToSendInput, "text", "5.42")
|
2024-06-14 11:34:20 +00:00
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
for (let i= 0; i < d.tokenSelectorAdaptor.outputAssetsModel.count; i++) {
|
|
|
|
let modelItemToTest = ModelUtils.get(d.tokenSelectorAdaptor.outputAssetsModel, i)
|
|
|
|
mouseClick(holdingSelector)
|
|
|
|
waitForRendering(holdingSelector)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
|
|
|
let delToTest = assetSelectorList.itemAtIndex(i)
|
|
|
|
verify(!!delToTest)
|
2024-07-01 12:03:08 +00:00
|
|
|
if(delToTest.interactive) {
|
|
|
|
mouseClick(delToTest)
|
|
|
|
|
|
|
|
// check input value and state
|
|
|
|
waitForItemPolished(controlUnderTest)
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
compare(amountToSendInput.text, "5.42")
|
|
|
|
const marketPrice = amountToSendInput.price
|
2024-07-01 12:03:08 +00:00
|
|
|
tryCompare(bottomItemText, "text", d.adaptor.formatCurrencyAmount(
|
2024-08-14 13:04:28 +00:00
|
|
|
numberTested * marketPrice,
|
|
|
|
d.adaptor.currencyStore.currentCurrency))
|
2024-07-01 12:03:08 +00:00
|
|
|
compare(controlUnderTest.value, numberTested)
|
2024-08-14 13:04:28 +00:00
|
|
|
compare(controlUnderTest.rawValue, AmountsArithmetic.fromNumber(amountToSendInput.text, modelItemToTest.decimals).toString())
|
2024-07-01 12:03:08 +00:00
|
|
|
compare(controlUnderTest.valueValid, numberTested <= maxTagButton.maxSafeValue)
|
|
|
|
compare(controlUnderTest.selectedHoldingId, modelItemToTest.tokensKey)
|
|
|
|
compare(controlUnderTest.amountEnteredGreaterThanBalance, numberTested > maxTagButton.maxSafeValue)
|
|
|
|
}
|
2024-06-14 11:34:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_if_values_are_reset_after_setting_tokenAmount_as_empty() {
|
|
|
|
const tokenKeyToTest = "ETH"
|
|
|
|
let numberTestedString = "1.0001"
|
2024-06-18 22:51:49 +00:00
|
|
|
let modelItemToTest = ModelUtils.getByKey(d.tokenSelectorAdaptor.outputAssetsModel, "tokensKey", tokenKeyToTest)
|
2024-06-14 11:34:20 +00:00
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root, {
|
|
|
|
swapSide: SwapInputPanel.SwapSide.Pay,
|
|
|
|
tokenKey: tokenKeyToTest,
|
|
|
|
tokenAmount: numberTestedString
|
|
|
|
})
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
waitForRendering(controlUnderTest)
|
|
|
|
|
|
|
|
|
|
|
|
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
|
|
|
const bottomItemText = findChild(amountToSendInput, "bottomItemText")
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
let numberTested = LocaleUtils.numberFromLocaleString(numberTestedString, amountToSendInput.locale)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
compare(amountToSendInput.text, numberTestedString)
|
2024-06-14 11:34:20 +00:00
|
|
|
compare(controlUnderTest.value, numberTested)
|
2024-08-14 13:04:28 +00:00
|
|
|
compare(controlUnderTest.rawValue, AmountsArithmetic.fromNumber(amountToSendInput.text, modelItemToTest.decimals).toString())
|
2024-06-14 11:34:20 +00:00
|
|
|
compare(controlUnderTest.valueValid, true)
|
|
|
|
compare(controlUnderTest.selectedHoldingId, tokenKeyToTest)
|
|
|
|
compare(controlUnderTest.amountEnteredGreaterThanBalance, false)
|
|
|
|
|
|
|
|
numberTestedString = ""
|
|
|
|
numberTested = 0
|
|
|
|
controlUnderTest.tokenAmount = numberTestedString
|
2024-06-18 22:51:49 +00:00
|
|
|
waitForItemPolished(controlUnderTest)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
tryCompare(amountToSendInput, "text", numberTestedString)
|
2024-06-18 22:51:49 +00:00
|
|
|
tryCompare(controlUnderTest, "value", numberTested)
|
2024-06-14 11:34:20 +00:00
|
|
|
compare(controlUnderTest.rawValue, AmountsArithmetic.fromNumber(numberTested, modelItemToTest.decimals).toString())
|
|
|
|
compare(controlUnderTest.valueValid, false)
|
|
|
|
compare(controlUnderTest.selectedHoldingId, tokenKeyToTest)
|
|
|
|
compare(controlUnderTest.amountEnteredGreaterThanBalance, false)
|
|
|
|
}
|
2024-07-31 13:02:10 +00:00
|
|
|
|
|
|
|
function test_if_values_not_reset_on_modelReset() {
|
|
|
|
const tokenKeyToTest = "ETH"
|
|
|
|
let numberTestedString = "1.0001"
|
|
|
|
let modelItemToTest = ModelUtils.getByKey(d.tokenSelectorAdaptor.outputAssetsModel, "tokensKey", tokenKeyToTest)
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root, {
|
|
|
|
swapSide: SwapInputPanel.SwapSide.Pay,
|
|
|
|
tokenKey: tokenKeyToTest,
|
|
|
|
tokenAmount: numberTestedString
|
|
|
|
})
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
waitForRendering(controlUnderTest)
|
|
|
|
|
|
|
|
|
|
|
|
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
let numberTested = LocaleUtils.numberFromLocaleString(numberTestedString, amountToSendInput.locale)
|
2024-07-31 13:02:10 +00:00
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
compare(amountToSendInput.text, numberTestedString)
|
2024-07-31 13:02:10 +00:00
|
|
|
compare(controlUnderTest.value, numberTested)
|
2024-08-14 13:04:28 +00:00
|
|
|
compare(controlUnderTest.rawValue, AmountsArithmetic.fromNumber(amountToSendInput.text, modelItemToTest.decimals).toString())
|
2024-07-31 13:02:10 +00:00
|
|
|
compare(controlUnderTest.valueValid, true)
|
|
|
|
compare(controlUnderTest.selectedHoldingId, tokenKeyToTest)
|
|
|
|
compare(controlUnderTest.amountEnteredGreaterThanBalance, false)
|
|
|
|
|
|
|
|
d.tokenSelectorAdaptor.assetsModel.modelReset()
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
compare(amountToSendInput.text, numberTestedString)
|
2024-07-31 13:02:10 +00:00
|
|
|
compare(controlUnderTest.value, numberTested)
|
2024-08-14 13:04:28 +00:00
|
|
|
compare(controlUnderTest.rawValue, AmountsArithmetic.fromNumber(amountToSendInput.text, modelItemToTest.decimals).toString())
|
2024-07-31 13:02:10 +00:00
|
|
|
compare(controlUnderTest.valueValid, true)
|
|
|
|
compare(controlUnderTest.selectedHoldingId, tokenKeyToTest)
|
|
|
|
compare(controlUnderTest.amountEnteredGreaterThanBalance, false)
|
|
|
|
}
|
2024-05-28 17:39:41 +00:00
|
|
|
}
|
|
|
|
}
|