From 097e1e862a99d53609c968514893b261c9d79d39 Mon Sep 17 00:00:00 2001 From: alter-eggo Date: Fri, 8 Sep 2023 09:50:29 +0400 Subject: [PATCH 1/4] refactor: fund test migrate, closes #4187 --- tests-legacy/integration/fund/fund.spec.ts | 46 ---------------------- tests-legacy/mocks/index.ts | 3 -- tests-legacy/page-objects/fund.page.ts | 41 ------------------- tests/page-object-models/home.page.ts | 6 +++ tests/selectors/fund.selectors.ts | 5 +++ tests/selectors/home.selectors.ts | 1 + tests/specs/fund/fund.spec.ts | 26 ++++++++++++ 7 files changed, 38 insertions(+), 90 deletions(-) delete mode 100644 tests-legacy/integration/fund/fund.spec.ts delete mode 100644 tests-legacy/page-objects/fund.page.ts create mode 100644 tests/selectors/fund.selectors.ts create mode 100644 tests/specs/fund/fund.spec.ts diff --git a/tests-legacy/integration/fund/fund.spec.ts b/tests-legacy/integration/fund/fund.spec.ts deleted file mode 100644 index 7a1e54e5864..00000000000 --- a/tests-legacy/integration/fund/fund.spec.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { SECRET_KEY_2 } from '@tests-legacy/mocks'; -import { FundPage } from '@tests-legacy/page-objects/fund.page'; - -import { RouteUrls } from '@shared/route-urls'; - -import { WalletPage } from '../../page-objects/wallet.page'; -import { BrowserDriver, setupBrowser } from '../utils'; - -jest.setTimeout(60_0000); -jest.retryTimes(process.env.CI ? 2 : 0); - -describe('Buy tokens test', () => { - const BEFORE_EACH_TIMEOUT = 600000; - - let browser: BrowserDriver; - let walletPage: WalletPage; - let fundPage: FundPage; - - beforeEach(async () => { - browser = await setupBrowser(); - walletPage = await WalletPage.init(browser, RouteUrls.Onboarding); - await walletPage.signIn(SECRET_KEY_2); - await walletPage.goToFundPage(); - fundPage = new FundPage(walletPage.page); - }, BEFORE_EACH_TIMEOUT); - - afterEach(async () => { - try { - await browser.context.close(); - } catch (error) {} - }); - - describe.skip('Fiat provider', () => { - it('should redirect to provider URL', async () => { - await fundPage.waitForFiatProviderItem(); - const providerName = await fundPage.getFirstFastCheckoutProviderName(); - await fundPage.clickFirstFastCheckoutProviderItem(); - await fundPage.page.waitForTimeout(2000); - const allPages = await WalletPage.getAllPages(browser); - const recentPage = allPages.pop(); - await recentPage?.waitForLoadState(); - const URL = recentPage?.url(); - expect(URL).toContain(providerName); - }); - }); -}); diff --git a/tests-legacy/mocks/index.ts b/tests-legacy/mocks/index.ts index f8a23242c16..e9d0c0359f4 100644 --- a/tests-legacy/mocks/index.ts +++ b/tests-legacy/mocks/index.ts @@ -61,6 +61,3 @@ export const STX_TRANSFER_DECODED = { txType: 'token_transfer', appDetails: { name: 'Testing App', icon: '/assets/messenger-app-icon.png' }, } as const; - -export const SECRET_KEY_2 = - 'derive plug aerobic cook until crucial school fine cushion panda ready crew photo typical nuclear ride steel indicate cupboard potato ignore bamboo script galaxy'; diff --git a/tests-legacy/page-objects/fund.page.ts b/tests-legacy/page-objects/fund.page.ts deleted file mode 100644 index e7b8a75951b..00000000000 --- a/tests-legacy/page-objects/fund.page.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Page } from '@playwright/test'; -import { FundPageSelectors } from '@tests-legacy/page-objects/fund.selectors'; - -import { createTestSelector } from '../integration/utils'; - -const selectors = { - $fiatProviderItem: createTestSelector(FundPageSelectors.FiatProviderItem), - $fiatProviderName: createTestSelector(FundPageSelectors.FiatProviderName), -}; - -export class FundPage { - selectors = selectors; - page: Page; - - constructor(page: Page) { - this.page = page; - } - - async select(selector: keyof typeof selectors) { - return this.page.$(selectors[selector]); - } - - getSelector(selector: keyof typeof selectors) { - return this.selectors[selector]; - } - - async waitForFiatProviderItem() { - await this.page.waitForSelector(this.selectors.$fiatProviderItem); - } - - async clickFirstFastCheckoutProviderItem() { - const providers = await this.page.$$(this.selectors.$fiatProviderItem); - await providers[0].click(); - } - - async getFirstFastCheckoutProviderName() { - const providerNames = await this.page.$$(this.selectors.$fiatProviderName); - const firstFastCheckoutProviderName = providerNames[0].innerText(); - return firstFastCheckoutProviderName; - } -} diff --git a/tests/page-object-models/home.page.ts b/tests/page-object-models/home.page.ts index b113fd92bbd..3acb73e7f4d 100644 --- a/tests/page-object-models/home.page.ts +++ b/tests/page-object-models/home.page.ts @@ -19,6 +19,7 @@ export class HomePage { readonly signOutDeleteWalletBtn: Locator; readonly signOutSettingsListItem: Locator; readonly lockSettingsListItem: Locator; + readonly fundAccountBtn: Locator; readonly testNetworkSelector: string = createTestSelector( WalletDefaultNetworkConfigurationIds.testnet @@ -43,6 +44,7 @@ export class HomePage { ); this.signOutSettingsListItem = page.getByTestId(SettingsSelectors.SignOutListItem); this.lockSettingsListItem = page.getByTestId(SettingsSelectors.LockListItem); + this.fundAccountBtn = page.getByTestId(HomePageSelectors.BtnFundAccount); } async goToReceiveModal() { @@ -120,4 +122,8 @@ export class HomePage { await this.clickSettingsButton(); await this.lockSettingsListItem.click(); } + + async goToFundPage() { + await this.fundAccountBtn.click(); + } } diff --git a/tests/selectors/fund.selectors.ts b/tests/selectors/fund.selectors.ts new file mode 100644 index 00000000000..1324e52f945 --- /dev/null +++ b/tests/selectors/fund.selectors.ts @@ -0,0 +1,5 @@ +export enum FundPageSelectors { + BtnReceiveStx = 'btn-receive-stx', + FiatProviderItem = 'fiat-provider-item', + FiatProviderName = 'fiat-provider-name', +} diff --git a/tests/selectors/home.selectors.ts b/tests/selectors/home.selectors.ts index 1990f1d139b..7f95cb1cc93 100644 --- a/tests/selectors/home.selectors.ts +++ b/tests/selectors/home.selectors.ts @@ -9,4 +9,5 @@ export enum HomePageSelectors { ActivityTabBtn = 'tab-activity', BalancesTabBtn = 'tab-balances', SwapBtn = 'swap-btn', + BtnFundAccount = 'btn-fund-account', } diff --git a/tests/specs/fund/fund.spec.ts b/tests/specs/fund/fund.spec.ts new file mode 100644 index 00000000000..301a780a60f --- /dev/null +++ b/tests/specs/fund/fund.spec.ts @@ -0,0 +1,26 @@ +import { FundPageSelectors } from '@tests/selectors/fund.selectors'; + +import { test } from '../../fixtures/fixtures'; + +test.describe('Buy tokens test', () => { + test.beforeEach(async ({ extensionId, globalPage, onboardingPage, homePage }) => { + await globalPage.setupAndUseApiCalls(extensionId); + await onboardingPage.signInWithTestAccount(extensionId); + await homePage.goToFundPage(); + }); + + test('should redirect to provider URL', async ({ page }) => { + const providerNames = await page.getByTestId(FundPageSelectors.FiatProviderName).all(); + const name = await providerNames[0].innerText(); + + const providerItems = await page.getByTestId(FundPageSelectors.FiatProviderItem).all(); + await providerItems[0].click(); + + await page.waitForTimeout(2000); + const allPages = page.context().pages(); + const recentPage = allPages.pop(); + await recentPage?.waitForLoadState(); + const URL = recentPage?.url(); + test.expect(URL).toContain(name); + }); +}); From befe8cc5bd1c790404e50a0092b64a4ef526662e Mon Sep 17 00:00:00 2001 From: alter-eggo Date: Fri, 8 Sep 2023 10:10:10 +0400 Subject: [PATCH 2/4] refactor: remove legacy settings selectors --- src/app/components/request-password.tsx | 2 +- .../current-account/current-account-name.tsx | 2 +- .../secret-key-displayer.layout.tsx | 2 +- src/app/features/theme-drawer/theme-list.tsx | 2 +- .../home/components/account-info-card.tsx | 2 +- .../components/add-network-button.tsx | 2 +- .../components/network-list-item.layout.tsx | 2 +- .../sign-out-confirm.layout.tsx | 2 +- .../integration/settings.selectors.ts | 22 ------------------- 9 files changed, 8 insertions(+), 30 deletions(-) delete mode 100644 tests-legacy/integration/settings.selectors.ts diff --git a/src/app/components/request-password.tsx b/src/app/components/request-password.tsx index 1f214c5e4c3..2b87cd60651 100644 --- a/src/app/components/request-password.tsx +++ b/src/app/components/request-password.tsx @@ -1,7 +1,7 @@ import { FormEvent, useCallback, useState } from 'react'; import { Box, Input, Stack } from '@stacks/ui'; -import { SettingsSelectors } from '@tests-legacy/integration/settings.selectors'; +import { SettingsSelectors } from '@tests/selectors/settings.selectors'; import { styled } from 'leather-styles/jsx'; import { token } from 'leather-styles/tokens'; diff --git a/src/app/features/current-account/current-account-name.tsx b/src/app/features/current-account/current-account-name.tsx index 2ae1a0e30f1..19dd33e5333 100644 --- a/src/app/features/current-account/current-account-name.tsx +++ b/src/app/features/current-account/current-account-name.tsx @@ -1,7 +1,7 @@ import { Suspense, memo } from 'react'; import { memoWithAs } from '@stacks/ui-core'; -import { SettingsSelectors } from '@tests-legacy/integration/settings.selectors'; +import { SettingsSelectors } from '@tests/selectors/settings.selectors'; import { Box, BoxProps, styled } from 'leather-styles/jsx'; import { HasChildren } from '@app/common/has-children'; diff --git a/src/app/features/secret-key-displayer/secret-key-displayer.layout.tsx b/src/app/features/secret-key-displayer/secret-key-displayer.layout.tsx index 8b39bfff276..907e9a32a15 100644 --- a/src/app/features/secret-key-displayer/secret-key-displayer.layout.tsx +++ b/src/app/features/secret-key-displayer/secret-key-displayer.layout.tsx @@ -1,6 +1,6 @@ import { useState } from 'react'; -import { SettingsSelectors } from '@tests-legacy/integration/settings.selectors'; +import { SettingsSelectors } from '@tests/selectors/settings.selectors'; import { Box, Flex, Stack, styled } from 'leather-styles/jsx'; import { LeatherButton } from '@app/components/button/button'; diff --git a/src/app/features/theme-drawer/theme-list.tsx b/src/app/features/theme-drawer/theme-list.tsx index 13c68b0eea8..8ca200d8e74 100644 --- a/src/app/features/theme-drawer/theme-list.tsx +++ b/src/app/features/theme-drawer/theme-list.tsx @@ -1,7 +1,7 @@ import { useCallback } from 'react'; import { Flex, FlexProps } from '@stacks/ui'; -import { SettingsSelectors } from '@tests-legacy/integration/settings.selectors'; +import { SettingsSelectors } from '@tests/selectors/settings.selectors'; import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; import { UserSelectedTheme, themeLabelMap, useThemeSwitcher } from '@app/common/theme-provider'; diff --git a/src/app/pages/home/components/account-info-card.tsx b/src/app/pages/home/components/account-info-card.tsx index a925b707b62..e51c8b6f4b7 100644 --- a/src/app/pages/home/components/account-info-card.tsx +++ b/src/app/pages/home/components/account-info-card.tsx @@ -1,5 +1,5 @@ import { useMediaQuery } from '@stacks/ui'; -import { SettingsSelectors } from '@tests-legacy/integration/settings.selectors'; +import { SettingsSelectors } from '@tests/selectors/settings.selectors'; import { Box, Divider, Flex, styled } from 'leather-styles/jsx'; import { useCurrentAccountDisplayName } from '@app/common/hooks/account/use-account-names'; diff --git a/src/app/pages/select-network/components/add-network-button.tsx b/src/app/pages/select-network/components/add-network-button.tsx index 1664af6f24a..9975c3a59de 100644 --- a/src/app/pages/select-network/components/add-network-button.tsx +++ b/src/app/pages/select-network/components/add-network-button.tsx @@ -1,5 +1,5 @@ import { ButtonProps } from '@stacks/ui'; -import { SettingsSelectors } from '@tests-legacy/integration/settings.selectors'; +import { SettingsSelectors } from '@tests/selectors/settings.selectors'; import { Flex } from 'leather-styles/jsx'; import { LeatherButton } from '@app/components/button/button'; diff --git a/src/app/pages/select-network/components/network-list-item.layout.tsx b/src/app/pages/select-network/components/network-list-item.layout.tsx index 4b4470a8879..3ecfd57ba7d 100644 --- a/src/app/pages/select-network/components/network-list-item.layout.tsx +++ b/src/app/pages/select-network/components/network-list-item.layout.tsx @@ -1,7 +1,7 @@ import { FiTrash2 } from 'react-icons/fi'; import { Box, BoxProps, Button, Flex, Stack } from '@stacks/ui'; -import { SettingsSelectors } from '@tests-legacy/integration/settings.selectors'; +import { SettingsSelectors } from '@tests/selectors/settings.selectors'; import { styled } from 'leather-styles/jsx'; import { token } from 'leather-styles/tokens'; diff --git a/src/app/pages/sign-out-confirm/sign-out-confirm.layout.tsx b/src/app/pages/sign-out-confirm/sign-out-confirm.layout.tsx index a44a8dc4d49..405b3045c39 100644 --- a/src/app/pages/sign-out-confirm/sign-out-confirm.layout.tsx +++ b/src/app/pages/sign-out-confirm/sign-out-confirm.layout.tsx @@ -1,5 +1,5 @@ import { Flex } from '@stacks/ui'; -import { SettingsSelectors } from '@tests-legacy/integration/settings.selectors'; +import { SettingsSelectors } from '@tests/selectors/settings.selectors'; import { useFormik } from 'formik'; import { Box, HStack, styled } from 'leather-styles/jsx'; import { token } from 'leather-styles/tokens'; diff --git a/tests-legacy/integration/settings.selectors.ts b/tests-legacy/integration/settings.selectors.ts deleted file mode 100644 index 2f06d359129..00000000000 --- a/tests-legacy/integration/settings.selectors.ts +++ /dev/null @@ -1,22 +0,0 @@ -export enum SettingsSelectors { - ToggleTheme = 'change-theme', - NetworkListItem = 'network-list-item', - MainnetNetworkItem = 'mainnet-network-item', - TestNetworkItem = 'test-network-item', - DevNetworkItem = 'dev-network-item', - ChangeNetworkAction = 'settings-change-network', - CurrentNetwork = 'current-network', - CurrentAccountDisplayName = 'current-account-display-name', - ViewSecretKeyListItem = 'settings-view-secret-key', - CopyKeyToClipboardBtn = 'copy-key-to-clipboard-btn', - SignOutListItem = 'settings-sign-out', - SignOutConfirmHasBackupCheckbox = 'sign-out-confirm-has-backup-checkbox', - SignOutConfirmPasswordDisable = 'sign-out-confirm-password-disable', - BtnSignOutReturnToHomeScreen = 'btn-sign-out-return-to-home-screen', - BtnSignOutActuallyDeleteWallet = 'btn-sign-out-actually-delete-wallet', - LockListItem = 'settings-lock', - EnterPasswordInput = 'password-input', - UnlockWalletBtn = 'unlock-wallet-btn', - BtnAddNetwork = 'btn-add-network', - ShowSecretKeyBtn = 'show-secret-key-btn', -} From 5be81b19a1cbdeb7acbbab633a142dc19d859b24 Mon Sep 17 00:00:00 2001 From: alter-eggo Date: Mon, 11 Sep 2023 10:21:10 +0400 Subject: [PATCH 3/4] refactor: remove legacy fund selectors --- src/app/pages/fund/components/fiat-provider-item.tsx | 2 +- src/app/pages/fund/components/fund-account-tile.tsx | 2 +- src/app/pages/fund/components/receive-stx-item.tsx | 2 +- src/app/pages/home/components/account-actions.tsx | 3 +-- tests-legacy/integration/onboarding/onboarding.spec.ts | 3 ++- tests-legacy/page-objects/fund.selectors.ts | 5 ----- tests/page-object-models/home.page.ts | 2 +- tests/selectors/home.selectors.ts | 2 +- 8 files changed, 8 insertions(+), 13 deletions(-) delete mode 100644 tests-legacy/page-objects/fund.selectors.ts diff --git a/src/app/pages/fund/components/fiat-provider-item.tsx b/src/app/pages/fund/components/fiat-provider-item.tsx index ac95a21414a..b94bdc268a6 100644 --- a/src/app/pages/fund/components/fiat-provider-item.tsx +++ b/src/app/pages/fund/components/fiat-provider-item.tsx @@ -1,4 +1,4 @@ -import { FundPageSelectors } from '@tests-legacy/page-objects/fund.selectors'; +import { FundPageSelectors } from '@tests/selectors/fund.selectors'; import { AvailableRegions } from '@app/query/common/remote-config/remote-config.query'; diff --git a/src/app/pages/fund/components/fund-account-tile.tsx b/src/app/pages/fund/components/fund-account-tile.tsx index 79621af6c01..2d49d48f534 100644 --- a/src/app/pages/fund/components/fund-account-tile.tsx +++ b/src/app/pages/fund/components/fund-account-tile.tsx @@ -1,5 +1,5 @@ import { Box, Stack, color, transition } from '@stacks/ui'; -import { FundPageSelectors } from '@tests-legacy/page-objects/fund.selectors'; +import { FundPageSelectors } from '@tests/selectors/fund.selectors'; import { styled } from 'leather-styles/jsx'; import { token } from 'leather-styles/tokens'; diff --git a/src/app/pages/fund/components/receive-stx-item.tsx b/src/app/pages/fund/components/receive-stx-item.tsx index 3bb3f130c3d..a815ad93173 100644 --- a/src/app/pages/fund/components/receive-stx-item.tsx +++ b/src/app/pages/fund/components/receive-stx-item.tsx @@ -2,7 +2,7 @@ import QRCodeIcon from '@assets/images/fund/qr-code-icon.png'; import ReceiveStxEllipses from '@assets/images/fund/receive-stx-ellipses.png'; import StacksIcon from '@assets/images/fund/stacks-icon.png'; import { Box } from '@stacks/ui'; -import { FundPageSelectors } from '@tests-legacy/page-objects/fund.selectors'; +import { FundPageSelectors } from '@tests/selectors/fund.selectors'; import { FundAccountTile } from './fund-account-tile'; diff --git a/src/app/pages/home/components/account-actions.tsx b/src/app/pages/home/components/account-actions.tsx index 6f836368985..0cc727a5428 100644 --- a/src/app/pages/home/components/account-actions.tsx +++ b/src/app/pages/home/components/account-actions.tsx @@ -1,6 +1,5 @@ import { useNavigate } from 'react-router-dom'; -import { HomePageSelectorsLegacy } from '@tests-legacy/page-objects/home.selectors'; import { HomePageSelectors } from '@tests/selectors/home.selectors'; import { Flex, FlexProps } from 'leather-styles/jsx'; @@ -30,7 +29,7 @@ export function AccountActions(props: FlexProps) { onClick={() => navigate(isBitcoinEnabled ? RouteUrls.Receive : RouteUrls.ReceiveStx)} /> } label="Buy" onClick={() => navigate(RouteUrls.Fund)} diff --git a/tests-legacy/integration/onboarding/onboarding.spec.ts b/tests-legacy/integration/onboarding/onboarding.spec.ts index 3c69df2f15b..44f9606b3c4 100644 --- a/tests-legacy/integration/onboarding/onboarding.spec.ts +++ b/tests-legacy/integration/onboarding/onboarding.spec.ts @@ -1,8 +1,9 @@ +import { SettingsSelectors } from '@tests/selectors/settings.selectors'; + import { RouteUrls } from '@shared/route-urls'; import { SECRET_KEY } from '../../mocks'; import { WalletPage } from '../../page-objects/wallet.page'; -import { SettingsSelectors } from '../settings.selectors'; import { BrowserDriver, createTestSelector, setupBrowser } from '../utils'; jest.setTimeout(30_000); diff --git a/tests-legacy/page-objects/fund.selectors.ts b/tests-legacy/page-objects/fund.selectors.ts deleted file mode 100644 index 1324e52f945..00000000000 --- a/tests-legacy/page-objects/fund.selectors.ts +++ /dev/null @@ -1,5 +0,0 @@ -export enum FundPageSelectors { - BtnReceiveStx = 'btn-receive-stx', - FiatProviderItem = 'fiat-provider-item', - FiatProviderName = 'fiat-provider-name', -} diff --git a/tests/page-object-models/home.page.ts b/tests/page-object-models/home.page.ts index 3acb73e7f4d..14fe6aa6c4e 100644 --- a/tests/page-object-models/home.page.ts +++ b/tests/page-object-models/home.page.ts @@ -44,7 +44,7 @@ export class HomePage { ); this.signOutSettingsListItem = page.getByTestId(SettingsSelectors.SignOutListItem); this.lockSettingsListItem = page.getByTestId(SettingsSelectors.LockListItem); - this.fundAccountBtn = page.getByTestId(HomePageSelectors.BtnFundAccount); + this.fundAccountBtn = page.getByTestId(HomePageSelectors.FundAccountBtn); } async goToReceiveModal() { diff --git a/tests/selectors/home.selectors.ts b/tests/selectors/home.selectors.ts index 7f95cb1cc93..f82a2f1d5a5 100644 --- a/tests/selectors/home.selectors.ts +++ b/tests/selectors/home.selectors.ts @@ -9,5 +9,5 @@ export enum HomePageSelectors { ActivityTabBtn = 'tab-activity', BalancesTabBtn = 'tab-balances', SwapBtn = 'swap-btn', - BtnFundAccount = 'btn-fund-account', + FundAccountBtn = 'fund-account-btn', } From 1a1e657facc0fd910e184e8ccc7d552b2f3c6ab4 Mon Sep 17 00:00:00 2001 From: alter-eggo Date: Mon, 11 Sep 2023 12:10:42 +0400 Subject: [PATCH 4/4] fix: fix fund test try --- src/app/query/common/remote-config/remote-config.query.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/query/common/remote-config/remote-config.query.ts b/src/app/query/common/remote-config/remote-config.query.ts index 15cba859cd7..4c22148d04b 100644 --- a/src/app/query/common/remote-config/remote-config.query.ts +++ b/src/app/query/common/remote-config/remote-config.query.ts @@ -5,6 +5,7 @@ import { GITHUB_ORG, GITHUB_REPO } from '@shared/constants'; import { BRANCH_NAME, IS_DEV_ENV, + IS_TEST_ENV, LEDGER_BITCOIN_ENABLED, WALLET_ENVIRONMENT, } from '@shared/environment'; @@ -73,7 +74,8 @@ const githubWalletConfigRawUrl = `https://raw.githubusercontent.com/${GITHUB_ORG }/config/wallet-config.json`; async function fetchHiroMessages(): Promise { - if (!BRANCH_NAME && WALLET_ENVIRONMENT !== 'production') return localConfig as RemoteConfig; + if ((!BRANCH_NAME && WALLET_ENVIRONMENT !== 'production') || IS_TEST_ENV) + return localConfig as RemoteConfig; return fetch(githubWalletConfigRawUrl).then(msg => msg.json()); }