diff --git a/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.test.tsx b/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.test.tsx index f0407434de9..a2cd3e231b3 100644 --- a/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.test.tsx +++ b/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.test.tsx @@ -87,6 +87,7 @@ const SAMPLE_NETWORKSETTINGS_PROPS = { { name: 'Ethereum Mainnet', chain: 'ETH', + chainId: 1, icon: 'ethereum', rpc: [ 'https://mainnet.infura.io/v3/${INFURA_API_KEY}', @@ -149,6 +150,17 @@ const SAMPLE_NETWORKSETTINGS_PROPS = { }, ], }, + { + name: 'Polygon', + chain: 'MATIC', + chainId: 137, + faucets: [], + nativeCurrency: { + name: 'Polygon', + symbol: 'MATIC', + decimals: 18, + }, + }, ], }, }; @@ -472,6 +484,15 @@ describe('NetworkSettings', () => { expect(wrapper.state('validatedChainId')).toBe(true); }); + it('should add RPC URL correctly to POL for polygon', async () => { + wrapper.setState({ rpcUrl: 'http://localhost:8545', chainId: '0x89' }); + + await wrapper.instance().validateRpcAndChainId(); + + expect(wrapper.state('validatedRpcURL')).toBe(true); + expect(wrapper.state('validatedChainId')).toBe(true); + }); + // here it('should update state and call getCurrentState on block explorer URL change', async () => { const newProps = { @@ -1149,6 +1170,34 @@ describe('NetworkSettings', () => { expect(wrapper4.state('chainId')).toBe('0x123'); expect(wrapper4.state('rpcUrl')).toBe('https://custom-network.io'); }); + + it('should call validateRpcAndChainId when matchedChainNetwork changes', () => { + const instance = wrapper.instance(); + + const validateRpcAndChainIdSpy = jest.spyOn( + wrapper.instance(), + 'validateRpcAndChainId', + ); + const updateNavBarSpy = jest.spyOn(wrapper.instance(), 'updateNavBar'); + + const prevProps = { + matchedChainNetwork: { + id: 'network1', + }, + }; + + // Simulate a prop change + wrapper.setProps({ + matchedChainNetwork: { + id: 'network2', + }, + }); + + instance.componentDidUpdate(prevProps); + + expect(updateNavBarSpy).toHaveBeenCalled(); + expect(validateRpcAndChainIdSpy).toHaveBeenCalled(); + }); }); describe('NetworkSettings - handleNetworkUpdate', () => { diff --git a/e2e/pages/Settings/NetworksView.js b/e2e/pages/Settings/NetworksView.js index 7be3bc71e37..5ab1cdde96d 100644 --- a/e2e/pages/Settings/NetworksView.js +++ b/e2e/pages/Settings/NetworksView.js @@ -139,10 +139,6 @@ class NetworkView { } async tapAddRpcButton() { - /* android is failing to tap on this element - The bottom sheet to add RPC url is not in the viewport for detox - Need to double check if the element is seen on android - */ await Gestures.waitAndTap(this.addRpcButton); }