Skip to content

Commit

Permalink
feat(e2e): Convert to pw test suite exchange-coins.test.ts (#16104)
Browse files Browse the repository at this point in the history
* feat(e2e): COnvert to pw test suite exchange-coins.test.ts

Test is currently skipped and will be later refactored once all tests are converted
It was not running in cypress suite too.

* fix(e2e): Skiping market tests until we implement invity mock
  • Loading branch information
Vere-Grey authored Jan 2, 2025
1 parent 7748d59 commit c813a28
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export class MarketActions {
readonly youPayCurrencyOption = (currency: FiatCurrencyCode) =>
this.page.getByTestId(`@coinmarket/form/fiat-currency-select/option/${currency}`);
readonly countryOfResidenceDropdown: Locator;
readonly countryOfResidenceOption = (countryCode: string) =>
this.page.getByTestId(`@coinmarket/form/country-select/option/${countryCode}`);
readonly buyOffersPage: Locator;
readonly compareButton: Locator;
readonly quotes: Locator;
Expand All @@ -42,6 +44,7 @@ export class MarketActions {
readonly tradeConfirmationCryptoAmount: Locator;
readonly tradeConfirmationProvider: Locator;
readonly tradeConfirmationContinueButton: Locator;
readonly exchangeFeeDetails: Locator;

constructor(private page: Page) {
this.offerSpinner = this.page.getByTestId('@coinmarket/offers/loading-spinner');
Expand Down Expand Up @@ -82,6 +85,7 @@ export class MarketActions {
this.tradeConfirmationContinueButton = this.page.getByTestId(
'@coinmarket/offer/continue-transaction-button',
);
this.exchangeFeeDetails = this.page.getByTestId('@wallet/fee-details');
}

waitForOffersSyncToFinish = async () => {
Expand All @@ -91,24 +95,24 @@ export class MarketActions {
await expect(this.buyBestOfferButton).toBeEnabled();
};

selectCountryOfResidence = async (country: string) => {
const countryLabel = getCountryLabel(country);
selectCountryOfResidence = async (countryCode: string) => {
const countryLabel = getCountryLabel(countryCode);
const currentCountry = await this.countryOfResidenceDropdown.textContent();
if (currentCountry === countryLabel) {
return;
}
await this.countryOfResidenceDropdown.click();
await this.countryOfResidenceDropdown.getByRole('combobox').fill(countryLabel);
await this.page.getByTestId(`@coinmarket/form/country-select/option/${country}`).click();
await this.countryOfResidenceOption(countryCode).click();
};

selectFiatCurrency = async (currency: FiatCurrencyCode) => {
selectFiatCurrency = async (currencyCode: FiatCurrencyCode) => {
const currentCurrency = await this.youPayCurrencyDropdown.textContent();
if (currentCurrency === currency.toUpperCase()) {
if (currentCurrency === currencyCode.toUpperCase()) {
return;
}
await this.youPayCurrencyDropdown.click();
await this.youPayCurrencyOption(currency).click();
await this.youPayCurrencyOption(currencyCode).click();
};

setYouPayAmount = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { Locator, Page, expect } from '@playwright/test';

import { NetworkSymbol } from '@suite-common/wallet-config';

type WalletParams = { symbol?: NetworkSymbol; atIndex?: number };

export class WalletActions {
readonly walletMenuButton: Locator;
readonly searchInput: Locator;
readonly accountChevron: Locator;
readonly cardanoAccountLabels: { [key: string]: Locator };
readonly walletStakingButton: Locator;
readonly stakeAddress: Locator;
readonly accountMenuButton: Locator;
readonly walletExtraDropDown: Locator;
readonly coinMarketBuyButton: Locator;
readonly coinExchangeButton: Locator;
readonly coinMarketDropdownBuyButton: Locator;

constructor(private readonly page: Page) {
this.walletMenuButton = this.page.getByTestId('@suite/menu/wallet-index');
this.searchInput = this.page.getByTestId('@wallet/accounts/search-icon');
this.accountChevron = this.page.getByTestId('@account-menu/arrow');
this.cardanoAccountLabels = {
Expand All @@ -25,9 +25,9 @@ export class WalletActions {
};
this.walletStakingButton = this.page.getByTestId('@wallet/menu/staking');
this.stakeAddress = this.page.getByTestId('@cardano/staking/address');
this.accountMenuButton = this.page.getByTestId('@account-menu/btc/normal/0');
this.walletExtraDropDown = this.page.getByTestId('@wallet/menu/extra-dropdown');
this.coinMarketBuyButton = this.page.getByTestId('@wallet/menu/wallet-coinmarket-buy');
this.coinExchangeButton = this.page.getByTestId('@wallet/menu/wallet-coinmarket-exchange');
this.coinMarketDropdownBuyButton = this.page
.getByRole('list')
.getByTestId('@wallet/menu/wallet-coinmarket-buy');
Expand Down Expand Up @@ -58,8 +58,12 @@ export class WalletActions {
.count();
}

async openCoinMarket() {
await this.accountMenuButton.click();
walletMenuButton = ({ symbol = 'btc', atIndex = 0 }: WalletParams = {}): Locator => {
return this.page.getByTestId(`@account-menu/${symbol}/normal/${atIndex}`);
};

async openCoinMarket(params: WalletParams = {}) {
await this.walletMenuButton(params).click();
//TODO: #16073 We cannot set resolution for Electron. on CI button is hidden under dropdown due to a breakpoint
const isBuyButtonHidden = !(await this.coinMarketBuyButton.isVisible());
if (isBuyButtonHidden) {
Expand All @@ -69,4 +73,9 @@ export class WalletActions {
await this.coinMarketBuyButton.click();
}
}

async openExchangeMarket(params: WalletParams = {}) {
await this.walletMenuButton(params).click();
await this.coinExchangeButton.click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ test.describe('Coin market buy', { tag: ['@group=other'] }, () => {
await walletPage.openCoinMarket();
});

test('Buy crypto from compared offers', async ({ marketPage }) => {
// TOOD: #16041 Once solved, fix and uncomment, invity calls are not stable on CI
test.skip('Buy crypto from compared offers', async ({ marketPage }) => {
await test.step('Fill input amount and opens offer comparison', async () => {
await marketPage.setYouPayAmount('1234');
await expect(marketPage.layout).toHaveScreenshot('buy-coins-layout.png', {
Expand Down Expand Up @@ -43,7 +44,8 @@ test.describe('Coin market buy', { tag: ['@group=other'] }, () => {
});
});

test('Buy crypto from best offer', async ({ marketPage }) => {
// TOOD: #16041 Once solved, fix and uncomment, invity calls are not stable on CI
test.skip('Buy crypto from best offer', async ({ marketPage }) => {
await marketPage.setYouPayAmount('1234');
const { amount, provider } = await marketPage.readBestOfferValues();
await marketPage.buyBestOfferButton.click();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { test, expect } from '../../support/fixtures';

test.describe('Coinmarket Exchange', { tag: ['@group=other'] }, () => {
test.use({
emulatorStartConf: { wipe: true },
emulatorSetupConf: {
mnemonic:
'alcohol woman abuse must during monitor noble actual mixed trade anger aisle',
},
});
test.beforeEach(
async ({ onboardingPage, dashboardPage, walletPage, settingsPage, trezorUserEnvLink }) => {
await onboardingPage.completeOnboarding();
await dashboardPage.discoveryShouldFinish();
await settingsPage.navigateTo();
await settingsPage.coinsTabButton.click();
await settingsPage.enableNetwork('regtest');
await trezorUserEnvLink.sendToAddressAndMineBlock({
address: 'bcrt1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvyg6q7g5r',
btc_amount: 25,
});
await settingsPage.enableNetwork('eth');
await dashboardPage.navigateTo();
await walletPage.openExchangeMarket({ symbol: 'regtest' });
},
);

// TOOD: #16041 Once solved, fix and uncomment, We dont have enough founds to make the exchange
test.skip('Exchange flow', async ({ marketPage, page }) => {
await test.step('Wait for exchange form initialization and make visual comparison', async () => {
await expect(marketPage.bestOfferAmount).toHaveText('0 BTC');
await expect(marketPage.form).toHaveScreenshot('exchange-form.png', {
mask: [marketPage.exchangeFeeDetails],
});
});

await page
.getByTestId('@coinmarket/form/select-account/input')
.getByRole('combobox')
.fill('ETH');
await page.getByTestId('@coinmarket/form/select-account/option/ethereum').first().click();

await page.getByTestId('@coinmarket/form/crypto-input').fill('0.005');
await expect(page.getByText('Not enough funds')).toBeVisible();

// Custom fee setup
// await page.getByTestId('select-bar/custom').click();
// await page.getByTestId('feePerUnit').fill('1');
// await page.getByTestId('@coinmarket/exchange/compare-button').click();

// TOOD: #16041 Once solved, Verifies the offers displayed match the mock

// pass through initial run and device auth check
// // Gets the deal
// await page.getByTestId('@coinmarket/exchange/offers/get-this-deal-button').first().click();
// await page.getByTestId('@modal').isVisible();
// await page.getByTestId('@coinmarket/exchange/offers/buy-terms-confirm-button').click();
// // Verifies amounts, currencies and providers
// const wrapper = await page
// .locator('[class*="CoinmarketExchangeOfferInfo__Wrapper"]')
// .first();
// await expect(wrapper.locator('[class*="FormattedCryptoAmount__Value"]').first()).toHaveText(
// testData.cryptoInput,
// );
// await expect(wrapper.locator('[class*="FormattedCryptoAmount__Value"]').nth(1)).toHaveText(
// testData.ethValue,
// );
// await expect(
// wrapper.locator('[class*="FormattedCryptoAmount__Container"]').first(),
// ).toContainText('REGTEST');
// await expect(
// wrapper.locator('[class*="FormattedCryptoAmount__Container"]').last(),
// ).toContainText(testData.targetCrypto);
// await expect(wrapper.locator('[class*="CoinmarketProviderInfo__Text"]')).toHaveText(
// 'ChangeHero',
// );
// // Verifies receiving address and its title
// const addressWrapper = await page.locator('[class*="VerifyAddress__Wrapper"]').first();
// await expect(addressWrapper.locator('[class*="AccountLabeling__TabularNums"]')).toHaveText(
// 'Ethereum #1',
// );
// await expect(addressWrapper.locator('[class*="Input__StyledInput"]')).toHaveValue(
// testData.ethAddress,
// );
// // Confirming the transaction
// await page.getByTestId('@coinmarket/exchange/offers/confirm-on-trezor-button').click();
// await page.getByTestId('@prompts/confirm-on-device');
// await trezorUserEnvLink.pressYes();
// await page.getByTestId('@coinmarket/exchange/offers/continue-transaction-button').click();
// await page.getByTestId('@coinmarket/exchange/offers/confirm-on-trezor-and-send').click();
// // Verification modal opens
// await page.locator('[class*="OutputElement__OutputWrapper"]').first();
});
});
Loading

0 comments on commit c813a28

Please sign in to comment.