Skip to content

Commit

Permalink
some of the tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed Feb 20, 2024
1 parent 40a3e79 commit 4928e9f
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 119 deletions.
28 changes: 9 additions & 19 deletions e2e/encrypt.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import { expect, test } from "@playwright/test";

import { loadHome, visitSettings } from "./utils";

test.beforeEach(async ({ page }) => {
await page.goto("http://localhost:3420/");
});

test("test local encrypt", async ({ page }) => {
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Mutiny Wallet/);

// Wait for an element matching the selector to appear in DOM.
await page.waitForSelector("text=0 SATS");

console.log("Page loaded.");

// Wait for a while just to make sure we can load everything
await page.waitForTimeout(1000);

// Navigate to settings
const settingsLink = await page.getByRole("link", { name: "Settings" });

settingsLink.click();

// Wait for settings to load
await page.waitForSelector("text=Settings");
await loadHome(page);
await visitSettings(page);

// Click the "Backup" link
await page.click("text=Backup");
Expand All @@ -48,6 +34,10 @@ test("test local encrypt", async ({ page }) => {
// Click the "I wrote down the words" button
await wroteDownButton.click();

// Go back to settings / change password
await visitSettings(page);
await page.click("text=Change Password");

// The header should now say "Encrypt your seed words"
await expect(page.locator("h1")).toContainText(["Encrypt your seed words"]);

Expand Down Expand Up @@ -86,5 +76,5 @@ test("test local encrypt", async ({ page }) => {
await page.click("text=Decrypt Wallet");

// Wait for an element matching the selector to appear in DOM.
await page.waitForSelector("text=0 SATS");
await page.locator(`text=0 sats`).first();
});
54 changes: 21 additions & 33 deletions e2e/fedimint.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect, test } from "@playwright/test";

import { loadHome, visitSettings } from "./utils";

const SIGNET_INVITE_CODE =
"fed11qgqzc2nhwden5te0vejkg6tdd9h8gepwvejkg6tdd9h8garhduhx6at5d9h8jmn9wshxxmmd9uqqzgxg6s3evnr6m9zdxr6hxkdkukexpcs3mn7mj3g5pc5dfh63l4tj6g9zk4er";

Expand All @@ -8,24 +10,8 @@ test.beforeEach(async ({ page }) => {
});

test("fedmint join, receive, send", async ({ page }) => {
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Mutiny Wallet/);

// Wait for an element matching the selector to appear in DOM.
await page.waitForSelector("text=0 SATS");

console.log("Page loaded.");

// Wait for a while just to make sure we can load everything
await page.waitForTimeout(1000);

// Navigate to settings
const settingsLink = await page.getByRole("link", { name: "Settings" });

settingsLink.click();

// Wait for settings to load
await page.waitForSelector("text=Settings");
await loadHome(page);
await visitSettings(page);

// Click "Manage Federations" link
await page.click("text=Manage Federations");
Expand All @@ -45,21 +31,27 @@ test("fedmint join, receive, send", async ({ page }) => {
await page.goBack();
await page.goBack();

// Make sure there's a fedimint icon
await expect(page.getByRole("img", { name: "community" })).toBeVisible();
// Click the top left button (it's the profile button), a child of header
// TODO: better ARIA stuff
await page.locator(`header button`).first().click();

// Click the receive button
await page.click("text=Receive");
// Make sure there's text that says "fedimint"
await page.locator("text=fedimint").first();

// Navigate back home
await page.goBack();

// Click the fab button
await page.locator("#fab").click();
// Click the receive button in the fab
await page.locator("text=Receive").last().click();

// Expect the url to conain receive
await expect(page).toHaveURL(/.*receive/);

// At least one h1 should show "0 sats"
await expect(page.locator("h1")).toContainText(["0 SATS"]);

// At least one h2 should show "0 USD"
await expect(page.locator("h2")).toContainText(["$0 USD"]);

// Type 100 into the input
await page.locator("#sats-input").pressSequentially("100");

Expand Down Expand Up @@ -114,16 +106,12 @@ test("fedmint join, receive, send", async ({ page }) => {
// Click the "Nice" button
await page.click("text=Nice");

// Make sure we have 100 sats in the fedimint balance
await expect(
page
.locator("div")
.filter({ hasText: /^100 eSATS$/ })
.nth(1)
).toBeVisible();
// Make sure we have 100 sats in the top balance
await expect(page.locator("text=100 SATS").first()).toBeVisible();

// Now we send
await page.click("text=Send");
await page.locator("#fab").click();
await page.locator("text=Send").last().click();

// type refund@lnurl-staging.mutinywallet.com
const sendInput = await page.locator("input");
Expand Down
19 changes: 4 additions & 15 deletions e2e/load.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { expect, test } from "@playwright/test";
import { test } from "@playwright/test";

import { loadHome } from "./utils";

test.beforeEach(async ({ page }) => {
await page.goto("http://localhost:3420/");
});

test("initial load", async ({ page }) => {
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Mutiny Wallet/);

await expect(page.locator("header")).toContainText(["Activity"], {
timeout: 30000
});

// Wait up to 30 seconds for an image element matching the selector to be visible
await page.waitForSelector("img[alt='lightning']", { timeout: 30000 });

// Wait for an element matching the selector to appear in DOM.
await page.waitForSelector("text=0 SATS");

console.log("Page loaded.");
await loadHome(page);
});
49 changes: 16 additions & 33 deletions e2e/restore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect, test } from "@playwright/test";

import { loadHome, visitSettings } from "./utils";

test.beforeEach(async ({ page }) => {
await page.goto("http://localhost:3420/");
});
Expand All @@ -9,34 +11,18 @@ test("restore from seed @slow", async ({ page }) => {
const TEST_SEED_WORDS =
"rival hood review write spoon tide orange ill opera enrich clip acoustic";

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Mutiny Wallet/);

// Wait for an element matching the selector to appear in DOM.
await page.waitForSelector("text=0 SATS");

console.log("Page loaded.");

// Wait for a while just to make sure we can load everything
await page.waitForTimeout(1000);

// Navigate to settings
const settingsLink = await page.getByRole("link", { name: "Settings" });

settingsLink.click();

// Wait for settings to load
await page.waitForSelector("text=Settings");
await loadHome(page);
await visitSettings(page);

// Click the "Restore" link
page.click("text=Restore");
await page.click("text=Restore");

// There should be some warning text: "This will replace your existing wallet"
await expect(page.locator("p")).toContainText([
"This will replace your existing wallet"
]);

let seedWords = TEST_SEED_WORDS.split(" ");
const seedWords = TEST_SEED_WORDS.split(" ");

// Find the input field with the name "words.0"
for (let i = 0; i < 12; i++) {
Expand All @@ -56,31 +42,28 @@ test("restore from seed @slow", async ({ page }) => {
const confirmButton = await page.locator("button", { hasText: "Confirm" });
confirmButton.click();

// Wait for the wallet to load
await page.waitForSelector("img[alt='lightning']");

// Eventually we should have a balance of 100k sats
await page.waitForSelector("text=100,000 SATS");
await page.locator("text=100,000 SATS");

// Now we should clean up after ourselves and delete the wallet
settingsLink.click();

// Wait for settings to load
await page.waitForSelector("text=Settings");
await visitSettings(page);

// Click the "Restore" link
page.click("text=Admin Page");
await page.click("text=Admin Page");

// Clicke the Delete Everything button
page.click("text=Delete Everything");
await page.click("text=Delete Everything");

// A modal should pop up, click the "Confirm" button
const confirmDeleteButton = await page.locator("button", {
hasText: "Confirm"
});
confirmDeleteButton.click();

// wait 5 seconds for no reason
await page.waitForTimeout(5000);

await confirmDeleteButton.click();

// Wait for the wallet to load
// Wait for the wallet to load
await page.waitForSelector("img[alt='lightning']");
await page.waitForSelector("text=Welcome to the Mutiny!");
});
23 changes: 4 additions & 19 deletions e2e/routes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect, Page, test } from "@playwright/test";

import { loadHome, visitSettings } from "./utils";

const routes = [
"/",
"/feedback",
Expand Down Expand Up @@ -57,29 +59,12 @@ test.beforeEach(async ({ page }) => {
});

test("visit each route", async ({ page }) => {
// Start on the home page
await expect(page).toHaveTitle(/Mutiny Wallet/);
await page.waitForSelector("text=Welcome to the Mutiny!");

// Wait for a while just to make sure we can load everything
await page.waitForTimeout(1000);

console.log("Waiting for new wallet to be created...");

await page.locator(`button:has-text('New Wallet')`).click();

await page.locator("text=Create your profile").first();

await page.locator("button:has-text('Skip for now')").click();
await loadHome(page);

checklist.set("/", true);

// Should have a balance up top now
await page.locator(`text=0 sats`).first();
await visitSettings(page);

// Find an image with an alt text of "mutiny" and click it
await page.locator("img[alt='mutiny']").first().click();
await expect(page.locator("h1").first()).toHaveText("Settings");
checklist.set("/settings", true);

// Mutiny+
Expand Down
25 changes: 25 additions & 0 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, Page } from "@playwright/test";

export async function loadHome(page: Page) {
// Start on the home page
await expect(page).toHaveTitle(/Mutiny Wallet/);
await page.waitForSelector("text=Welcome to the Mutiny!");

console.log("Waiting for new wallet to be created...");

await page.locator(`button:has-text('New Wallet')`).click();

await page.locator("text=Create your profile").first();

await page.locator("button:has-text('Skip for now')").click();

// Should have a balance up top now
await page.locator(`text=0 sats`).first();
}

export async function visitSettings(page: Page) {
// Find an image with an alt text of "mutiny" and click it
// TODO: probably should have better ARIA stuff for this
await page.locator("img[alt='mutiny']").first().click();
await expect(page.locator("h1").first()).toHaveText("Settings");
}

0 comments on commit 4928e9f

Please sign in to comment.