Skip to content

Commit

Permalink
Merge pull request #7958 from LedgerHQ/fix/improve-ledger-sync-inte-t…
Browse files Browse the repository at this point in the history
…ests

fix: improve ledger sync tests
  • Loading branch information
KVNLS authored Oct 1, 2024
2 parents 07c584a + c00bf75 commit 98f0ae7
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render, screen, waitFor } from "tests/testUtils";
import { render, screen } from "tests/testUtils";
import { WalletSyncTestApp, mockedSdk, simpleTrustChain, walletSyncActivatedState } from "./shared";
import { INSTANCES } from "./shared";

Expand Down Expand Up @@ -48,17 +48,15 @@ describe("manageSynchronizedInstances", () => {
const button = screen.getByRole("button", { name: "Manage" });
await user.click(button);

const row = screen.getByTestId("walletSync-manage-instances");

await waitFor(() => expect(row).toBeDefined());
const row = await screen.findByTestId("walletSync-manage-instances");

expect(screen.getByText("2 Ledger Live apps synched")).toBeDefined();

await user.click(row);

//Manage Synch Instances Step

await waitFor(() => expect(screen.getByText("Ledger Live is synched across")).toBeDefined());
expect(await screen.findByText("Ledger Live is synched across")).toBeDefined();

const instance = screen.getByTestId("walletSync-manage-instance-currentInstance");
expect(instance).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ describe("ManageYourBackup", () => {
const button = screen.getByRole("button", { name: "Manage" });
await user.click(button);

const row = screen.getByTestId("walletSync-manage-backup");
await waitFor(() => expect(row).toBeDefined());
const row = await screen.findByTestId("walletSync-manage-backup");

await user.click(row);

Expand All @@ -57,8 +56,6 @@ describe("ManageYourBackup", () => {
await user.click(deleteButton);

//Success message
await waitFor(() =>
expect(screen.getByText("Your Ledger Live apps are no longer synched")).toBeDefined(),
);
expect(await screen.findByText("Your Ledger Live apps are no longer synched")).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render, screen, waitFor } from "tests/testUtils";
import { render, screen } from "tests/testUtils";
import { WalletSyncTestApp, simpleTrustChain, walletSyncActivatedState } from "./shared";

jest.mock("../hooks/useQRCode", () => ({
Expand Down Expand Up @@ -46,35 +46,35 @@ describe("Synchronize flow", () => {
const { button, user } = await openDrawer();
await user.click(button);

const row = screen.getByTestId("walletSync-synchronize");
await waitFor(() => expect(row).toBeDefined());
const row = await screen.findByTestId("walletSync-synchronize");

await user.click(row);

// QRCode Page
await waitFor(() =>
expect(screen.getByText(/Sync with the Ledger Live app on another phone/i)).toBeDefined(),
);
expect(
await screen.findByText(/Sync with the Ledger Live app on another phone/i),
).toBeDefined();

//TODO: Fix this test
//PinCode Page after scanning QRCode
// Need to wait 3 seconds to simulate the time taken to scan the QR code
setTimeout(async () => {
await waitFor(() => {
screen.debug();
expect(screen.getByText("Your Ledger Sync code")).toBeDefined();
});
}, 3000);
// setTimeout(async () => {
// await waitFor(() => {
// screen.debug();
// expect(screen.getByText("Your Ledger Sync code")).toBeDefined();
// });
// }, 3000);

//Succes Page after PinCode
setTimeout(async () => {
await waitFor(() => {
screen.debug();
expect(
screen.getByText(
"Changes in your crypto accounts will now automatically appear across Ledger Live apps on synched phones and computers.",
),
).toBeDefined();
});
}, 3000);
// //Succes Page after PinCode
// setTimeout(async () => {
// await waitFor(() => {
// screen.debug();
// expect(
// screen.getByText(
// "Changes in your crypto accounts will now automatically appear across Ledger Live apps on synched phones and computers.",
// ),
// ).toBeDefined();
// });
// }, 3000);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment jsdom
*/
import React from "react";
import { render, screen, waitFor } from "tests/testUtils";
import { render, screen } from "tests/testUtils";
import { initialStateWalletSync } from "~/renderer/reducers/walletSync";
import { WalletSyncTestApp, lldWalletSyncFeatureFlag, mockedSdk } from "./shared";
import { INITIAL_STATE as INITIAL_STATE_SETTINGS } from "~/renderer/reducers/settings";
Expand Down Expand Up @@ -34,10 +34,7 @@ describe("Rendering", () => {
const button = screen.getByRole("button", { name: "Manage" });

await user.click(button);
await waitFor(() =>
expect(screen.getByRole("button", { name: "Turn on Ledger Sync" })).toBeDefined(),
);

expect(await screen.findByRole("button", { name: "Turn on Ledger Sync" })).toBeDefined();
expect(screen.getByText("I already turned it on")).toBeDefined();
expect(store.getState().settings.overriddenFeatureFlags.lldWalletSync.enabled).toBe(true);
expect(screen.getByText(/How does Ledger Sync work?/i)).toBeDefined();
Expand All @@ -52,10 +49,7 @@ describe("Rendering", () => {
const button = screen.getByRole("button", { name: "Manage" });

await user.click(button);
await waitFor(() =>
expect(screen.getByRole("button", { name: "Turn on Ledger Sync" })).toBeDefined(),
);

expect(await screen.findByRole("button", { name: "Turn on Ledger Sync" })).toBeDefined();
expect(screen.getByText("I already turned it on")).toBeDefined();
expect(store.getState().settings.overriddenFeatureFlags.lldWalletSync).toBe(undefined);
expect(screen.queryByText(/How does Ledger Sync work?/i)).toBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("ManageKey", () => {
});

// Check if the ledger sync row is visible
await expect(await screen.findByText(/ledger sync/i)).toBeVisible();
expect(await screen.findByText(/ledger sync/i)).toBeVisible();

// On Press the ledger sync row
await user.press(await screen.findByText(/ledger sync/i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("scanQRCode", () => {
await user.press(await screen.findByText(/ledger sync/i));
await user.press(await screen.findByText(/I already turned it on/i));
await user.press(await screen.findByText(/scan qr code/i));
await expect(screen.queryAllByText(/show qr/i)).toHaveLength(2);
await expect(screen.getByTestId("ws-scan-camera")).toBeVisible();
expect(screen.queryAllByText(/show qr/i)).toHaveLength(2);
expect(screen.getByTestId("ws-scan-camera")).toBeVisible();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render, screen, waitFor } from "@tests/test-renderer";
import { render, screen } from "@tests/test-renderer";

import { INITIAL_TEST, WalletSyncSettingsNavigator } from "./shared";
import getWalletSyncEnvironmentParams from "@ledgerhq/live-common/walletSync/getEnvironmentParams";
Expand All @@ -21,6 +21,8 @@ jest.mock("@ledgerhq/trustchain/qrcode/index", () => ({
}),
}));

jest.useFakeTimers();

describe("SynchronizeWithQrCode", () => {
it("Should display the QR code when 'show qr' toggle is pressed and add a new member through the flow", async () => {
const { user } = render(<WalletSyncSettingsNavigator />, {
Expand All @@ -29,26 +31,19 @@ describe("SynchronizeWithQrCode", () => {
await user.press(await screen.findByText(/ledger sync/i));
await user.press(await screen.findByText(/I already turned it on/i));
await user.press(await screen.findByText(/scan qr code/i));
await user.press(await screen.queryAllByText(/show qr/i)[0]);
expect(await screen.getByTestId("ws-qr-code-displayed")).toBeVisible();
await user.press(screen.queryAllByText(/show qr/i)[0]);
expect(screen.getByTestId("ws-qr-code-displayed")).toBeVisible();

//PinCode Page after scanning QRCode
// Need to wait 3 seconds to simulate the time taken to scan the QR code
setTimeout(async () => {
await waitFor(() => {
expect(screen.getByText("Enter Ledger Sync code")).toBeDefined();
});
}, 3000);
// TODO: We need to simulate the QR code scanning process
// //PinCode Page after scanning QRCode
// // Need to wait 3 seconds to simulate the time taken to scan the QR code
// expect(await screen.findByText("Enter Ledger Sync code")).toBeDefined();

//Succes Page after PinCode
setTimeout(async () => {
await waitFor(() => {
expect(
screen.getByText(
"Changes in your accounts will now automatically appear across all apps and platforms.",
),
).toBeDefined();
});
}, 3000);
// //Succes Page after PinCode
// expect(
// await screen.findByText(
// "Changes in your accounts will now automatically appear across all apps and platforms.",
// ),
// ).toBeDefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("WalletSyncActivated", () => {
});

// Check if the ledger sync row is visible
await expect(await screen.findByText(/ledger sync/i)).toBeVisible();
expect(await screen.findByText(/ledger sync/i)).toBeVisible();

// On Press the ledger sync row
await user.press(await screen.findByText(/ledger sync/i));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { screen } from "@testing-library/react-native";
import { render, waitFor } from "@tests/test-renderer";
import { render } from "@tests/test-renderer";
import { INITIAL_TEST, WalletSyncSharedNavigator } from "./shared";
import { DeviceLike, State } from "~/reducers/types";
import { setEnv } from "@ledgerhq/live-env";
Expand Down Expand Up @@ -65,9 +65,7 @@ describe("WalletSyncActivation", () => {
}),
);

await waitFor(async () => {
expect(await screen.getByTestId("device-action-loading")).toBeVisible();
});
expect(await screen.findByTestId("device-action-loading")).toBeVisible();

// await waitFor(async () => {
// expect(await screen.findByText(`Continue on your Ledger Stax`)).toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { INITIAL_TEST, WalletSyncSettingsNavigator } from "./shared";
describe("WalletSyncSettings", () => {
it("Should display the ledger sync row", async () => {
render(<WalletSyncSettingsNavigator />, { overrideInitialState: INITIAL_TEST });
await expect(await screen.findByText(/ledger sync/i)).toBeVisible();
expect(await screen.findByText(/ledger sync/i)).toBeVisible();
});

it("Should open the activation drawer when ledger sync row is pressed", async () => {
const { user } = render(<WalletSyncSettingsNavigator />, {
overrideInitialState: INITIAL_TEST,
});
await user.press(await screen.findByText(/ledger sync/i));
await expect(await screen.findByText(/Turn on Ledger Sync for this phone/i)).toBeVisible();
await expect(await screen.findByText(/I already turned it on/i)).toBeVisible();
expect(await screen.findByText(/Turn on Ledger Sync for this phone/i)).toBeVisible();
expect(await screen.findByText(/I already turned it on/i)).toBeVisible();
});

it("Should open the drawer when 'already created a key' button is pressed", async () => {
Expand All @@ -24,6 +24,6 @@ describe("WalletSyncSettings", () => {
});
await user.press(await screen.findByText(/ledger sync/i));
await user.press(await screen.findByText(/I already turned it on/i));
await expect(await screen.findByText(/choose your sync method/i)).toBeVisible();
expect(await screen.findByText(/choose your sync method/i)).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("WalletSyncStatus", () => {
);

// Check if the ledger sync row is visible
await expect(await screen.findByText(/ledger sync/i)).toBeVisible();
expect(await screen.findByText(/ledger sync/i)).toBeVisible();

// On Press the ledger sync row
await user.press(await screen.findByText(/ledger sync/i));
Expand Down

0 comments on commit 98f0ae7

Please sign in to comment.