Skip to content

Commit

Permalink
fix(e2e): Rework waiting for offer sync and disables snapshots for web
Browse files Browse the repository at this point in the history
  • Loading branch information
Vere-Grey committed Dec 22, 2024
1 parent f3770d8 commit 5c42fbd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/suite-desktop-core/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const config: PlaywrightTestConfig = {
baseURL: process.env.BASE_URL || 'http://localhost:8000/',
},
grepInvert: /@desktopOnly/,
ignoreSnapshots: true,
},
{
name: PlaywrightProjects.Desktop,
Expand All @@ -35,7 +36,6 @@ const config: PlaywrightTestConfig = {
video: 'on',
screenshot: 'on',
testIdAttribute: 'data-testid',
geolocation: { latitude: 50.11432979105013, longitude: 14.481946491687228 }, // Trezor, Prague, Czech Republic
},
reportSlowTests: null,
reporter: process.env.GITHUB_ACTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { Locator, Page, expect } from '@playwright/test';

import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link';
import { FiatCurrencyCode } from '@suite-common/suite-config';
import regional from '@trezor/suite/src/constants/wallet/coinmarket/regional';

const getCountryLabel = (country: string) => {
const labelWithFlag = regional.countriesMap.get(country);
if (!labelWithFlag) {
throw new Error(`Country ${country} not found in the countries map`);
}

return labelWithFlag.substring(labelWithFlag.indexOf(' ') + 1);
};

export class MarketActions {
readonly offerSpinner: Locator;
Expand All @@ -14,6 +24,7 @@ export class MarketActions {
readonly youPayCurrencyDropdown: Locator;
readonly youPayCurrencyOption = (currency: FiatCurrencyCode) =>
this.page.getByTestId(`@coinmarket/form/fiat-currency-select/option/${currency}`);
readonly countryOfResidenceDropdown: Locator;
readonly buyOffersPage: Locator;
readonly compareButton: Locator;
readonly quotes: Locator;
Expand Down Expand Up @@ -42,6 +53,9 @@ export class MarketActions {
this.youPayCurrencyDropdown = this.page.getByTestId(
'@coinmarket/form/fiat-currency-select/input',
);
this.countryOfResidenceDropdown = this.page.getByTestId(
'@coinmarket/form/country-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 Down Expand Up @@ -69,8 +83,21 @@ export class MarketActions {
}

waitForOffersSyncToFinish = async () => {
await expect(this.offerSpinner).toBeVisible();
await expect(this.offerSpinner).toBeHidden({ timeout: 30000 });
//Even though the offer sync is finished, the best offer might not be displayed correctly yet and show 0 BTC
await expect(this.bestOfferAmount).not.toHaveText('0 BTC');
await expect(this.buyBestOfferButton).toBeEnabled();
};

selectCountryOfResidence = async (country: string) => {
const countryLabel = getCountryLabel(country);
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();
};

selectFiatCurrency = async (currency: FiatCurrencyCode) => {
Expand All @@ -82,10 +109,14 @@ export class MarketActions {
await this.youPayCurrencyOption(currency).click();
};

setYouPayAmount = async (amount: string, currency: FiatCurrencyCode) => {
setYouPayAmount = async (
amount: string,
currency: FiatCurrencyCode = 'czk',
country: string = 'CZ',
) => {
//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.selectCountryOfResidence(country);
await this.selectFiatCurrency(currency);
await this.youPayInput.fill(amount);
//Warning: Bug #16054, as a workaround we wait for offer sync after setting the amount
Expand All @@ -102,7 +133,6 @@ export class MarketActions {
};

readBestOfferValues = async () => {
//Even though the offer sync is finished, the best offer might not be available yet and show 0 BTC
await expect(this.bestOfferAmount).not.toHaveText('0 BTC');
const amount = await this.bestOfferAmount.textContent();
const provider = await this.bestOfferProvider.textContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.describe('Coin market buy', { tag: ['@group=other'] }, () => {

test('Buy crypto from compared offers', async ({ marketPage }) => {
await test.step('Fill input amount and opens offer comparison', async () => {
await marketPage.setYouPayAmount('1234', 'czk');
await marketPage.setYouPayAmount('1234');
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', 'czk');
await marketPage.setYouPayAmount('1234');
const { amount, provider } = await marketPage.readBestOfferValues();
await marketPage.buyBestOfferButton.click();
await marketPage.confirmTrade();
Expand Down

0 comments on commit 5c42fbd

Please sign in to comment.