From 39e485a438abbea53f832b1a01b8f7183d51c995 Mon Sep 17 00:00:00 2001 From: nitesh Date: Sat, 15 Jun 2024 13:32:01 -0400 Subject: [PATCH 1/2] fix jest config and test cases --- jest.config.js | 22 +- tests/react/windows/OnChain.test.tsx | 36 +- tests/react/windows/Overview.test.tsx | 14 +- tests/react/windows/Receive.test.tsx | 25 +- .../__snapshots__/OnChain.test.tsx.snap | 361 ++++++++++-------- .../__snapshots__/Overview.test.tsx.snap | 122 +++--- .../__snapshots__/Receive.test.tsx.snap | 344 +++++++++-------- .../__snapshots__/Restore.test.tsx.snap | 121 +++--- 8 files changed, 525 insertions(+), 520 deletions(-) diff --git a/jest.config.js b/jest.config.js index b719b8201..2a3739377 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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)$": "/assetsTransformer.js", - "\\.(css|less)$": "/assetsTransformer.js" + "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": + "/assetsTransformer.js", + "\\.(css|less)$": "/assetsTransformer.js", + "^react-native-reanimated$": "/node_modules/react-native-reanimated/src/Animated.ts", }, - testMatch: ['**/tests/**/*.[jt]s?(x)'], -} + testMatch: ["**/tests/**/*.[jt]s?(x)"], +}; diff --git a/tests/react/windows/OnChain.test.tsx b/tests/react/windows/OnChain.test.tsx index a92dc37ca..e030a4a76 100644 --- a/tests/react/windows/OnChain.test.tsx +++ b/tests/react/windows/OnChain.test.tsx @@ -15,11 +15,7 @@ const AppContainer = createNavigationContainer(OnChain, "OnChain"); it("renders correctly", async () => { const store = await initCommonStore(true); - const { unmount, toJSON } = render( - - {AppContainer} - - ); + const { unmount, toJSON } = render({AppContainer}); expect(toJSON()).toMatchSnapshot(); unmount(); @@ -34,9 +30,7 @@ it("is possible display on-chain funds", async () => { }); const { queryByTestId, queryByText, unmount } = render( - - {AppContainer} - + {AppContainer}, ); const onChainFundsText = queryByTestId("ONCHAIN_FUNDS"); @@ -69,12 +63,10 @@ it("should be possible to withdraw funds (no camera)", async () => { txid: "7836ca1453ef598b989a09496f48be17e14950a44e6ab2526b4a7fc17f9e4591", }); return response; - }) + }); const { queryByTestId, unmount } = render( - - {AppContainer} - + {AppContainer}, ); const onChainFundsText = queryByTestId("ONCHAIN_FUNDS"); @@ -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!)); @@ -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( - - {AppContainer} - + const { getByTestId, unmount, debug, baseElement } = render( + {AppContainer}, ); 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; }); diff --git a/tests/react/windows/Overview.test.tsx b/tests/react/windows/Overview.test.tsx index 5cb146260..cde46bb10 100644 --- a/tests/react/windows/Overview.test.tsx +++ b/tests/react/windows/Overview.test.tsx @@ -22,11 +22,7 @@ it("renders correctly", () => { const store = setupStore(); store.getActions().channel.setBalance(Long.fromNumber(123)); - const { toJSON, unmount } = render( - - {AppContainer} - - ); + const { toJSON, unmount } = render({AppContainer}); expect(toJSON()).toMatchSnapshot(); // unmount(); }); @@ -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( - - {AppContainer} - + {AppContainer}, ); const txList = getByTestId("TX_LIST"); @@ -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()), }); }); diff --git a/tests/react/windows/Receive.test.tsx b/tests/react/windows/Receive.test.tsx index bd4edba56..266c864fb 100644 --- a/tests/react/windows/Receive.test.tsx +++ b/tests/react/windows/Receive.test.tsx @@ -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"; @@ -20,11 +25,7 @@ const AppContainer = createNavigationContainer(Receive, "Receive"); it("renders correctly", () => { const store = setupStore(); - const { unmount, toJSON } = render( - - {AppContainer} - - ); + const { unmount, toJSON } = render({AppContainer}); expect(toJSON()).toMatchSnapshot(); unmount(); @@ -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( - - {AppContainer} - + {AppContainer}, ); const inputAmountSat = queryByTestId("input-amount-sat"); @@ -84,9 +83,7 @@ test("invoice appears on the transaction list", async () => { ); const { getByTestId, findByTestId, unmount, getAllByTestId } = render( - - {Container} - + {Container}, ); // See if we can find the Overview transaction list @@ -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()), }); }); diff --git a/tests/react/windows/__snapshots__/OnChain.test.tsx.snap b/tests/react/windows/__snapshots__/OnChain.test.tsx.snap index 4a7d005e9..2bb56cafe 100644 --- a/tests/react/windows/__snapshots__/OnChain.test.tsx.snap +++ b/tests/react/windows/__snapshots__/OnChain.test.tsx.snap @@ -11,20 +11,21 @@ exports[`renders correctly 1`] = ` - - + > + + @@ -1038,47 +973,46 @@ exports[`renders correctly 1`] = ` pointerEvents="box-none" style={ { - "bottom": 0, - "left": 0, - "position": "absolute", - "right": 0, - "top": 0, - "zIndex": 0, + "height": 44, + "maxHeight": undefined, + "minHeight": undefined, + "opacity": undefined, + "transform": undefined, } } > - - + > + + + > + + + + + Back + + + + @@ -1130,6 +1168,7 @@ exports[`renders correctly 1`] = ` style={ { "color": "#e5eaea", + "fontFamily": "System", "fontSize": 17, "fontWeight": "600", } @@ -1239,10 +1278,10 @@ exports[`renders correctly 1`] = ` pointerEvents="box-none" style={ { + "end": 0, "height": 44, - "left": 0, "position": "absolute", - "right": 0, + "start": 0, "top": 0, "zIndex": 1, } diff --git a/tests/react/windows/__snapshots__/Overview.test.tsx.snap b/tests/react/windows/__snapshots__/Overview.test.tsx.snap index e7bf87887..84e3ac445 100644 --- a/tests/react/windows/__snapshots__/Overview.test.tsx.snap +++ b/tests/react/windows/__snapshots__/Overview.test.tsx.snap @@ -11,20 +11,21 @@ exports[`renders correctly 1`] = ` - - + > + + - - + > + + - - + > + + + > + + + + + Back + + + + @@ -1173,6 +1210,7 @@ exports[`renders correctly 1`] = ` style={ { "color": "#e5eaea", + "fontFamily": "System", "fontSize": 17, "fontWeight": "600", } @@ -1211,10 +1249,10 @@ exports[`renders correctly 1`] = ` pointerEvents="box-none" style={ { + "end": 0, "height": 44, - "left": 0, "position": "absolute", - "right": 0, + "start": 0, "top": 0, "zIndex": 1, } diff --git a/tests/react/windows/__snapshots__/Restore.test.tsx.snap b/tests/react/windows/__snapshots__/Restore.test.tsx.snap index 26b7f7cf3..8e08ca9e6 100644 --- a/tests/react/windows/__snapshots__/Restore.test.tsx.snap +++ b/tests/react/windows/__snapshots__/Restore.test.tsx.snap @@ -11,20 +11,21 @@ exports[`renders correctly 1`] = ` - - + > + + Date: Sat, 15 Jun 2024 13:34:13 -0400 Subject: [PATCH 2/2] fix test workflow --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 648361792..d11af59cb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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