Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix jest config and test cases #1437

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ on: [pull_request]

jobs:
tests:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- run: yarn
- run: yarn gen-proto
- run: yarn test
22 changes: 11 additions & 11 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
module.exports = {
preset: 'react-native',
moduleFileExtensions: ['android.ts', 'android.tsx', 'ts', 'tsx', 'js', 'jsx', 'json', 'node'],
preset: "react-native",
moduleFileExtensions: ["android.ts", "android.tsx", "ts", "tsx", "js", "jsx", "json", "node"],
transformIgnorePatterns: [
"node_modules/(?!react-native|@shoutem|react-clone-referenced-element|native-base|native-base-shoutem-theme|react-native-camera|@react-navigation|react-navigation-tabs|react-navigation|@react-native-community\/async-storage|@react-native-community/slider|@codler\/react-native-keyboard-aware-scroll-view|@react-native-community\/picker|@react-native)",
],
testPathIgnorePatterns: [
"tests/utils.ts",
"node_modules/(?!react-native|@shoutem|react-clone-referenced-element|native-base|native-base-shoutem-theme|react-native-camera|@react-navigation|react-navigation-tabs|react-navigation|@react-native-community/async-storage|@react-native-community/slider|@codler/react-native-keyboard-aware-scroll-view|@react-native-community/picker|@react-native)",
],
testPathIgnorePatterns: ["tests/utils.ts"],
setupFiles: [
// "react-native/jest/setup.js",
"./jestSetup.js",
"jest-date-mock",
"./node_modules/react-native-gesture-handler/jestSetup.js"
"./node_modules/react-native-gesture-handler/jestSetup.js",
],
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/assetsTransformer.js",
"\\.(css|less)$": "<rootDir>/assetsTransformer.js"
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/assetsTransformer.js",
"\\.(css|less)$": "<rootDir>/assetsTransformer.js",
"^react-native-reanimated$": "<rootDir>/node_modules/react-native-reanimated/src/Animated.ts",
},
testMatch: ['**/tests/**/*.[jt]s?(x)'],
}
testMatch: ["**/tests/**/*.[jt]s?(x)"],
};
36 changes: 17 additions & 19 deletions tests/react/windows/OnChain.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ const AppContainer = createNavigationContainer(OnChain, "OnChain");
it("renders correctly", async () => {
const store = await initCommonStore(true);

const { unmount, toJSON } = render(
<StoreProvider store={store}>
{AppContainer}
</StoreProvider>
);
const { unmount, toJSON } = render(<StoreProvider store={store}>{AppContainer}</StoreProvider>);
expect(toJSON()).toMatchSnapshot();

unmount();
Expand All @@ -34,9 +30,7 @@ it("is possible display on-chain funds", async () => {
});

const { queryByTestId, queryByText, unmount } = render(
<StoreProvider store={store}>
{AppContainer}
</StoreProvider>
<StoreProvider store={store}>{AppContainer}</StoreProvider>,
);

const onChainFundsText = queryByTestId("ONCHAIN_FUNDS");
Expand Down Expand Up @@ -69,12 +63,10 @@ it("should be possible to withdraw funds (no camera)", async () => {
txid: "7836ca1453ef598b989a09496f48be17e14950a44e6ab2526b4a7fc17f9e4591",
});
return response;
})
});

const { queryByTestId, unmount } = render(
<StoreProvider store={store}>
{AppContainer}
</StoreProvider>
<StoreProvider store={store}>{AppContainer}</StoreProvider>,
);

const onChainFundsText = queryByTestId("ONCHAIN_FUNDS");
Expand All @@ -90,7 +82,13 @@ it("should be possible to withdraw funds (no camera)", async () => {
const sendCoinsButton = await waitFor(() => queryByTestId("SEND_COINS"));
expect(sendCoinsButton).not.toBeNull();

act(() => void fireEvent.changeText(inputBitcoinAddress!, "tb1qy24mr4attphw83xhmxcspkkrxwqwurxjy085vuz6t4gxtmfyuq9srzd0yw"));
act(
() =>
void fireEvent.changeText(
inputBitcoinAddress!,
"tb1qy24mr4attphw83xhmxcspkkrxwqwurxjy085vuz6t4gxtmfyuq9srzd0yw",
),
);
act(() => void fireEvent.changeText(inputAmount!, "1"));
await act(async () => await fireEvent.press(sendCoinsButton!));

Expand All @@ -102,22 +100,22 @@ it("should be possible to withdraw funds (no camera)", async () => {
it("should be possible generate a new bitcoin address", async () => {
const store = await initCommonStore(true);

const {getByTestId, unmount, debug, baseElement } = render(
<StoreProvider store={store}>
{AppContainer}
</StoreProvider>
const { getByTestId, unmount, debug, baseElement } = render(
<StoreProvider store={store}>{AppContainer}</StoreProvider>,
);

const generateAddressButton = getByTestId("GENERATE_ADDRESS");

await waitFor(() => getByTestId('COPY_BITCOIN_ADDRESS'));
await waitFor(() => getByTestId("COPY_BITCOIN_ADDRESS"));
const bitcoinAddress = getByTestId("COPY_BITCOIN_ADDRESS");

expect(bitcoinAddress).not.toBeNull();
const oldAddress = within(bitcoinAddress).getByTestId("BITCOIN_ADDRESS").children[0];

newAddress.mockImplementationOnce(() => {
const response = lnrpc.NewAddressResponse.create({ address: "tb1qsl4hhqs8skzwknqhwjcyyyjepnwmq8tlcd32m4" });
const response = lnrpc.NewAddressResponse.create({
address: "tb1qsl4hhqs8skzwknqhwjcyyyjepnwmq8tlcd32m4",
});
return response;
});

Expand Down
14 changes: 4 additions & 10 deletions tests/react/windows/Overview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ it("renders correctly", () => {
const store = setupStore();
store.getActions().channel.setBalance(Long.fromNumber(123));

const { toJSON, unmount } = render(
<StoreProvider store={store}>
{AppContainer}
</StoreProvider>
);
const { toJSON, unmount } = render(<StoreProvider store={store}>{AppContainer}</StoreProvider>);
expect(toJSON()).toMatchSnapshot();
// unmount();
});
Expand All @@ -52,9 +48,7 @@ it("expect balance to update when paying an invoice", async () => {
await waitFor(() => expect(store.getState().transaction.transactions).toHaveLength(1));

const { queryByTestId, getByTestId } = render(
<StoreProvider store={store}>
{AppContainer}
</StoreProvider>
<StoreProvider store={store}>{AppContainer}</StoreProvider>,
);

const txList = getByTestId("TX_LIST");
Expand All @@ -75,11 +69,11 @@ it("expect balance to update when paying an invoice", async () => {
expiry: Long.fromValue(40),
isKeysend: false,
state: lnrpc.Invoice.InvoiceState.SETTLED,
})
});
act(() => {
balance = balance - 100;
DeviceEventEmitter.emit("SubscribeInvoices", {
data: base64.fromByteArray(lnrpc.Invoice.encode(invoice).finish())
data: base64.fromByteArray(lnrpc.Invoice.encode(invoice).finish()),
});
});

Expand Down
25 changes: 11 additions & 14 deletions tests/react/windows/Receive.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import * as base64 from "base64-js";

import Overview from "../../../src/windows/Overview";
import Receive from "../../../src/windows/Receive";
import { createNavigationContainer, setupStore, setDefaultAsyncStorage, initCommonStore } from "../../utils";
import {
createNavigationContainer,
setupStore,
setDefaultAsyncStorage,
initCommonStore,
} from "../../utils";
import { createStackNavigator } from "@react-navigation/stack";
import { NavigationContainer } from "@react-navigation/native";
import { DeviceEventEmitter } from "react-native";
Expand All @@ -20,11 +25,7 @@ const AppContainer = createNavigationContainer(Receive, "Receive");
it("renders correctly", () => {
const store = setupStore();

const { unmount, toJSON } = render(
<StoreProvider store={store}>
{AppContainer}
</StoreProvider>
);
const { unmount, toJSON } = render(<StoreProvider store={store}>{AppContainer}</StoreProvider>);
expect(toJSON()).toMatchSnapshot();

unmount();
Expand All @@ -35,9 +36,7 @@ it("is possible to create an invoice and go to the QR screen", async () => {
const store = await initCommonStore(true);

const { queryByTestId, unmount } = render(
<StoreProvider store={store}>
{AppContainer}
</StoreProvider>
<StoreProvider store={store}>{AppContainer}</StoreProvider>,
);

const inputAmountSat = queryByTestId("input-amount-sat");
Expand Down Expand Up @@ -84,9 +83,7 @@ test("invoice appears on the transaction list", async () => {
);

const { getByTestId, findByTestId, unmount, getAllByTestId } = render(
<StoreProvider store={store}>
{Container}
</StoreProvider>
<StoreProvider store={store}>{Container}</StoreProvider>,
);

// See if we can find the Overview transaction list
Expand Down Expand Up @@ -127,10 +124,10 @@ test("invoice appears on the transaction list", async () => {
expiry: Long.fromValue(40),
isKeysend: false,
state: lnrpc.Invoice.InvoiceState.SETTLED,
})
});
act(() => {
DeviceEventEmitter.emit("SubscribeInvoices", {
data: base64.fromByteArray(lnrpc.Invoice.encode(invoice).finish())
data: base64.fromByteArray(lnrpc.Invoice.encode(invoice).finish()),
});
});

Expand Down
Loading
Loading