Skip to content

Commit

Permalink
fix: increase test for network selector
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Oct 16, 2024
1 parent 7d59860 commit b5f5ea6
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions app/components/Views/NetworkSelector/NetworkSelector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,62 @@ describe('Network Selector', () => {
fireEvent.press(rpcOption);
});
});

it('filters networks correctly when searching', () => {
(isNetworkUiRedesignEnabled as jest.Mock).mockImplementation(() => true);
const { getByPlaceholderText, queryByText } = renderComponent(initialState);

const searchInput = getByPlaceholderText('Search');

// Simulate entering a search term
fireEvent.changeText(searchInput, 'Polygon');

// Polygon should appear, but others should not
expect(queryByText('Polygon Mainnet')).toBeTruthy();
expect(queryByText('Avalanche Mainnet C-Chain')).toBeNull();

// Clear search and check if all networks appear
fireEvent.changeText(searchInput, '');
expect(queryByText('Polygon Mainnet')).toBeTruthy();
expect(queryByText('Avalanche Mainnet C-Chain')).toBeTruthy();
});

it('shows popular networks when network UI redesign is enabled', () => {
(isNetworkUiRedesignEnabled as jest.Mock).mockImplementation(() => true);
const { getByText } = renderComponent(initialState);

// Check that the additional networks section is rendered
const popularNetworksTitle = getByText('Additional networks');
expect(popularNetworksTitle).toBeTruthy();
});

it('opens the multi-RPC selection modal correctly', async () => {
(isNetworkUiRedesignEnabled as jest.Mock).mockImplementation(() => true);
const { getByText } = renderComponent(initialState);

const polygonCell = getByText('Polygon Mainnet');

// Open the modal
fireEvent.press(polygonCell);
await waitFor(() => {
const rpcOption = getByText('polygon-mainnet.infura.io/v3');
expect(rpcOption).toBeTruthy();
});
});

it('toggles test networks visibility when switch is used', () => {
(isNetworkUiRedesignEnabled as jest.Mock).mockImplementation(() => true);
const { getByTestId } = renderComponent(initialState);
const testNetworksSwitch = getByTestId(
NetworkListModalSelectorsIDs.TEST_NET_TOGGLE,
);

// Toggle the switch on
fireEvent(testNetworksSwitch, 'onValueChange', true);
expect(setShowTestNetworksSpy).toBeCalledWith(true);

// Toggle the switch off
fireEvent(testNetworksSwitch, 'onValueChange', false);
expect(setShowTestNetworksSpy).toBeCalledWith(false);
});
});

0 comments on commit b5f5ea6

Please sign in to comment.