Skip to content

Commit

Permalink
chore: updating liveapp-sdk spec to smoke
Browse files Browse the repository at this point in the history
  • Loading branch information
ggilchrist-ledger committed Jul 12, 2023
1 parent 361b675 commit c55fb50
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 46 deletions.
8 changes: 6 additions & 2 deletions apps/ledger-live-desktop/tests/models/LiveAppWebview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Page, Locator } from "@playwright/test";
import { WebviewTag } from "../../src/renderer/components/Web3AppWebview/types";
import { waitFor } from "../utils/waitFor";
import { getLiveAppManifest, startDummyServer } from "@ledgerhq/test-utils";
import { getLiveAppManifest, startDummyServer, stopDummyServer } from "@ledgerhq/test-utils";
import { AppManifest } from "@ledgerhq/live-common/wallet-api/types";

export class LiveAppWebview {
Expand Down Expand Up @@ -56,7 +56,6 @@ export class LiveAppWebview {

const localManifests = JSON.stringify(getLiveAppManifest({ ...liveAppManifest, url: url }));
process.env.MOCK_REMOTE_LIVE_MANIFEST = localManifests;
console.log("mock manifest:", process.env.MOCK_REMOTE_LIVE_MANIFEST);
return true;
} else {
throw new Error("Ping response != 200, got: " + response.status);
Expand All @@ -68,6 +67,11 @@ export class LiveAppWebview {
}
}

static async stopLiveApp() {
await stopDummyServer();
delete process.env.MOCK_REMOTE_LIVE_MANIFEST;
}

async getLiveAppTitle() {
return await this.liveAppTitle.textContent();
}
Expand Down
20 changes: 9 additions & 11 deletions apps/ledger-live-desktop/tests/specs/services/buy.smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ test.use({
},
});

let continueTest = false;
let testServerIsRunning = false;

test.beforeAll(async () => {
// Check that dummy app in tests/utils/dummy-app-build has been started successfully
continueTest = await LiveAppWebview.startLiveApp("dummy-ptx-app/public", {
// Check that dummy app in libs/test-utils/dummy-ptx-app has been started successfully
testServerIsRunning = await LiveAppWebview.startLiveApp("dummy-ptx-app/public", {
name: "Buy App",
id: "multibuy",
permissions: [
Expand All @@ -38,20 +38,19 @@ test.beforeAll(async () => {
],
});

if (!continueTest) {
if (!testServerIsRunning) {
console.warn("Stopping Buy/Sell test setup");
return; // need to make this a proper ignore/jest warning
return;
}
});

test.afterAll(async () => {
await stopDummyServer();
delete process.env.MOCK_REMOTE_LIVE_MANIFEST;
await LiveAppWebview.stopLiveApp();
});

test("Buy / Sell", async ({ page }) => {
// Don't run test if server is not running
if (!continueTest) return;
if (!testServerIsRunning) return;

const layout = new Layout(page);
const portfolioPage = new PortfolioPage(page);
Expand All @@ -63,10 +62,9 @@ test("Buy / Sell", async ({ page }) => {
const marketPage = new MarketPage(page);

await test.step("Navigate to Buy app from portfolio banner", async () => {
await page.pause();
await portfolioPage.startBuyFlow();
// await expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
// await expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
await expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
await expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
await expect.soft(page).toHaveScreenshot("buy-app-opened.png");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Analytics } from "../../models/Analytics";
import { Drawer } from "../../models/Drawer";
import { Modal } from "../../models/Modal";
import { PortfolioPage } from "../../models/PortfolioPage";
import { DiscoverPage } from "../../models/DiscoverPage";
import { LiveAppWebview } from "../../models/LiveAppWebview";
import { MarketPage } from "../../models/MarketPage";
import { Layout } from "../../models/Layout";
import { MarketCoinPage } from "../../models/MarketCoinPage";
Expand Down Expand Up @@ -69,7 +69,7 @@ test("Ethereum staking flows via portfolio, asset page and market page", async (
const portfolioPage = new PortfolioPage(page);
const drawer = new Drawer(page);
const modal = new Modal(page);
const liveApp = new DiscoverPage(page);
const liveAppWebview = new LiveAppWebview(page);
const assetPage = new AssetPage(page);
const accountsPage = new AccountsPage(page);
const accountPage = new AccountPage(page);
Expand Down Expand Up @@ -116,9 +116,9 @@ test("Ethereum staking flows via portfolio, asset page and market page", async (
});
await modal.chooseStakeProvider("kiln");
await analyticsPromise;
await liveApp.waitForCorrectTextInWebview("Ethereum 2");
const dappURL = await liveApp.getLiveAppDappURL();
await expect(await liveApp.getLiveAppTitle()).toBe("Kiln");
await liveAppWebview.waitForCorrectTextInWebview("Ethereum 2");
const dappURL = await liveAppWebview.getLiveAppDappURL();
await expect(await liveAppWebview.getLiveAppTitle()).toBe("Kiln");
expect(dappURL).toContain("?focus=dedicated");
await expect.soft(page).toHaveScreenshot("stake-provider-dapp-has-opened.png", {
mask: [page.locator("webview")],
Expand Down Expand Up @@ -184,9 +184,9 @@ test("Ethereum staking flows via portfolio, asset page and market page", async (
});
await modal.chooseStakeProvider("kiln_pooling");
await analyticsPromise;
const dappURL = await liveApp.getLiveAppDappURL();
await liveApp.waitForCorrectTextInWebview("Ethereum 1");
const dappURL = await liveAppWebview.getLiveAppDappURL();
await liveAppWebview.waitForCorrectTextInWebview("Ethereum 1");
expect(dappURL).toContain("?focus=pooled");
await expect(await liveApp.getLiveAppTitle()).toBe("Kiln");
await expect(await liveAppWebview.getLiveAppTitle()).toBe("Kiln");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,33 @@ import { Layout } from "../../models/Layout";
import { Drawer } from "../../models/Drawer";
import { Modal } from "../../models/Modal";
import { DeviceAction } from "../../models/DeviceAction";
import { stopDummyServer } from "@ledgerhq/test-utils";
import { LiveAppWebview } from "../../models/LiveAppWebview";

test.use({ userdata: "1AccountBTC1AccountETH" });

let continueTest = false;
let testServerIsRunning = false;

test.beforeAll(async () => {
// Check that dummy app in tests/utils/dummy-app-build has been started successfully
continueTest = await LiveAppWebview.startLiveApp("dummy-live-app/build", {
// Check that dummy app in libs/test-utils/dummy-live-app has been started successfully
testServerIsRunning = await LiveAppWebview.startLiveApp("dummy-live-app/build", {
name: "Dummy Live App",
id: "dummy-live-app",
permissions: [{ method: "*" }],
});

if (!continueTest) {
if (!testServerIsRunning) {
console.warn("Stopping Buy/Sell test setup");
return; // need to make this a proper ignore/jest warning
return;
}
});

test.afterAll(async () => {
await stopDummyServer();
delete process.env.MOCK_REMOTE_LIVE_MANIFEST;
await LiveAppWebview.stopLiveApp();
});

// Due to flakiness on different OS's and CI, we won't run the screenshots where unncessary for testing
test("Discover", async ({ page }) => {
test("Live App SDK methods", async ({ page }) => {
// Don't run test if server is not running
if (!continueTest) return;
if (!testServerIsRunning) return;

const discoverPage = new DiscoverPage(page);
const liveAppWebview = new LiveAppWebview(page);
Expand Down
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.
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,44 @@ import { Layout } from "../../models/Layout";
import { Drawer } from "../../models/Drawer";
import { Modal } from "../../models/Modal";
import { DeviceAction } from "../../models/DeviceAction";
import { stopDummyServer } from "@ledgerhq/test-utils";
import { randomUUID } from "crypto";
import { LiveAppWebview } from "../../models/LiveAppWebview";

test.use({ userdata: "1AccountBTC1AccountETH" });

let liveAppWebview;
let continueTest = false;
let testServerIsRunning = false;

test.beforeAll(async ({ page }) => {
liveAppWebview = new LiveAppWebview(page);

// Check that dummy app in tests/utils/dummy-app-build has been started successfully
continueTest = await liveAppWebview.startLiveApp("dummy-wallet-app/build");
test.beforeAll(async () => {
// Check that dummy app in libs/test-utils/dummy-live-app has been started successfully
testServerIsRunning = await LiveAppWebview.startLiveApp("dummy-wallet-app/build", {
name: "Dummy Wallet API Live App",
id: "dummy-live-app",
apiVersion: "2.0.0",
content: {
shortDescription: {
en: "App to test the Wallet API",
},
description: {
en: "App to test the Wallet API with Playwright",
},
},
});

if (!continueTest) {
console.warn("Stopping Wallet API test setup");
return; // need to make this a proper ignore/jest warning
if (!testServerIsRunning) {
console.warn("Stopping Buy/Sell test setup");
return;
}
});

test.afterAll(async () => {
await stopDummyServer();
delete process.env.MOCK_REMOTE_LIVE_MANIFEST;
await LiveAppWebview.stopLiveApp();
});

test("Wallet API methods", async ({ page }) => {
if (!continueTest) return;
if (!testServerIsRunning) return;

const discoverPage = new DiscoverPage(page);
const liveAppWebview = new LiveAppWebview(page);
const drawer = new Drawer(page);
const modal = new Modal(page);
const layout = new Layout(page);
Expand Down

0 comments on commit c55fb50

Please sign in to comment.