Skip to content

Commit

Permalink
feat(llm): add missing integration test for the select import account…
Browse files Browse the repository at this point in the history
…s modal
  • Loading branch information
LucasWerey committed Jun 18, 2024
1 parent 4938d10 commit 0e1d53a
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 3 deletions.
29 changes: 29 additions & 0 deletions apps/ledger-live-mobile/__mocks__/MockedExpoCamera.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";

type Props = {
children: React.ReactNode;
};

export class MockedExpoCamera extends React.Component<Props> {
static useCameraPermissions = () => [
{ canAskAgain: false, expires: "never", granted: true, status: "granted" },
() => {
return new Promise(resolve => {
resolve(jest.fn());
});
},
() => {
return new Promise(resolve => {
resolve(jest.fn());
});
},
];
render() {
return <>{this.props.children}</>;
}
}

export const MockedCameraType = {
back: "back",
front: "front",
};
18 changes: 18 additions & 0 deletions apps/ledger-live-mobile/__tests__/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "@mocks/console";
import { ALLOWED_UNHANDLED_REQUESTS } from "./handlers";
import { server } from "./server";
import { NativeModules } from "react-native";
import { MockedExpoCamera, MockedCameraType } from "../__mocks__/MockedExpoCamera";

// Needed for react-reanimated https://docs.swmansion.com/react-native-reanimated/docs/next/guide/testing/
jest.useFakeTimers();
Expand Down Expand Up @@ -38,6 +39,23 @@ jest.mock("react-native-share", () => ({
default: jest.fn(),
}));

jest.mock("expo-camera", () => {
return {
Camera: MockedExpoCamera,
CameraType: MockedCameraType,
};
});

jest.mock("expo-barcode-scanner", () => ({
BarCodeScanner: {
Constants: {
BarCodeType: {
qr: "qr",
},
},
},
}));

// Mock of Native Modules
jest.mock("react-native-localize", () => ({
getTimeZone: jest.fn(),
Expand Down
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const transformIncludePatterns = [
"uuid",
"react-native-ble-plx",
"react-native-android-location-services-dialog-box",
"react-native-vector-icons",
];

/** @type {import('ts-jest').JestConfigWithTsJest} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { TestButtonPage } from "./shared";
import { State } from "~/reducers/types";

describe("AddAccount", () => {
it("Should open select add account method drawer with Wallet Sync option and navigate to import with your Ledger", async () => {
/**====== Import with ledger device test =======*/
it("Should open select add account method drawer with WS feature flag and navigate to import with your Ledger", async () => {
const { user } = render(<TestButtonPage />, {
overrideInitialState: (state: State) => ({
...state,
Expand All @@ -29,17 +30,75 @@ describe("AddAccount", () => {
await expect(await screen.findByText(/add another account/i));
await expect(await screen.findByText(/add with your ledger/i));
await expect(await screen.findByText(/import via another ledger live app/i));

// On press add with another ledger live app
await act(async () => {
await user.press(await screen.getByText(/add with your ledger/i));
});
await expect(await screen.findByText(/crypto asset/i)).toBeVisible();

// On click back
await act(async () => {
await user.press(await screen.findByTestId(/navigation-header-back-button/i));
});
await expect(addAssetButton).toBeVisible();
});

/**====== Import with WS test =======*/
it("Should open select add account method drawer with WS feature flag and navigate to import with wallet sync", async () => {
const { user } = render(<TestButtonPage />, {
overrideInitialState: (state: State) => ({
...state,
settings: {
...state.settings,
readOnlyModeEnabled: false,
overriddenFeatureFlags: { llmWalletSync: { enabled: true } },
},
}),
});

const addAssetButton = await screen.findByText(/Add asset/i);
// Check if the add asset button is visible
await expect(addAssetButton).toBeVisible();
// Open drawer
await act(async () => {
await user.press(addAssetButton);
});
// Wait for the drawer to open
await expect(await screen.findByText(/add another account/i));
await expect(await screen.findByText(/add with your ledger/i));
await expect(await screen.findByText(/import via another ledger live app/i));
// On press add with wallet sync
await act(async () => {
await user.press(await screen.getByText(/import via another ledger live app/i));
});
await expect(await screen.findByText(/dummy drawer/i)).toBeVisible();
});

/**====== Import from desktop Test =======*/
it("Should open select add account method drawer without WS feature flag and navigate to import from desktop", async () => {
const { user } = render(<TestButtonPage />, {
overrideInitialState: (state: State) => ({
...state,
settings: {
...state.settings,
readOnlyModeEnabled: false,
overriddenFeatureFlags: { llmWalletSync: { enabled: false } },
},
}),
});

const addAssetButton = await screen.findByText(/add asset/i);
// Check if the add asset button is visible
await expect(addAssetButton).toBeVisible();
// Open drawer
await user.press(addAssetButton);
// Wait for the drawer to open
await expect(await screen.findByText(/add another account/i));
await expect(await screen.findByText(/add with your ledger/i));
await expect(await screen.findByText(/import from desktop/i));
// On press add from desktop
await user.press(await screen.getByText(/import from desktop/i));
await expect(
await screen.findByText(/Scan and import your accounts from Ledger Live desktop/i),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from "react-i18next";
import AddAccountDrawer from "LLM/features/Accounts/screens/AddAccount";
import { BaseNavigatorStackParamList } from "~/components/RootNavigator/types/BaseNavigator";
import AddAccountsNavigator from "~/components/RootNavigator/AddAccountsNavigator";
import ImportAccountsNavigator from "~/components/RootNavigator/ImportAccountsNavigator";

const MockComponent = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -45,6 +46,7 @@ export function TestButtonPage() {
<Stack.Navigator initialRouteName={ScreenName.MockedAddAssetButton}>
<Stack.Screen name={ScreenName.MockedAddAssetButton} component={MockComponent} />
<Stack.Screen name={NavigatorName.AddAccounts} component={AddAccountsNavigator} />
<Stack.Screen name={NavigatorName.ImportAccounts} component={ImportAccountsNavigator} />
</Stack.Navigator>
);
}

0 comments on commit 0e1d53a

Please sign in to comment.