Skip to content

Commit

Permalink
fix(e2e): Solve default currency issue in buy-coin.tests.ts
Browse files Browse the repository at this point in the history
improves stability of settings tests
  • Loading branch information
Vere-Grey committed Dec 21, 2024
1 parent d75965a commit 599da41
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Locator, Page, expect } from '@playwright/test';

import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link';

import { WalletActions } from './walletActions';
import { FiatCurrencyCode } from '@suite-common/suite-config';

export class MarketActions {
readonly offerSpinner: Locator;
Expand All @@ -12,6 +11,9 @@ export class MarketActions {
readonly bestOfferAmount: Locator;
readonly buyBestOfferButton: Locator;
readonly youPayInput: Locator;
readonly youPayCurrencyDropdown: Locator;
readonly youPayCurrencyOption = (currency: FiatCurrencyCode) =>
this.page.getByTestId(`@coinmarket/form/fiat-currency-select/option/${currency}`);
readonly buyOffersPage: Locator;
readonly compareButton: Locator;
readonly quotes: Locator;
Expand All @@ -37,6 +39,9 @@ export class MarketActions {
this.bestOfferAmount = this.page.getByTestId('@coinmarket/form/offer/crypto-amount');
this.buyBestOfferButton = this.page.getByTestId('@coinmarket/form/buy-button');
this.youPayInput = this.page.getByTestId('@coinmarket/form/fiat-input');
this.youPayCurrencyDropdown = this.page.getByTestId(
'@coinmarket/form/fiat-currency-select/input',
);
this.buyOffersPage = this.page.getByTestId('@coinmarket/buy-offers');
this.compareButton = this.page.getByTestId('@coinmarket/form/compare-button');
this.quotes = this.page.getByTestId('@coinmarket/offers/quote');
Expand All @@ -63,28 +68,25 @@ export class MarketActions {
);
}

openCoinMarket = async () => {
const walletPage = new WalletActions(this.page);
await walletPage.accountMenuButton.click();
//TODO: #16073 We cannot set resolution for Electron. on CI button is hidden under dropdown due to a breakpoint
const isBuyButtonHidden = !(await walletPage.coinMarketBuyButton.isVisible());
if (isBuyButtonHidden) {
await walletPage.walletExtraDropDown.click();
await walletPage.coinMarketDropdownBuyButton.click();
} else {
await walletPage.coinMarketBuyButton.click();
}
};

waitForOffersSyncToFinish = async () => {
await expect(this.offerSpinner).toBeVisible();
await expect(this.offerSpinner).toBeHidden({ timeout: 30000 });
};

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

setYouPayAmount = async (amount: string, currency: FiatCurrencyCode) => {
//Warning: the field is initialized empty and gets default value after the first offer sync
await expect(this.youPayInput).not.toHaveValue('');
await expect(this.offerSpinner).toBeHidden({ timeout: 30000 });
await this.selectFiatCurrency(currency);
await this.youPayInput.fill(amount);
//Warning: Bug #16054, as a workaround we wait for offer sync after setting the amount
await this.waitForOffersSyncToFinish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@ export class WalletActions {
.locator(`[data-testid*="@account-menu/${symbol}"][tabindex]`)
.count();
}

async openCoinMarket() {
await this.accountMenuButton.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) {
await this.walletExtraDropDown.click();
await this.coinMarketDropdownBuyButton.click();
} else {
await this.coinMarketBuyButton.click();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const regexpBtcValue = /^\d+(\.\d+)? BTC$/;

test.describe('Coin market buy', { tag: ['@group=other'] }, () => {
test.use({ emulatorStartConf: { wipe: true } });
test.beforeEach(async ({ onboardingPage, dashboardPage, marketPage }) => {
test.beforeEach(async ({ onboardingPage, dashboardPage, walletPage }) => {
await onboardingPage.completeOnboarding();
await dashboardPage.discoveryShouldFinish();
await marketPage.openCoinMarket();
await walletPage.openCoinMarket();
});

test('Buy crypto from compared offers', async ({ marketPage }) => {
await test.step('Fill input amount and opens offer comparison', async () => {
await marketPage.setYouPayAmount('1234');
await marketPage.setYouPayAmount('1234', 'czk');
await expect(marketPage.layout).toHaveScreenshot('buy-coins-layout.png', {
mask: [marketPage.bestOfferAmount, marketPage.bestOfferProvider],
});
Expand Down Expand Up @@ -44,7 +44,7 @@ test.describe('Coin market buy', { tag: ['@group=other'] }, () => {
});

test('Buy crypto from best offer', async ({ marketPage }) => {
await marketPage.setYouPayAmount('1234');
await marketPage.setYouPayAmount('1234', 'czk');
const { amount, provider } = await marketPage.readBestOfferValues();
await marketPage.buyBestOfferButton.click();
await marketPage.confirmTrade();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ test.describe.serial('T2B1 - Device settings', { tag: ['@group=settings'] }, ()
emulatorStartConf: { version: '2-latest', model: 'T2B1', wipe: true },
});

test.beforeEach(async ({ onboardingPage, settingsPage }) => {
test.beforeEach(async ({ onboardingPage, dashboardPage, settingsPage }) => {
await onboardingPage.completeOnboarding();
await dashboardPage.discoveryShouldFinish();
await settingsPage.navigateTo();
await settingsPage.deviceTabButton.click();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { test, expect } from '../../support/fixtures';

test.describe('T2T1 - Device settings', { tag: ['@group=settings'] }, () => {
test.use({ emulatorStartConf: { wipe: true, model: 'T2T1' } });
test.beforeEach(async ({ onboardingPage, settingsPage }) => {
test.beforeEach(async ({ onboardingPage, dashboardPage, settingsPage }) => {
await onboardingPage.completeOnboarding();
await dashboardPage.discoveryShouldFinish();
await settingsPage.navigateTo();
await settingsPage.deviceTabButton.click();
});
Expand Down

0 comments on commit 599da41

Please sign in to comment.