Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

test: refactor wallet e2e tests #2726

Merged
merged 10 commits into from Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -92,3 +92,10 @@ jobs:

- name: Test
run: xvfb-run --server-args="-screen 0 1920x1080x16" yarn test:e2e:ci

- name: Upload Screenshots
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: screenshots
path: screenshots/
7 changes: 5 additions & 2 deletions .testcaferc.json
@@ -1,6 +1,9 @@
{
"browsers": "electron:",
"src": "./src/domains/**/e2e/*.e2e.ts",
"disableScreenshots": true,
"selectorTimeout": 15000
"screenshots": {
"takeOnFails": true
},
"selectorTimeout": 15000,
"assertionTimeout": 15000
Copy link
Contributor

Choose a reason for hiding this comment

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

🦗

}
2 changes: 2 additions & 0 deletions jest.setup.js
Expand Up @@ -17,3 +17,5 @@ afterEach(() => {
afterAll(() => {
global.gc();
});

window.scrollTo = jest.fn();
13 changes: 13 additions & 0 deletions src/domains/wallet/e2e/common.ts
@@ -0,0 +1,13 @@
import { Selector } from "testcafe";

import { buildTranslations } from "../../../app/i18n/helpers";

const translations = buildTranslations();

export const goToWallet = async (t: any, wallet = "D8rr7B1d6TL6pf14LgMz4sKp1VBMs6YUYD") => {
await t.click(Selector("p").withText("John Doe"));
await t.expect(Selector("div").withText(translations.COMMON.WALLETS).exists).ok();

await t.click(Selector(`[data-testid=WalletCard__${wallet}]`));
await t.expect(Selector("[data-testid=WalletHeader]").exists).ok();
};
42 changes: 11 additions & 31 deletions src/domains/wallet/e2e/delete-wallet-action.e2e.ts
@@ -1,27 +1,19 @@
import { ClientFunction, Selector } from "testcafe";
import { Selector } from "testcafe";

import { buildTranslations } from "../../../app/i18n/helpers";
import { getPageURL } from "../../../utils/e2e-utils";
import { getLocation, getPageURL, scrollTo } from "../../../utils/e2e-utils";
import { goToWallet } from "./common";

fixture`Delete Wallet action`.page(getPageURL());
const translations = buildTranslations();

const getLocation = ClientFunction(() => document.location.href);
fixture`Delete Wallet action`.page(getPageURL()).beforeEach(async (t) => await goToWallet(t));

const scrollTop = ClientFunction(() => {
window.scrollTo({ top: 0 });
});
test("Should open and cancel deletion modal in wallet detail page", async (t) => {
await t.click(Selector("p").withText("John Doe"));
await t.expect(Selector("div").withText("Wallets").exists).ok();

// Navigate to wallet detail page
await t.click(Selector("[data-testid=WalletCard__D8rr7B1d6TL6pf14LgMz4sKp1VBMs6YUYD]"));
await t.expect(Selector("[data-testid=WalletHeader]").exists).ok();
await scrollTo(0);

// Click delete message in dropdown menu
await scrollTop();
await t.click(Selector('[data-testid="WalletHeader__more-button"]'));
await t.click(Selector('[data-testid="WalletHeader__more-button"] li').withText(buildTranslations().COMMON.DELETE));
await t.click(Selector('[data-testid="WalletHeader__more-button"] li').withText(translations.COMMON.DELETE));

await t.expect(Selector("[data-testid=modal__inner]").exists).ok();
await t.expect(Selector("[data-testid=DeleteResource__cancel-button]").exists).ok();
Expand All @@ -30,17 +22,11 @@ test("Should open and cancel deletion modal in wallet detail page", async (t) =>
});

test("Should open and close deletion modal in wallet detail page", async (t) => {
await t.click(Selector("p").withText("John Doe"));
await t.expect(Selector("div").withText("Wallets").exists).ok();

// Navigate to wallet detail page
await t.click(Selector("[data-testid=WalletCard__D8rr7B1d6TL6pf14LgMz4sKp1VBMs6YUYD]"));
await t.expect(Selector("[data-testid=WalletHeader]").exists).ok();
await scrollTo(0);

// Click delete message in dropdown menu
await scrollTop();
await t.click(Selector('[data-testid="WalletHeader__more-button"]'));
await t.click(Selector('[data-testid="WalletHeader__more-button"] li').withText(buildTranslations().COMMON.DELETE));
await t.click(Selector('[data-testid="WalletHeader__more-button"] li').withText(translations.COMMON.DELETE));

await t.expect(Selector("[data-testid=modal__inner]").exists).ok();
await t.expect(Selector('[data-testid="modal__close-btn"]').exists).ok();
Expand All @@ -49,17 +35,11 @@ test("Should open and close deletion modal in wallet detail page", async (t) =>
});

test("Should delete wallet from wallet details page", async (t) => {
await t.click(Selector("p").withText("John Doe"));
await t.expect(Selector("div").withText("Wallets").exists).ok();

// Navigate to wallet detail page
await t.click(Selector("[data-testid=WalletCard__D8rr7B1d6TL6pf14LgMz4sKp1VBMs6YUYD]"));
await t.expect(Selector("[data-testid=WalletHeader]").exists).ok();
await scrollTo(0);

// Click delete message in dropdown menu
await scrollTop();
await t.click(Selector('[data-testid="WalletHeader__more-button"]'));
await t.click(Selector('[data-testid="WalletHeader__more-button"] li').withText(buildTranslations().COMMON.DELETE));
await t.click(Selector('[data-testid="WalletHeader__more-button"] li').withText(translations.COMMON.DELETE));

await t.expect(Selector("[data-testid=modal__inner]").exists).ok();
await t.expect(Selector("[data-testid=DeleteResource__submit-button]").exists).ok();
Expand Down
45 changes: 13 additions & 32 deletions src/domains/wallet/e2e/sign-message-action.e2e.ts
@@ -1,28 +1,21 @@
import { ClientFunction, Selector } from "testcafe";
import { Selector } from "testcafe";

import { buildTranslations as translations } from "../../../app/i18n/helpers";
import { getPageURL } from "../../../utils/e2e-utils";
import { buildTranslations } from "../../../app/i18n/helpers";
import { getPageURL, scrollTo } from "../../../utils/e2e-utils";
import { goToWallet } from "./common";

fixture`Sign Message`.page(getPageURL());
const translations = buildTranslations();

const scrollTop = ClientFunction(() => {
window.scrollTo({ top: 0 });
});
fixture`Sign Message`.page(getPageURL()).beforeEach(async (t) => await goToWallet(t));

test("Should open and close sign message modal", async (t) => {
await t.click(Selector("p").withText("John Doe"));
await t.expect(Selector("div").withText(translations().COMMON.WALLETS).exists).ok();

// Navigate to wallet details page
await t.click(Selector("[data-testid=WalletCard__D8rr7B1d6TL6pf14LgMz4sKp1VBMs6YUYD]"));
await t.expect(Selector("[data-testid=WalletHeader]").exists).ok();
await scrollTo(0);

// Click sign message option in dropdown menu
await scrollTop();
await t.click(Selector('[data-testid="WalletHeader__more-button"]'));
await t.click(
Selector('[data-testid="WalletHeader__more-button"] li').withText(
translations().WALLETS.PAGE_WALLET_DETAILS.OPTIONS.SIGN_MESSAGE,
translations.WALLETS.PAGE_WALLET_DETAILS.OPTIONS.SIGN_MESSAGE,
),
);

Expand All @@ -33,19 +26,13 @@ test("Should open and close sign message modal", async (t) => {
});

test("Should open and cancel sign message modal", async (t) => {
await t.click(Selector("p").withText("John Doe"));
await t.expect(Selector("div").withText(translations().COMMON.WALLETS).exists).ok();

// Navigate to wallet details page
await t.click(Selector("[data-testid=WalletCard__D8rr7B1d6TL6pf14LgMz4sKp1VBMs6YUYD]"));
await t.expect(Selector("[data-testid=WalletHeader]").exists).ok();
await scrollTo(0);

// Click sign message option in dropdown menu
await scrollTop();
await t.click(Selector('[data-testid="WalletHeader__more-button"]'));
await t.click(
Selector('[data-testid="WalletHeader__more-button"] li').withText(
translations().WALLETS.PAGE_WALLET_DETAILS.OPTIONS.SIGN_MESSAGE,
translations.WALLETS.PAGE_WALLET_DETAILS.OPTIONS.SIGN_MESSAGE,
),
);

Expand All @@ -56,25 +43,19 @@ test("Should open and cancel sign message modal", async (t) => {
});

test("Should successfully sign message", async (t) => {
await t.click(Selector("p").withText("John Doe"));
await t.expect(Selector("div").withText("Wallets").exists).ok();

// Navigate to wallet details page
await t.click(Selector("[data-testid=WalletCard__D8rr7B1d6TL6pf14LgMz4sKp1VBMs6YUYD]"));
await t.expect(Selector("[data-testid=WalletHeader]").exists).ok();
await scrollTo(0);

// Click sign message option in dropdown menu
await scrollTop();
await t.click(Selector('[data-testid="WalletHeader__more-button"]'));
await t.click(
Selector('[data-testid="WalletHeader__more-button"] li').withText(
translations().WALLETS.PAGE_WALLET_DETAILS.OPTIONS.SIGN_MESSAGE,
translations.WALLETS.PAGE_WALLET_DETAILS.OPTIONS.SIGN_MESSAGE,
),
);

await t.typeText(Selector("input[name=message]"), "Hello World");
await t.typeText(Selector("input[name=mnemonic]"), "this is a top secret passphrase");
await t.click(Selector("[data-testid=SignMessage__submit-button]"));
await t.expect(Selector("h2").withText(translations().WALLETS.MODAL_SIGN_MESSAGE.SUCCESS_TITLE).exists).ok();
await t.expect(Selector("h2").withText(translations.WALLETS.MODAL_SIGN_MESSAGE.SUCCESS_TITLE).exists).ok();
await t.click(Selector("[data-testid=modal__close-btn]"));
});