Skip to content

Commit

Permalink
fix: increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Oct 16, 2024
1 parent abd5daf commit 7d59860
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
Expand Down Expand Up @@ -149,6 +150,17 @@ const SAMPLE_NETWORKSETTINGS_PROPS = {
},
],
},
{
name: 'Polygon',
chain: 'MATIC',
chainId: 137,
faucets: [],
nativeCurrency: {
name: 'Polygon',
symbol: 'MATIC',
decimals: 18,
},
},
],
},
};
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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', () => {
Expand Down
4 changes: 0 additions & 4 deletions e2e/pages/Settings/NetworksView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 7d59860

Please sign in to comment.