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 d6e8152
Showing 1 changed file with 49 additions and 0 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

0 comments on commit d6e8152

Please sign in to comment.