-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30bfacb
commit 19d1588
Showing
8 changed files
with
285 additions
and
8 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
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* | ||
* @group rollupWithdraw | ||
*/ | ||
import { jest } from "@jest/globals"; | ||
import { WebDriver } from "selenium-webdriver"; | ||
import { getApi, initApi } from "../../utils/api"; | ||
import { DriverBuilder } from "../../utils/frontend/utils/Driver"; | ||
import { | ||
acceptNetworkSwitchInNewWindow, | ||
addExtraLogs, | ||
importMetamaskExtension, | ||
} from "../../utils/frontend/utils/Helper"; | ||
import "dotenv/config"; | ||
import { | ||
connectWallet, | ||
setupPage, | ||
setupPageWithState, | ||
waitForActionNotification, | ||
} from "../../utils/frontend/rollup-utils/Handlers"; | ||
import { WalletWrapper } from "../../utils/frontend/rollup-pages/WalletWrapper"; | ||
import { TransactionType } from "../../utils/frontend/rollup-pages/NotificationToast"; | ||
import { | ||
WithdrawActionType, | ||
WithdrawModal, | ||
} from "../../utils/frontend/rollup-pages/WithdrawModal"; | ||
|
||
jest.spyOn(console, "log").mockImplementation(jest.fn()); | ||
|
||
jest.setTimeout(1500000); | ||
let driver: WebDriver; | ||
|
||
let acc_addr = ""; | ||
let acc_addr_short = ""; | ||
const GETH_ASSET_NAME = "GETH"; | ||
|
||
describe("Gasp UI withdraw tests", () => { | ||
beforeAll(async () => { | ||
try { | ||
getApi(); | ||
} catch (e) { | ||
await initApi(); | ||
} | ||
|
||
driver = await DriverBuilder.getInstance(); | ||
acc_addr = await importMetamaskExtension(driver, true); | ||
acc_addr_short = acc_addr.slice(-4).toLowerCase(); | ||
|
||
await setupPage(driver); | ||
await connectWallet(driver, "Metamask", acc_addr_short); | ||
}); | ||
|
||
test("User can withdraw GETH", async () => { | ||
await setupPageWithState(driver, acc_addr_short); | ||
|
||
const walletWrapper = new WalletWrapper(driver); | ||
await walletWrapper.openWalletConnectionInfo(); | ||
await walletWrapper.openWithdraw(); | ||
const withdrawModal = new WithdrawModal(driver); | ||
const isModalVisible = await withdrawModal.isModalVisible(); | ||
expect(isModalVisible).toBeTruthy(); | ||
|
||
await withdrawModal.openChainList(); | ||
await withdrawModal.selectChain("Ethereum"); | ||
await withdrawModal.openTokensList(); | ||
await withdrawModal.waitForTokenListElementsVisible(GETH_ASSET_NAME); | ||
await withdrawModal.selectToken(GETH_ASSET_NAME); | ||
await withdrawModal.enterValue("1"); | ||
|
||
await withdrawModal.waitForContinueState(true, 60000); | ||
const isOriginFeeDisplayed = | ||
await withdrawModal.isDestinationFeeDisplayed(); | ||
expect(isOriginFeeDisplayed).toBeTruthy(); | ||
|
||
const isNetworkButtonEnabled = await withdrawModal.isNetworkButtonEnabled(); | ||
expect(isNetworkButtonEnabled).toBeTruthy(); | ||
|
||
await withdrawModal.clickWithdrawButtonByText(WithdrawActionType.Network); | ||
await acceptNetworkSwitchInNewWindow(driver); | ||
|
||
await withdrawModal.clickWithdrawButtonByText(WithdrawActionType.Withdraw); | ||
await waitForActionNotification(driver, TransactionType.Withdraw); | ||
}); | ||
|
||
afterEach(async () => { | ||
const session = await driver.getSession(); | ||
await addExtraLogs( | ||
driver, | ||
expect.getState().currentTestName + " - " + session.getId(), | ||
); | ||
}); | ||
|
||
afterAll(async () => { | ||
const api = getApi(); | ||
await api.disconnect(); | ||
await driver.quit(); | ||
DriverBuilder.destroy(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { By, WebDriver } from "selenium-webdriver"; | ||
import { sleep } from "../../utils"; | ||
import { | ||
buildDataTestIdXpath, | ||
buildXpathByElementText, | ||
buildXpathByText, | ||
clickElement, | ||
getText, | ||
isDisplayed, | ||
waitForElementStateInterval, | ||
waitForElementVisible, | ||
writeText, | ||
} from "../utils/Helper"; | ||
|
||
//SELECTORS | ||
const WITHDRAW_MODAL_CONTENT = "withdrawal-modal-content"; | ||
const BTN_CHAIN_SELECT = "chain-select-btn"; | ||
const CHAIN_SELECT_LIST = "chain-select-list"; | ||
const BTN_SELECT_TOKEN = "tokenInput-selector-btn"; | ||
const TOKEN_LIST = "tokenList"; | ||
const TOKEN_LIST_ITEM = "tokenList-item"; | ||
const TOKEN_TEXT_INPUT = "tokenInput-input"; | ||
const BTN_SUBMIT = "submit-withdrawal-button"; | ||
const ORIGIN_FEE = "origin-fee"; | ||
const DESTINATION_FEE = "destination-fee"; | ||
const FEE_VALUE = "fee-value"; | ||
const ERR_MESSAGE = "withdrawal-error-message"; | ||
|
||
export enum WithdrawActionType { | ||
Withdraw, | ||
Network, | ||
} | ||
|
||
export class WithdrawModal { | ||
driver: WebDriver; | ||
|
||
constructor(driver: WebDriver) { | ||
this.driver = driver; | ||
} | ||
|
||
withdrawAction: Record<WithdrawActionType, string> = { | ||
[WithdrawActionType.Withdraw]: "Withdraw", | ||
[WithdrawActionType.Network]: "Switch to Holesky", | ||
}; | ||
|
||
async isModalVisible() { | ||
const title = buildDataTestIdXpath(WITHDRAW_MODAL_CONTENT); | ||
return isDisplayed(this.driver, title); | ||
} | ||
|
||
async isOriginFeeDisplayed() { | ||
const xpath = | ||
buildDataTestIdXpath(ORIGIN_FEE) + buildDataTestIdXpath(FEE_VALUE); | ||
return isDisplayed(this.driver, xpath); | ||
} | ||
|
||
async isDestinationFeeDisplayed() { | ||
const xpath = | ||
buildDataTestIdXpath(DESTINATION_FEE) + buildDataTestIdXpath(FEE_VALUE); | ||
return isDisplayed(this.driver, xpath); | ||
} | ||
|
||
async openChainList() { | ||
await clickElement(this.driver, buildDataTestIdXpath(BTN_CHAIN_SELECT)); | ||
} | ||
|
||
async isErrorMessage() { | ||
const errMessageXpath = buildDataTestIdXpath(ERR_MESSAGE); | ||
return await isDisplayed(this.driver, errMessageXpath); | ||
} | ||
|
||
async selectChain(chainName: string) { | ||
await waitForElementVisible( | ||
this.driver, | ||
buildDataTestIdXpath(CHAIN_SELECT_LIST), | ||
5000, | ||
); | ||
const chainTestId = `${chainName}-chain`; | ||
const chainLocator = buildDataTestIdXpath(chainTestId); | ||
await sleep(1000); | ||
await waitForElementVisible(this.driver, chainLocator, 5000); | ||
await clickElement(this.driver, chainLocator); | ||
} | ||
|
||
async openTokensList() { | ||
await clickElement(this.driver, buildDataTestIdXpath(BTN_SELECT_TOKEN)); | ||
} | ||
|
||
async selectToken(assetName: string) { | ||
//const tokenTestId = `tokenList-item`; | ||
const tokenLocator = | ||
buildDataTestIdXpath(TOKEN_LIST_ITEM) + buildXpathByText(assetName); | ||
await sleep(1000); | ||
await waitForElementVisible(this.driver, tokenLocator, 5000); | ||
await clickElement(this.driver, tokenLocator); | ||
} | ||
|
||
async getTokenAmount(assetName: string) { | ||
const assetTestId = `token-list-token-${assetName}-balance`; | ||
const assetLocator = buildDataTestIdXpath(assetTestId); | ||
return parseFloat(await getText(this.driver, assetLocator)); | ||
} | ||
|
||
async waitForTokenListElementsVisible(assetName: string) { | ||
await waitForElementVisible( | ||
this.driver, | ||
buildDataTestIdXpath(TOKEN_LIST), | ||
5000, | ||
); | ||
const tokenTestId = `token-icon-${assetName}`; | ||
const tokenLocator = buildDataTestIdXpath(tokenTestId); | ||
await waitForElementVisible(this.driver, tokenLocator, 5000); | ||
} | ||
|
||
async enterValue(amount: string) { | ||
const inputTokenLocator = buildDataTestIdXpath(TOKEN_TEXT_INPUT); | ||
await clickElement(this.driver, inputTokenLocator); | ||
await writeText(this.driver, inputTokenLocator, amount); | ||
} | ||
|
||
async waitForContinueState(isEnabled: boolean, timeout: number) { | ||
const continueBtn = buildDataTestIdXpath(BTN_SUBMIT); | ||
await waitForElementStateInterval( | ||
this.driver, | ||
continueBtn, | ||
isEnabled, | ||
timeout, | ||
); | ||
} | ||
|
||
async clickContinue() { | ||
const continueBtn = buildDataTestIdXpath(BTN_SUBMIT); | ||
await clickElement(this.driver, continueBtn); | ||
} | ||
|
||
async isContinueButtonEnabled() { | ||
const xpath = buildDataTestIdXpath(BTN_SUBMIT); | ||
return await (await this.driver.findElement(By.xpath(xpath))).isEnabled(); | ||
} | ||
|
||
async isNetworkButtonEnabled() { | ||
const xpath = buildXpathByElementText("button", "Switch to Holesky"); | ||
return await (await this.driver.findElement(By.xpath(xpath))).isEnabled(); | ||
} | ||
|
||
async clickWithdrawButtonByText(action: WithdrawActionType) { | ||
const xpath = | ||
buildDataTestIdXpath(WITHDRAW_MODAL_CONTENT) + | ||
buildXpathByElementText("button", this.withdrawAction[action]); | ||
await clickElement(this.driver, xpath); | ||
} | ||
} |
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