Skip to content

Commit

Permalink
[TEST] Onboarding flow (#1081)
Browse files Browse the repository at this point in the history
* [BUG] https check sign blob (#1074) (#1075)

* uses full url to check for https on sign blob interaction

* Added translations

* remves file accidentally added by transalations hook

Co-authored-by: aristides <aristides.staffieri@stellar.org>

* adds remaining onboarding tests, cleans up fixtures

* cleans up test fixtures, removes excperimental react playwright package, removes action workflow, not ready

* ignore playwright tests in CI for now

* adds snapshot tests, cleans up debug logs

* update ignore pattern for e2e in jest target

---------

Co-authored-by: Piyal Basu <pbasu235@gmail.com>
  • Loading branch information
aristidesstaffieri and piyalbasu authored Jan 11, 2024
1 parent 57309b3 commit 826cbf2
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 5 deletions.
10 changes: 10 additions & 0 deletions extension/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/test-results/
171 changes: 171 additions & 0 deletions extension/e2e-tests/onboarding.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { shuffle } from "lodash";
import { test, expect } from "./test-fixtures";

test.beforeEach(async ({ page, extensionId }) => {
await page.goto(`chrome-extension://${extensionId}/index.html`);
});

test("Welcome page loads", async ({ page }) => {
await expect(
page.getByText("Welcome! Is this your first time using Freighter?"),
).toBeVisible();
await expect(page.getByText("I’m going to need a seed phrase")).toBeVisible();
await expect(page.getByText("I’ve done this before")).toBeVisible();
await expect(page).toHaveScreenshot("welcome-page.png");
});

test("Create new wallet", async ({ page }) => {
await expect(page).toHaveScreenshot("welcome-page.png");
await page.getByText("Create Wallet").click();
await expect(page.getByText("Create a password")).toBeVisible();

await page.locator("#new-password-input").fill("My-password123");
await page.locator("#confirm-password-input").fill("My-password123");
await page.locator("#termsOfUse-input").check({ force: true });
await page.getByText("Confirm").click();

await expect(page.getByText("Secret Recovery phrase")).toBeVisible();
await expect(page).toHaveScreenshot("recovery-page.png", {
mask: [page.locator(".MnemonicDisplay__list-item")],
});

const domWords = page.getByTestId("word");
const wordCount = await domWords.count();
const words = [] as string[];
for (let i = 0; i < wordCount; i++) {
const word = await domWords.nth(i).innerText();
words.push(word);
}

await page.getByTestId("display-mnemonic-phrase-next-btn").click();
await expect(page.getByText("Confirm your recovery phrase")).toBeVisible();

await expect(page).toHaveScreenshot("confirm-recovery-page.png", {
mask: [page.locator(".ConfirmMnemonicPhrase__word-bubble-wrapper")],
});

for (let i = 0; i < words.length; i++) {
await page.getByTestId(words[i]).check();
}
await page.getByTestId("display-mnemonic-phrase-confirm-btn").click();
await expect(
page.getByText("Your Freighter install is complete"),
).toBeVisible();
await expect(page).toHaveScreenshot("wallet-create-complete-page.png");
});

test("Import wallet", async ({ page }) => {
await expect(page).toHaveScreenshot("welcome-page.png");
await page.getByText("Import Wallet").click();
await expect(
page.getByText("Import wallet from recovery phrase"),
).toBeVisible();

const TEST_WORDS = [
"have",
"style",
"milk",
"flush",
"you",
"possible",
"thrive",
"dice",
"delay",
"police",
"seminar",
"face",
];

for (let i = 1; i <= TEST_WORDS.length; i++) {
await page.locator(`#MnemonicPhrase-${i}`).fill(TEST_WORDS[i - 1]);
}

await page.locator("#password-input").fill("My-password123");
await page.locator("#confirm-password-input").fill("My-password123");
await page.locator("#termsOfUse-input").check({ force: true });
await page.getByRole("button", { name: "Import" }).click();

await expect(page.getByText("Wallet created successfully!")).toBeVisible();
await expect(page).toHaveScreenshot("wallet-import-complete-page.png");
});

test("Import wallet with wrong password", async ({ page }) => {
await expect(page).toHaveScreenshot("welcome-page.png");
await page.getByText("Import Wallet").click();
await expect(
page.getByText("Import wallet from recovery phrase"),
).toBeVisible();

const TEST_WORDS = [
"have",
"style",
"milk",
"flush",
"you",
"possible",
"thrive",
"dice",
"delay",
"police",
"seminar",
"face",
];

for (let i = 1; i <= TEST_WORDS.length; i++) {
await page.locator(`#MnemonicPhrase-${i}`).fill(TEST_WORDS[i - 1]);
}

await page.locator("#password-input").fill("My-password123");
await page.locator("#confirm-password-input").fill("Not-my-password123");
await page.locator("#termsOfUse-input").focus();

await expect(page.getByText("Passwords must match")).toBeVisible();
await expect(page).toHaveScreenshot("recovery-bad-password.png", {
mask: [
page.locator(".RecoverAccount__mnemonic-input"),
page.locator("#password-input"),
page.locator("#confirm-password-input"),
],
});
});

test("Incorrect mnemonic phrase", async ({ page }) => {
await expect(page).toHaveScreenshot("welcome-page.png");
await page.getByText("Create Wallet").click();
await expect(page.getByText("Create a password")).toBeVisible();

await page.locator("#new-password-input").fill("My-password123");
await page.locator("#confirm-password-input").fill("My-password123");
await page.locator("#termsOfUse-input").check({ force: true });
await page.getByText("Confirm").click();

await expect(page.getByText("Secret Recovery phrase")).toBeVisible();
await expect(page).toHaveScreenshot("recovery-page.png", {
mask: [page.locator(".MnemonicDisplay__list-item")],
});

const domWords = page.getByTestId("word");
const wordCount = await domWords.count();
const words = [] as string[];
for (let i = 0; i < wordCount; i++) {
const word = await domWords.nth(i).innerText();
words.push(word);
}

await page.getByTestId("display-mnemonic-phrase-next-btn").click();
await expect(page.getByText("Confirm your recovery phrase")).toBeVisible();

const shuffledWords = shuffle(words);

for (let i = 0; i < shuffledWords.length; i++) {
await page.getByTestId(shuffledWords[i]).check();
}

await page.getByTestId("display-mnemonic-phrase-confirm-btn").click();
await expect(
page.getByText("The secret phrase you entered is incorrect."),
).toBeVisible();
await expect(page).toHaveScreenshot("incorrect-recovery-phrase-page.png", {
mask: [page.locator(".ConfirmMnemonicPhrase__word-bubble-wrapper")],
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions extension/e2e-tests/test-fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { test as base, chromium, BrowserContext } from "@playwright/test";
import path from "path";

export const test = base.extend<{
context: BrowserContext;
extensionId: string;
}>({
context: async ({}, use) => {
const pathToExtension = path.join(__dirname, "../build");
const context = await chromium.launchPersistentContext("", {
headless: false,
args: [
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
],
});
await use(context);
await context.close();
},
extensionId: async ({ context }, use) => {
// for manifest v2:
let [background] = context.backgroundPages();
if (!background) background = await context.waitForEvent("backgroundpage");

// for manifest v3:
// let [background] = context.serviceWorkers();
// if (!background)
// background = await context.waitForEvent('serviceworker');

const extensionId = background.url().split("/")[2];
await use(extensionId);
},
});
export const expect = test.expect;
4 changes: 3 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"build:translations": "yarn build --env TRANSLATIONS=true",
"start": "webpack-dev-server --config webpack.dev.js",
"start:experimental": "yarn start --env EXPERIMENTAL=true",
"start:unpacked-extension": "yarn build --watch"
"start:unpacked-extension": "yarn build --watch",
"test": "playwright test"
},
"dependencies": {
"@ledgerhq/hw-app-str": "^6.27.1",
Expand Down Expand Up @@ -84,6 +85,7 @@
},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.3.1",
"@playwright/test": "^1.40.1",
"@types/semver": "^7.5.2",
"https-browserify": "^1.0.0",
"os-browserify": "^0.3.0",
Expand Down
72 changes: 72 additions & 0 deletions extension/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./e2e-tests",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "list",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
12 changes: 12 additions & 0 deletions extension/playwright/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Testing Page</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./index.tsx"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions extension/playwright/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Import styles, initialize component theme here.
// import '../src/common.css';
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const CheckButton = ({ onChange, wordKey, word }: CheckButtonProps) => (
key={wordKey}
text={word}
/>
<label className="ButtonLabel" htmlFor={wordKey}>
<label className="ButtonLabel" htmlFor={wordKey} data-testid={word}>
{word}
</label>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export const generateMnemonicPhraseDisplay = ({
</span>

<span>
<strong>{word}</strong>
<strong data-testid="word">{word}</strong>
</span>
</>
) : (
<>
<span>
<strong>{word}</strong>
<strong data-testid="word">{word}</strong>
</span>
<span className="MnemonicDisplay__random-word">
<strong>{randomWord}</strong>
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const jsdomTests = {
moduleFileExtensions: ["js", "jsx", "json", "node", "mjs", "ts", "tsx"],
moduleDirectories: ["node_modules", "<rootDir>/extension/src", "<rootDir>/."],
testEnvironment: "jsdom",
modulePathIgnorePatterns: ["extension/e2e-tests"],
};

module.exports = {
Expand Down
Loading

0 comments on commit 826cbf2

Please sign in to comment.