diff --git a/tests-legacy/integration/network/add-network.spec.ts b/tests-legacy/integration/network/add-network.spec.ts deleted file mode 100644 index 01f0612d156..00000000000 --- a/tests-legacy/integration/network/add-network.spec.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { NetworkSelectors } from '@tests-legacy/integration/network.selectors'; -import { SettingsSelectors } from '@tests-legacy/integration/settings.selectors'; -import { BrowserDriver, createTestSelector, setupBrowser } from '@tests-legacy/integration/utils'; -import { SECRET_KEY_2 } from '@tests-legacy/mocks'; -import { NetworkPage } from '@tests-legacy/page-objects/network-page'; -import { WalletPage } from '@tests-legacy/page-objects/wallet.page'; - -import { RouteUrls } from '@shared/route-urls'; - -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 networkPage: NetworkPage; - - beforeEach(async () => { - browser = await setupBrowser(); - walletPage = await WalletPage.init(browser, RouteUrls.Onboarding); - await walletPage.signIn(SECRET_KEY_2); - await walletPage.clickSettingsButton(); - await walletPage.page.click(createTestSelector(SettingsSelectors.ChangeNetworkAction)); - await walletPage.page.click(createTestSelector(SettingsSelectors.BtnAddNetwork)); - networkPage = new NetworkPage(walletPage.page); - }, BEFORE_EACH_TIMEOUT); - - afterEach(async () => { - try { - await browser.context.close(); - } catch (error) {} - }); - - describe('Add new network', () => { - it('validation error when address is empty', async () => { - await networkPage.clickAddNetwork(); - await networkPage.waitForErrorMessage(); - const errorMsgElement = await networkPage.page.$$(networkPage.getSelector('$errorText')); - const errorMessage = await errorMsgElement[0].innerText(); - expect(errorMessage).toEqual(NetworkSelectors.EmptyAddressError); - }); - - it('unable to fetch info from node', async () => { - await networkPage.inputNetworkAddressField('https://www.google.com/'); - await networkPage.inputNetworkKeyField('test-network'); - await networkPage.clickAddNetwork(); - await networkPage.waitForErrorMessage(); - const errorMsgElement = await networkPage.page.$$(networkPage.getSelector('$errorText')); - const errorMessage = await errorMsgElement[0].innerText(); - expect(errorMessage).toEqual(NetworkSelectors.NoNodeFetch); - }); - }); -}); diff --git a/tests-legacy/page-objects/network-page.ts b/tests-legacy/page-objects/network-page.ts deleted file mode 100644 index d4d01d4afe9..00000000000 --- a/tests-legacy/page-objects/network-page.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { Page } from '@playwright/test'; -import { NetworkSelectors } from '@tests-legacy/integration/network.selectors'; - -import { createTestSelector } from '../integration/utils'; - -const selectors = { - $networkName: createTestSelector(NetworkSelectors.NetworkName), - $networkAddress: createTestSelector(NetworkSelectors.NetworkAddress), - $networkKey: createTestSelector(NetworkSelectors.NetworkKey), - $btnAddNetwork: createTestSelector(NetworkSelectors.BtnAddNetwork), - $errorText: createTestSelector(NetworkSelectors.ErrorText), -}; - -export class NetworkPage { - selectors = selectors; - page: Page; - - constructor(page: Page) { - this.page = page; - } - - getSelector(selector: keyof typeof selectors) { - return this.selectors[selector]; - } - - async inputNetworkNameField(input: string) { - const field = await this.page.$(this.selectors.$networkName); - await field?.type(input); - } - - async inputNetworkAddressField(input: string) { - const field = await this.page.$(this.selectors.$networkAddress); - await field?.type(input); - } - - async inputNetworkKeyField(input: string) { - const field = await this.page.$(this.selectors.$networkKey); - await field?.type(input); - } - - async waitForErrorMessage() { - await this.page.waitForSelector(this.selectors.$errorText); - } - - async clickAddNetwork() { - await this.page.click(this.selectors.$btnAddNetwork); - } -} diff --git a/tests/fixtures/fixtures.ts b/tests/fixtures/fixtures.ts index 691e8a914ff..cb611cd684b 100644 --- a/tests/fixtures/fixtures.ts +++ b/tests/fixtures/fixtures.ts @@ -1,6 +1,7 @@ import { BrowserContext, test as base, chromium } from '@playwright/test'; import { GlobalPage } from '@tests/page-object-models/global.page'; import { HomePage } from '@tests/page-object-models/home.page'; +import { NetworkPage } from '@tests/page-object-models/network.page'; import { OnboardingPage } from '@tests/page-object-models/onboarding.page'; import { SendPage } from '@tests/page-object-models/send.page'; import { SwapPage } from '@tests/page-object-models/swap.page'; @@ -14,6 +15,7 @@ interface TestFixtures { onboardingPage: OnboardingPage; sendPage: SendPage; swapPage: SwapPage; + networkPage: NetworkPage; } /** @@ -60,4 +62,7 @@ export const test = base.extend({ swapPage: async ({ page }, use) => { await use(new SwapPage(page)); }, + networkPage: async ({ page }, use) => { + await use(new NetworkPage(page)); + }, }); diff --git a/tests/page-object-models/network.page.ts b/tests/page-object-models/network.page.ts new file mode 100644 index 00000000000..6a7f08440fb --- /dev/null +++ b/tests/page-object-models/network.page.ts @@ -0,0 +1,40 @@ +import { Page } from '@playwright/test'; +import { NetworkSelectors } from '@tests/selectors/network.selectors'; +import { createTestSelector } from '@tests/utils'; + +export class NetworkPage { + readonly networkNameSelector = createTestSelector(NetworkSelectors.NetworkName); + readonly networkAddressSelector = createTestSelector(NetworkSelectors.NetworkAddress); + readonly networkKeySelector = createTestSelector(NetworkSelectors.NetworkKey); + readonly btnAddNetworkSelector = createTestSelector(NetworkSelectors.BtnAddNetwork); + readonly errorTextSelector = createTestSelector(NetworkSelectors.ErrorText); + + constructor(readonly page: Page) {} + + async inputNetworkNameField(input: string) { + const field = this.page.locator(this.networkNameSelector); + await field?.type(input); + } + + async inputNetworkAddressField(input: string) { + const field = this.page.locator(this.networkAddressSelector); + await field?.type(input); + } + + async inputNetworkKeyField(input: string) { + const field = this.page.locator(this.networkKeySelector); + await field?.type(input); + } + + async waitForErrorMessage() { + await this.page.waitForSelector(this.errorTextSelector); + } + + async getErrorMessage() { + return this.page.locator(this.errorTextSelector); + } + + async clickAddNetwork() { + await this.page.locator(this.btnAddNetworkSelector).click(); + } +} diff --git a/tests/selectors/network.selectors.ts b/tests/selectors/network.selectors.ts new file mode 100644 index 00000000000..38aa40ca29d --- /dev/null +++ b/tests/selectors/network.selectors.ts @@ -0,0 +1,9 @@ +export enum NetworkSelectors { + NetworkName = 'network-name', + NetworkAddress = 'network-address', + NetworkKey = 'network-key', + BtnAddNetwork = 'btn-add-network', + ErrorText = 'error-text', + EmptyAddressError = 'Enter a valid URL', + NoNodeFetch = 'Unable to fetch info from node.', +} diff --git a/tests/specs/network/add-network.spec.ts b/tests/specs/network/add-network.spec.ts new file mode 100644 index 00000000000..fcb1220f579 --- /dev/null +++ b/tests/specs/network/add-network.spec.ts @@ -0,0 +1,33 @@ +import { NetworkSelectors } from '@tests/selectors/network.selectors'; +import { SettingsSelectors } from '@tests/selectors/settings.selectors'; + +import { test } from '../../fixtures/fixtures'; + +test.describe('Networks tests', () => { + test.beforeEach(async ({ extensionId, globalPage, onboardingPage, homePage, page }) => { + await globalPage.setupAndUseApiCalls(extensionId); + await onboardingPage.signInWithTestAccount(extensionId); + await homePage.clickSettingsButton(); + await page.getByTestId(SettingsSelectors.ChangeNetworkAction).click(); + await page.getByTestId(SettingsSelectors.BtnAddNetwork).click(); + }); + + test('validation error when address is empty', async ({ networkPage }) => { + await networkPage.clickAddNetwork(); + await networkPage.waitForErrorMessage(); + + const errorMsgElement = await networkPage.getErrorMessage(); + const errorMessage = await errorMsgElement.innerText(); + test.expect(errorMessage).toEqual(NetworkSelectors.EmptyAddressError); + }); + + test('unable to fetch info from node', async ({ networkPage }) => { + await networkPage.inputNetworkAddressField('https://www.google.com/'); + await networkPage.inputNetworkKeyField('test-network'); + await networkPage.clickAddNetwork(); + await networkPage.waitForErrorMessage(); + const errorMsgElement = await networkPage.getErrorMessage(); + const errorMessage = await errorMsgElement.innerText(); + test.expect(errorMessage).toEqual(NetworkSelectors.NoNodeFetch); + }); +});