Skip to content

Commit

Permalink
test: added mocked svg and new fixtures
Browse files Browse the repository at this point in the history
test(lld): update screenshots (ubuntu-latest)  lld, test, screenshot

test(lld): update screenshots (macos-latest)  lld, test, screenshot

test(lld): update screenshots (windows-latest)  lld, test, screenshot

chore: removing redundant imports

chore: removing screenshots for regeneration

test(lld): update screenshots (ubuntu-latest)  lld, test, screenshot

test(lld): update screenshots (windows-latest)  lld, test, screenshot
  • Loading branch information
ggilchrist-ledger committed Oct 12, 2023
1 parent cc14bd3 commit b7d3dc3
Show file tree
Hide file tree
Showing 82 changed files with 155 additions and 29 deletions.
3 changes: 2 additions & 1 deletion apps/ledger-live-desktop/tests/fixtures/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type TestFixtures = {

const IS_DEBUG_MODE = !!process.env.PWDEBUG;

const test = base.extend<TestFixtures>({
export const test = base.extend<TestFixtures>({
env: undefined,
lang: "en-US",
theme: "dark",
Expand Down Expand Up @@ -149,6 +149,7 @@ const test = base.extend<TestFixtures>({

console.log(`Video for test recorded at: ${await page.video()?.path()}\n`);
},

// below is used for the logging file at `artifacts/networkResponses.log`
recordTestNamesForApiResponseLogging: [
async ({}, use, testInfo) => {
Expand Down
70 changes: 70 additions & 0 deletions apps/ledger-live-desktop/tests/fixtures/mockFixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Page } from "@playwright/test";
import { test as base } from "./common";
import { getStatusMock } from "tests/specs/services/services-api-mocks/getStatus.mock";

type TestFixtures = {
mockProviderSvgs: Page;
mockFeesEndpoint: Page;
mockSwapCancelledEndpoint: Page;
mockSwapAcceptedEndpoint: Page;
mockSwapStatusEndpoint: Page;
};

export const test = base.extend<TestFixtures>({
mockProviderSvgs: async ({ page }, use) => {
await page.route("https://cdn.live.ledger.com/icons/providers/boxed/**.svg", async route => {
console.log("Mocking Provider icons");
route.fulfill({
headers: { teststatus: "mocked" },
path: "tests/mocks/dummy-provider-icon.svg",
});
});

await use(page);
},

mockFeesEndpoint: async ({ page }, use) => {
await page.route(
"https://explorers.api.live.ledger.com/blockchain/v4/btc/fees",
async route => {
console.log("Mocking Fees endpoint");
console.log("THE DATE: ", Date.now());
route.fulfill({
headers: { teststatus: "mocked" },
body: JSON.stringify({ "2": 15067, "4": 15067, "6": 15067, last_updated: Date.now() }),
});
},
);

await use(page);
},

// We mock the 'cancelled' swap response because the transaction isn't broadcast when run locally.
// If 'cancelled' is called then it's a successful test
mockSwapCancelledEndpoint: async ({ page }, use) => {
await page.route("https://swap.ledger.com/v5/swap/cancelled", async route => {
console.log("Mocking swap cancelled HTTP response");
route.fulfill({ headers: { teststatus: "mocked" }, body: "" });
});
await use(page);
},

mockSwapAcceptedEndpoint: async ({ page }, use) => {
await page.route("https://swap.ledger.com/v5/swap/accepted", async route => {
console.log("Mocking swap accepted HTTP response");
route.fulfill({ headers: { teststatus: "mocked" }, body: "" });
});
await use(page);
},

mockSwapStatusEndpoint: async ({ page }, use) => {
await page.route("https://swap.ledger.com/v5/swap/status", async route => {
console.log("Mocking swap status HTTP response");
const mockStatusResponse = getStatusMock();
route.fulfill({ headers: { teststatus: "mocked" }, body: mockStatusResponse });
});
await use(page);
},
});

export default test;
24 changes: 24 additions & 0 deletions apps/ledger-live-desktop/tests/mocks/dummy-provider-icon.svg
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.
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.
54 changes: 32 additions & 22 deletions apps/ledger-live-desktop/tests/specs/services/swap.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test from "../../fixtures/common";
/* eslint-disable @typescript-eslint/no-unused-vars */
import test from "../../fixtures/mockFixtures";
import { expect } from "@playwright/test";
import { SwapPage } from "../../models/SwapPage";
import { DeviceAction } from "../../models/DeviceAction";
Expand All @@ -12,7 +13,6 @@ import {
getBitcoinToEthereumRatesMock,
getEthereumToTetherRatesMock,
} from "./services-api-mocks/getRates.mock";
import { getStatusMock } from "./services-api-mocks/getStatus.mock";

test.use({
userdata: "1AccountBTC1AccountETH",
Expand All @@ -27,7 +27,11 @@ test.use({
// could add pause to HTTP mock to test 'LOADING' component

test.describe.parallel("Swap", () => {
test("Add accounts via Swap page @smoke", async ({ page }) => {
test("Add accounts via Swap page @smoke", async ({
page,
mockProviderSvgs,
mockFeesEndpoint,
}) => {
const layout = new Layout(page);
const accountsPage = new AccountsPage(page);
const accountPage = new AccountPage(page);
Expand Down Expand Up @@ -79,7 +83,7 @@ test.describe.parallel("Swap", () => {
});
});

test("Filter Rates @smoke", async ({ page }) => {
test("Filter Rates @smoke", async ({ page, mockProviderSvgs, mockFeesEndpoint }) => {
const swapPage = new SwapPage(page);
const layout = new Layout(page);

Expand Down Expand Up @@ -126,8 +130,14 @@ test.describe.parallel("Swap", () => {
});
});

// FIXME flaky https://ledgerhq.atlassian.net/browse/LIVE-9617
test.skip("Full Swap with Centralised Exchange @smoke", async ({ page }) => {
test("Full Swap with Centralised Exchange @smoke", async ({
page,
mockProviderSvgs,
mockFeesEndpoint,
mockSwapAcceptedEndpoint,
mockSwapCancelledEndpoint,
mockSwapStatusEndpoint,
}) => {
const swapPage = new SwapPage(page);
const deviceAction = new DeviceAction(page);
const drawer = new Drawer(page);
Expand All @@ -138,22 +148,22 @@ test.describe.parallel("Swap", () => {
route.fulfill({ headers: { teststatus: "mocked" }, body: mockRatesResponse });
});

// We mock the 'cancelled' swap response because the transaction isn't broadcast when run locally.
// If 'cancelled' is called then it's a successful test
await page.route("https://swap.ledger.com/v5/swap/cancelled", async route => {
console.log("Mocking swap cancelled HTTP response");
route.fulfill({ headers: { teststatus: "mocked" }, body: "" });
});

await page.route("https://swap.ledger.com/v5/swap/accepted", async route => {
console.log("Mocking swap accepted HTTP response");
route.fulfill({ headers: { teststatus: "mocked" }, body: "" });
});

await page.route("https://swap.ledger.com/v5/swap/status", async route => {
console.log("Mocking swap status HTTP response");
const mockStatusResponse = getStatusMock();
route.fulfill({ headers: { teststatus: "mocked" }, body: mockStatusResponse });
await page.route("https://swap.ledger.com/v5/currencies/to**", async route => {
route.fulfill({
headers: { teststatus: "mocked" },
body: JSON.stringify({
currencyGroups: [
{
network: "dogecoin",
supportedCurrencies: ["dogecoin"],
},
{
network: "ethereum",
supportedCurrencies: ["ethereum", "ethereum/erc20/usd_tether__erc20_"],
},
],
}),
});
});

await test.step("Open Swap Page", async () => {
Expand Down
Binary file not shown.
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.
Binary file not shown.
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.
Binary file not shown.
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.
Binary file not shown.
Binary file not shown.
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.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { ResponseDataAll } from "../fetchCurrencyAll";

export const fetchCurrencyAllMock: ResponseDataAll = {
from: [
{
network: "bitcoin",
supportedCurrencies: ["bitcoin"],
},
{
network: "dogecoin",
supportedCurrencies: ["dogecoin"],
},
{
network: "ethereum",
supportedCurrencies: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export const fetchCurrencyFromMock: ResponseData = {
network: "bitcoin",
supportedCurrencies: ["bitcoin"],
},
{
network: "dogecoin",
supportedCurrencies: ["dogecoin"],
},
{
network: "ethereum",
supportedCurrencies: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { ResponseData } from "../fetchCurrencyTo";

export const fetchCurrencyToMock: ResponseData = {
currencyGroups: [
{
network: "bitcoin",
supportedCurrencies: ["bitcoin"],
},
{
network: "dogecoin",
supportedCurrencies: ["dogecoin"],
},
{
network: "ethereum",
supportedCurrencies: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import network from "@ledgerhq/live-network/network";
import { isIntegrationTestEnv } from "../../utils/isIntegrationTestEnv";
import { DEFAULT_SWAP_TIMEOUT_MS } from "../../const/timeout";
import axios from "axios";
import { LedgerAPI4xx } from "@ledgerhq/errors";
Expand All @@ -8,6 +7,7 @@ import { ResponseData as ResponseDataTo } from "./fetchCurrencyTo";
import { ResponseData as ResponseDataFrom } from "./fetchCurrencyFrom";
import { flattenV5CurrenciesAll } from "../../utils/flattenV5CurrenciesAll";
import { getSwapAPIBaseURL } from "../..";
import { getEnv } from "@ledgerhq/live-env";

type Props = {
providers: Array<string>;
Expand All @@ -20,7 +20,8 @@ export type ResponseDataAll = {
};

export async function fetchCurrencyAll({ providers, additionalCoinsFlag = false }: Props) {
if (isIntegrationTestEnv()) return Promise.resolve(flattenV5CurrenciesAll(fetchCurrencyAllMock));
if (getEnv("MOCK") || getEnv("PLAYWRIGHT_RUN"))
return Promise.resolve(flattenV5CurrenciesAll(fetchCurrencyAllMock));

const url = new URL(`${getSwapAPIBaseURL()}/currencies/all`);
url.searchParams.append("providers-whitelist", providers.join(","));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import network from "@ledgerhq/live-network/network";
import { isIntegrationTestEnv } from "../../utils/isIntegrationTestEnv";
import { DEFAULT_SWAP_TIMEOUT_MS } from "../../const/timeout";
import { flattenV5CurrenciesToAndFrom } from "../../utils/flattenV5CurrenciesToAndFrom";
import { fetchCurrencyFromMock } from "./__mocks__/fetchCurrencyFrom.mocks";
import { getSwapAPIBaseURL } from "../..";
import { getEnv } from "@ledgerhq/live-env";

type Props = {
providers: Array<string>;
Expand All @@ -23,7 +23,8 @@ export async function fetchCurrencyFrom({
currencyTo,
additionalCoinsFlag = false,
}: Props) {
if (isIntegrationTestEnv()) return flattenV5CurrenciesToAndFrom(fetchCurrencyFromMock);
if (getEnv("MOCK") || getEnv("PLAYWRIGHT_RUN"))
return flattenV5CurrenciesToAndFrom(fetchCurrencyFromMock);

const url = new URL(`${getSwapAPIBaseURL()}/currencies/from`);
url.searchParams.append("providers-whitelist", providers.join(","));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ export async function fetchCurrencyTo({
providers,
additionalCoinsFlag = false,
}: Props) {
if (isIntegrationTestEnv()) {
if (isIntegrationTestEnv())
return Promise.resolve(flattenV5CurrenciesToAndFrom(fetchCurrencyToMock));
}

const url = new URL(`${getSwapAPIBaseURL()}/currencies/to`);

Expand Down

0 comments on commit b7d3dc3

Please sign in to comment.