Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/vtx: fixing e2e tests #409

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: test cleanups
Sidharth Suresh authored and Sidharth Suresh committed Oct 27, 2022
commit 62d13abed8c38b8d842ef115b0e20229aced3b26
6 changes: 1 addition & 5 deletions tests/auth-helper.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import { memoize } from "lodash-es";
import type { OpenLoginBackendState } from "@/utils/enums";
import TorusStorageLayer from "@/utils/tkey/storageLayer";

import { getBackendDomain, getDomain, getStateDomain, wait } from "./utils";
import { getBackendDomain, getDomain, getStateDomain } from "./utils";

const ec = new EC("secp256k1");
export const EPHEMERAL_KEYPAIR = ec.genKeyPair({ entropy: "ad1238470128347018934701983470183478sfa" });
@@ -75,7 +75,6 @@ export const createRedisKey = memoize(async () => {

export async function login(context: BrowserContext, browserName: "chromium" | "webkit" | "firefox"): Promise<Page> {
await createRedisKey();

const keyFunction = `window.localStorage.setItem(
"controllerModule-ephemeral",
JSON.stringify({
@@ -142,8 +141,5 @@ export async function login(context: BrowserContext, browserName: "chromium" | "
await context.addInitScript({ content: stateFunction });
const page = await context.newPage();
await page.goto(getDomain());
// await changeLanguage(page, "english");
await wait(500);
// await page.locator("text=Account Balance").waitFor();
return page;
}
20 changes: 1 addition & 19 deletions tests/e2e/activity/activity.test.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import {
selectTransactionTypeFilter,
} from "../../activity.utils";
import { IMPORT_ACC_SECRET_KEY, login } from "../../auth-helper";
import { ensureTextualElementExists, getLastWeeksDate, getOlderDate, importAccount, switchNetwork, switchTab, wait } from "../../utils";
import { ensureTextualElementExists, getLastWeeksDate, getOlderDate, importAccount, switchNetwork, switchTab } from "../../utils";
import test, { markResult, setBrowserStackTestTitle } from "../fixtures";

test.describe("Activity Page", async () => {
@@ -34,7 +34,6 @@ test.describe("Activity Page", async () => {
test("Activities should work with network=mainnet", async () => {
// see navigation works correctly
await switchTab(page, "activity");
await wait(1000);
// getting list of activities on activity page
const activities = await getActivities(page);

@@ -49,7 +48,6 @@ test.describe("Activity Page", async () => {
// see navigation works correctly
await switchTab(page, "activity");
await switchNetwork(page, "testnet");
await wait(1000);
// getting list of activities on activity page
const activities = await getActivities(page);

@@ -64,7 +62,6 @@ test.describe("Activity Page", async () => {
// see navigation works correctly
await switchTab(page, "activity");
await switchNetwork(page, "devnet");
await wait(1000);
// getting list of activities on activity page
const activities = await getActivities(page);

@@ -80,7 +77,6 @@ test.describe("Activity Page", async () => {
await switchTab(page, "activity");
// Last 1 week filter
await selectTimeFilter(page, "Last 1 week");
await wait(1000);
// getting list of dates on activity page
let activityDates = await getDateOfActivities(page);
let elements = await activityDates.elementHandles();
@@ -96,7 +92,6 @@ test.describe("Activity Page", async () => {

// Last 1 month filter
await selectTimeFilter(page, "Last 1 month");
await wait(1000);
// getting list of dates on activity page
activityDates = await getDateOfActivities(page);
elements = await activityDates.elementHandles();
@@ -112,7 +107,6 @@ test.describe("Activity Page", async () => {

// Last 6 months filter
await selectTimeFilter(page, "Last 6 months");
await wait(1000);
// getting list of dates on activity page
activityDates = await getDateOfActivities(page);
elements = await activityDates.elementHandles();
@@ -134,7 +128,6 @@ test.describe("Activity Page", async () => {

// Send filter
await selectTransactionTypeFilter(page, "Send");
await wait(1000);
// getting list on activities
let activitiesList = await getActivities(page);
let elements = await activitiesList.elementHandles();
@@ -148,7 +141,6 @@ test.describe("Activity Page", async () => {

// Receive filter
await selectTransactionTypeFilter(page, "Receive");
await wait(1000);
// getting list on activities
activitiesList = await getActivities(page);
elements = await activitiesList.elementHandles();
@@ -162,7 +154,6 @@ test.describe("Activity Page", async () => {

// Topup filter
await selectTransactionTypeFilter(page, "Topup");
await wait(1000);
// getting list on activities
activitiesList = await getActivities(page);
elements = await activitiesList.elementHandles();
@@ -233,7 +224,6 @@ test.skip("Activity Page with Imported Account", async () => {
test("Activities should work with network=mainnet", async () => {
// see navigation works correctly
await switchTab(page, "activity");
await wait(1000);
// getting list of activities on activity page
const activities = await getActivities(page);

@@ -248,7 +238,6 @@ test.skip("Activity Page with Imported Account", async () => {
// see navigation works correctly
await switchTab(page, "activity");
await switchNetwork(page, "testnet");
await wait(1000);
// getting list of activities on activity page
const activities = await getActivities(page);

@@ -263,7 +252,6 @@ test.skip("Activity Page with Imported Account", async () => {
// see navigation works correctly
await switchTab(page, "activity");
await switchNetwork(page, "devnet");
await wait(1000);
// getting list of activities on activity page
const activities = await getActivities(page);

@@ -279,7 +267,6 @@ test.skip("Activity Page with Imported Account", async () => {
await switchTab(page, "activity");
// Last 1 week filter
await selectTimeFilter(page, "Last 1 week");
await wait(1000);
// getting list of dates on activity page
let activityDates = await getDateOfActivities(page);
let elements = await activityDates.elementHandles();
@@ -295,7 +282,6 @@ test.skip("Activity Page with Imported Account", async () => {

// Last 1 month filter
await selectTimeFilter(page, "Last 1 month");
await wait(1000);
// getting list of dates on activity page
activityDates = await getDateOfActivities(page);
elements = await activityDates.elementHandles();
@@ -311,7 +297,6 @@ test.skip("Activity Page with Imported Account", async () => {

// Last 6 months filter
await selectTimeFilter(page, "Last 6 months");
await wait(1000);
// getting list of dates on activity page
activityDates = await getDateOfActivities(page);
elements = await activityDates.elementHandles();
@@ -333,7 +318,6 @@ test.skip("Activity Page with Imported Account", async () => {

// Send filter
await selectTransactionTypeFilter(page, "Send");
await wait(1000);
// getting list on activities
let activitiesList = await getActivities(page);
let elements = await activitiesList.elementHandles();
@@ -347,7 +331,6 @@ test.skip("Activity Page with Imported Account", async () => {

// Receive filter
await selectTransactionTypeFilter(page, "Receive");
await wait(1000);
// getting list on activities
activitiesList = await getActivities(page);
elements = await activitiesList.elementHandles();
@@ -361,7 +344,6 @@ test.skip("Activity Page with Imported Account", async () => {

// Topup filter
await selectTransactionTypeFilter(page, "Topup");
await wait(1000);
// getting list on activities
activitiesList = await getActivities(page);
elements = await activitiesList.elementHandles();
9 changes: 3 additions & 6 deletions tests/e2e/home/home.test.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import test, { markResult, setBrowserStackTestTitle } from "../fixtures";

test.describe("Home Page", async () => {
let page: Page;
test.beforeAll(async ({ browser, browserName }) => {
test.beforeEach(async ({ browser, browserName }) => {
page = await login(await browser.newContext(), browserName);
});
test.afterAll(async () => {
@@ -37,7 +37,8 @@ test.describe("Home Page", async () => {
await switchTab(page, "home");

// ENSURE TopUp button click should take to topup page
await clickTopupButton(page);
// await clickTopupButton(page);
await page.click("button >> text=Top up");
await wait(1000);
await ensureTextualElementExists(page, "Select a Provider");
});
@@ -55,20 +56,17 @@ test.describe("Home Page", async () => {
test("Currency Change should work correctly", async () => {
// see navigation works correctly
await switchTab(page, "home");
await wait(1000);
// Switching to testnet as it has > 0 balance
await switchNetwork(page, "testnet");
expect(await getInnerText(page, "#selected_network")).toContain("Solana Testnet");

// ENSURE On selecting EUR as currency, conversion rate has a positive value
await selectCurrency(page, "EUR");
await wait(1000);
const eurRate = Number(await getInnerText(page, "#conversionRate"));
expect(eurRate).toBeGreaterThan(0);

// ENSURE On selecting USD as currency, conversion rate has a positive value
await selectCurrency(page, "USD");
await wait(1000);
const usdRate = Number(await getInnerText(page, "#conversionRate"));
expect(usdRate).toBeGreaterThan(0);

@@ -83,7 +81,6 @@ test.describe("Home Page", async () => {
await switchNetwork(page, "testnet");
// Ensure Tokens are displayed
await ensureTextualElementExists(page, "Tokens");
await wait(1000);
await clickTokenIfAvailable(page);
});

10 changes: 5 additions & 5 deletions tests/e2e/login/login.test.ts
Original file line number Diff line number Diff line change
@@ -12,24 +12,24 @@ test("Should Login successfully", async ({ context, browserName }) => {
const page = await login(context, browserName);

await page.click("text=Home");
await wait(1000);
await wait(500);
expect(page.url().includes("/wallet/home")).toBeTruthy();

await page.click("text=NFTs");
await wait(1000);
await wait(500);
expect(page.url().includes("/wallet/nfts")).toBeTruthy();

await page.click("text=Activity");
await wait(1000);
await wait(500);
expect(page.url().includes("/wallet/activity")).toBeTruthy();

// Click text=Settings
await page.click("text=Settings");
await wait(1000);
await wait(500);
expect(page.url().includes("/wallet/settings")).toBeTruthy();

await page.click("text=Discover");
await wait(1000);
await wait(500);
expect(page.url().includes("/wallet/discover")).toBeTruthy();
await page.close();
});
3 changes: 2 additions & 1 deletion tests/e2e/mobile-screen/mobile-screen.test.ts
Original file line number Diff line number Diff line change
@@ -28,8 +28,9 @@ test.describe("Mobile screens", async () => {
test("Should have all the tabs", async () => {
// eslint-disable-next-line no-restricted-syntax
for (const key of tabs) {
await wait(200);
await wait(1000);
expect(await page.locator(`#${key}_link`).count()).toBeGreaterThan(0);
await wait(200);
}
});

6 changes: 2 additions & 4 deletions tests/e2e/nfts/nfts.test.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ test.describe("Nfts Page", async () => {
});
test.beforeEach(async () => {
await switchTab(page, "nfts");
await wait(2000);
});

test.afterAll(() => {
@@ -27,7 +26,6 @@ test.describe("Nfts Page", async () => {
});

test("If no NFTs project eventually load popular NFTs project", async () => {
await wait(1000);
await ensureTextualElementExists(page, "You might be keen to check out some of the popular NFT projects");
expect(await page.locator(".popular-nft").count()).toBeGreaterThan(0);
});
@@ -43,10 +41,10 @@ test.describe("Nfts Page", async () => {
});

test("Click on NFT should open page with correct information, clicking on Send should take on transfer page", async () => {
test.slow();
await switchNetwork(page, "testnet");
await page.locator(".nft-item").first().click();
await wait(5000);
await page.locator(".send-nft").first().click();
await wait(1000);
await ensureTextualElementExists(page, "Transfer Details");
});
});
8 changes: 4 additions & 4 deletions tests/e2e/settings/settings.test.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import test, { markResult, setBrowserStackTestTitle } from "../fixtures";

test.describe("Settings Page", async () => {
let page: Page;
test.beforeAll(async ({ browser, browserName }) => {
test.beforeEach(async ({ browser, browserName }) => {
page = await login(await browser.newContext(), browserName);
});
test.afterAll(async () => {
@@ -47,16 +47,16 @@ test.describe("Settings Page", async () => {
test("Theme Change should work", async () => {
// // see navigation works correctly
await switchTab(page, "settings");
await wait(500);

// **************DISPLAY CHANGES********
// CHOOSE LIGHT
await page.click("text=Light");
await wait(1000);
await expect(await page.locator(".light").elementHandles()).toHaveLength(0);

await wait(500);
// CHOOSE DARK
await page.click("text=Dark");
await wait(1000);
await wait(500);
await expect(await page.locator(".dark").elementHandles()).toHaveLength(1);
});

14 changes: 3 additions & 11 deletions tests/e2e/topup/topup.test.ts
Original file line number Diff line number Diff line change
@@ -8,9 +8,8 @@ import test, { markResult, setBrowserStackTestTitle } from "../fixtures";

test.describe("Topup page", async () => {
let page: Page;
test.beforeAll(async ({ browser, browserName }) => {
test.beforeEach(async ({ browser, browserName }) => {
page = await login(await browser.newContext(), browserName);
await wait(3000);
});
test.afterAll(() => {
page.close();
@@ -22,53 +21,46 @@ test.describe("Topup page", async () => {
test("Topup Page Should render", async () => {
// // see navigation works correctly
await page.click("button:has-text('Top up')");
await wait(1000);
// ENSURE UI IS INTACT
await wait(500);
await ensureTextualElementExists(page, "Select a Provider");
});

test("Changing amount changes received value", async () => {
// // see navigation works correctly
await page.click("button:has-text('Top up')");
await wait(1000);
// MoonPay SHOULD WORK AS EXPECTED
// set amount to be transferred as 100 US Dollars, expect a positive value for expected SOL
await page.click("img[alt=moonpay]");
await page.fill("input[type='number']", "100");
await wait(2000);
const usdToSol100 = Number(await getInnerText(page, "#resCryptoAmt"));
expect(usdToSol100).toBeGreaterThan(0);

// set amount to be transferred as 200 US Dollars, expect a positive value for expected SOL
await page.fill("input[type='number']", "200");
await wait(1000);
const usdToSol200 = Number(await getInnerText(page, "#resCryptoAmt"));
await wait(2000);
expect(usdToSol200).toBeGreaterThan(usdToSol100);
});

test("Pop up page should show for top up", async () => {
// // see navigation works correctly
await page.click("button:has-text('Top up')");
await wait(1000);
// MoonPay SHOULD WORK AS EXPECTED
// set amount to be transferred as 100 US Dollars, expect a positive value for expected SOL
await page.click("img[alt=moonpay]");
await page.fill("input[type='number']", "100");
await wait(2000);

// ensure that on clicking Top up, it is redirected to MoonPay Payment page
const [page2] = await Promise.all([page.waitForEvent("popup"), page.click("button:has-text('Top up')")]);
// closing moonpay page, will show an error on top up page
page2.close();
await wait(500);
await wait(1000);
await ensureTextualElementExists(page, "Transaction could not complete.");
});

test("Changing of crypto/fiat currency changes the value you receive correctly", async () => {
// see navigation works correctly
await page.click("button:has-text('Top up')");
await wait(1000);
// change crypto currency to SOL
await switchCryptoCurrency(page, "SOL");
// change fiat currency EUR
36 changes: 27 additions & 9 deletions tests/e2e/transfer/transfer.test.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import test, { markResult, setBrowserStackTestTitle } from "../fixtures";

test.describe("Transfer page", async () => {
let page: Page;
test.beforeAll(async ({ browser, browserName }) => {
test.beforeEach(async ({ browser, browserName }) => {
page = await login(await browser.newContext(), browserName);
});
test.afterAll(async () => {
@@ -25,7 +25,7 @@ test.describe("Transfer page", async () => {
await ensureTextualElementExists(page, "Transfer Details");
});

test("Checks before transaction should be correct", async () => {
test("Prevents transaction to an invalid solana address", async () => {
// see navigation works correctly
await page.click("button:has-text('Transfer')");
await wait(1000);
@@ -35,25 +35,40 @@ test.describe("Transfer page", async () => {
await page.fill("input[type='number']", "0.01");
await page.click("button >> text=Transfer");
expect(await page.locator("text=Invalid SOL Address").elementHandles()).toHaveLength(1);
});

// using testnet as we poor on mainnet
await switchNetwork(page, "testnet");
test("Prevents sending zero value transactions", async () => {
// see navigation works correctly
await page.click("button:has-text('Transfer')");
await wait(1000);
// if address is a valid sol address, should show popup
await page.fill("input[type='text']", PUB_ADDRESS);
// if amount is not valid, should show error
await page.fill("input[type='number']", "0");
await wait(500);
await page.click("button >> text=Transfer");
await wait(1000);
expect(await page.locator("text=Must be greater than 0.0001").elementHandles()).toHaveLength(1);
// entering valid amount
});

test.skip("Check if total cost is displayed before confirming", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip?

// see navigation works correctly
await page.click("button:has-text('Transfer')");
await page.fill("input[type='text']", PUB_ADDRESS);
await page.fill("input[type='number']", "0.01");
await page.click("button >> text=Transfer");
await wait(1000);
expect(await page.locator("text=Total Cost").elementHandles()).toHaveLength(1);
await page.click("button >> text=Cancel");
});

test("Prevents empty field in the amount", async () => {
// see navigation works correctly
await page.click("button:has-text('Transfer')");
// entering no amount, empty field
await page.fill("input[type='text']", PUB_ADDRESS);
await page.fill("input[type='number']", "");
await wait(1000);
await page.click("button >> text=Transfer");
expect(await page.locator("text=Must be greater than 0.0001").elementHandles()).toHaveLength(1);
expect(await page.locator("button >> text=Transfer").isDisabled()).toBeTruthy();
});
@@ -64,17 +79,20 @@ test.describe("Transfer page", async () => {
await page.click("button:has-text('Transfer')");
await wait(1000);
const transferAmount = (Math.random() / 100).toFixed(4);
// global.console.log("amount to transfer is : ", transferAmount);

// using testnet as we poor on mainnet
await switchNetwork(page, "testnet");

// Click transfer tab
await Promise.all([page.click("text=Transfer"), wait(1000)]);
// await Promise.all([page.click("text=Transfer"), wait(1000)]);

// Fill a valid sol address
await page.fill(".combo-input-field[aria-label='Select field']", PUB_ADDRESS);
// await page.fill(".combo-input-field[aria-label='Select field']", PUB_ADDRESS);
await page.fill("input[type='text']", PUB_ADDRESS);

// Fill a unique random amount
// await page.fill("input[type='number']", transferAmount);
await page.fill("input[type='number']", transferAmount);

// Click transfer, wait for popup
@@ -216,7 +234,7 @@ test.skip("Transfer page using imported account", async () => {
await page.click("button >> text=Cancel");
});

test("Transaction should happen correctly", async () => {
test.only("Transaction should happen correctly", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually the entire tests for Transfer page using imported account is skipped at line 206.

test.slow();
// see navigation works correctly
await page.click("button:has-text('Transfer')");
3 changes: 1 addition & 2 deletions tests/home.utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Page } from "@playwright/test";
import * as dotenv from "dotenv";

import { ensureTextualElementExists, wait } from "./utils";
import { ensureTextualElementExists } from "./utils";

dotenv.config({ path: ".env.testing" });

export async function clickTokenIfAvailable(page: Page) {
const token_locator = page.locator("text=/\\s\\≈\\s/");
if ((await token_locator.count()) > 1) {
await token_locator.nth(1).click();
await wait(1000);
await ensureTextualElementExists(page, "Transfer Details");
}
}