Skip to content

Commit

Permalink
feat(llm): fix missing mock for jest integrations tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasWerey committed Jun 17, 2024
1 parent d6ecc39 commit e76560a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
10 changes: 10 additions & 0 deletions apps/ledger-live-mobile/__tests__/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ const mockAnalytics = jest.genMockFromModule("@segment/analytics-react-native");

jest.mock("@segment/analytics-react-native", () => mockAnalytics);

jest.mock("react-native-launch-arguments", () => ({}));

NativeModules.BluetoothHelperModule = {
E_BLE_CANCELLED: "BLE_UNKNOWN_STATE",
};

jest.mock("react-native-share", () => ({
default: jest.fn(),
}));

// 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 @@ -16,6 +16,7 @@ const transformIncludePatterns = [
"@segment/analytics-react-native",
"uuid",
"react-native-ble-plx",
"react-native-android-location-services-dialog-box",
];

/** @type {import('ts-jest').JestConfigWithTsJest} */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Flex } from "@ledgerhq/native-ui";
import { Flex, Icons } from "@ledgerhq/native-ui";
import { useNavigation } from "@react-navigation/native";
import React from "react";
import Touchable from "./Touchable";
import { ArrowLeft } from "@ledgerhq/native-ui/assets/icons";

type Props = {
/**
* Function called when user presses on the back arrow.
Expand All @@ -13,7 +13,7 @@ type Props = {

export const NavigationHeaderBackImage = () => (
<Flex p={6}>
<ArrowLeft size={"M"} />
<Icons.ArrowLeft />
</Flex>
);

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 } from "@tests/test-renderer";
import { render, act } from "@tests/test-renderer";
import { TestButtonPage } from "./shared";
import { State } from "~/reducers/types";

Expand All @@ -11,29 +11,30 @@ describe("AddAccount", () => {
...state,
settings: {
...state.settings,
overriddenFeatureFlags: { llmWalletSync: { enabled: true } },
readOnlyModeEnabled: false,
overriddenFeatureFlags: { llmWalletSync: { enabled: true } },
},
}),
});

const addAssetButton = await screen.findByText(/Add asset/i);

// Check if the add asset button is visible
expect(addAssetButton).toBeVisible();

await expect(addAssetButton).toBeVisible();
// Open drawer
await user.press(addAssetButton);
expect(await screen.findByText(/Add another account/i)).toBeVisible();
expect(await screen.findByText(/Add with your Ledger/i)).toBeVisible();
expect(await screen.findByText(/Import via another Ledger Live app/i)).toBeVisible();

// On press add with your Ledger
await user.press(screen.getByText(/Add with your Ledger/i));
expect(await screen.findByText(/Crypto asset/i)).toBeVisible();
// IT NEED A FIX ON SOME PACKAGES TO AVOID THE FOLLOWING ERROR :
/**
* SyntaxError: Cannot use import statement outside a module
*/
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 another ledger live app
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();
});

// ITS WORKING FOR WS PATH BUT NOT WHEN WE WANT TO TEST OTHER PATH WHICH TRIGGERS OTHER SCREEN
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import AddAccountsNavigator from "~/components/RootNavigator/AddAccountsNavigato

const MockComponent = () => {
const { t } = useTranslation();
const [isAddModalOpened, setAddModalOpened] = React.useState(false);
const [isAddModalOpened, setAddModalOpened] = React.useState<boolean>(false);

const openAddModal = () => setAddModalOpened(true);
const closeAddModal = () => setAddModalOpened(false);
Expand Down

0 comments on commit e76560a

Please sign in to comment.