Skip to content

Commit

Permalink
fix: fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Sep 20, 2024
1 parent d6b6b07 commit 1342825
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 38 deletions.
2 changes: 1 addition & 1 deletion test/integration/data/integration-init-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@
"chainId": "0x1",
"rpcEndpoints": [
{
"networkClientId": "mainnet",
"networkClientId": "testNetworkConfigurationId",
"url": "https://mainnet.infura.io/v3/{infuraProjectId}",
"type": "infura"
}
Expand Down
72 changes: 35 additions & 37 deletions test/integration/multi-chain/rpc-modal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import mockMetaMaskState from '../data/integration-init-state.json';
import { integrationTestRender } from '../../lib/render-helpers';
import * as backgroundConnection from '../../../ui/store/background-connection';
import { createMockImplementation, mockGetChains, mockNetworkBaseLlama } from '../helpers';
import {
createMockImplementation,
mockGetChains,
mockNetworkBaseLlama,
} from '../helpers';
import { act, fireEvent, screen, waitFor } from '@testing-library/react';

jest.mock('../../../ui/store/background-connection', () => ({
Expand Down Expand Up @@ -39,9 +43,9 @@ describe('Metamask home page', () => {
...mockMetaMaskState,
preferences: {
...mockMetaMaskState.preferences,
showMultiRpcModal: true
}
}
showMultiRpcModal: true,
},
};

const mockedRequests = {
getState: mockedMetamaskState,
Expand All @@ -51,16 +55,18 @@ describe('Metamask home page', () => {
setupSubmitRequestToBackgroundMocks(mockedRequests);

await act(async () => {
await integrationTestRender({
await integrationTestRender({
preloadedState: mockedMetamaskState,
backgroundConnection: backgroundConnectionMocked,
})
});
});

const multiRpcModal = screen.getByTestId('multi-rpc-edit-modal');
expect(multiRpcModal).toBeInTheDocument();
expect(multiRpcModal).toHaveTextContent('Network RPCs Updated');
expect(multiRpcModal).toHaveTextContent('We now support multiple RPCs for a single network. Your most recent RPC has been selected as the default one to resolve conflicting information.');
expect(multiRpcModal).toHaveTextContent(
'We now support multiple RPCs for a single network. Your most recent RPC has been selected as the default one to resolve conflicting information.',
);
expect(screen.getByTestId('mm-modal-confirm')).toBeInTheDocument();
});

Expand All @@ -74,9 +80,9 @@ describe('Metamask home page', () => {
...mockMetaMaskState,
preferences: {
...mockMetaMaskState.preferences,
showMultiRpcModal: true
}
}
showMultiRpcModal: true,
},
};

const mockedRequests = {
getState: mockedMetamaskState,
Expand All @@ -86,10 +92,10 @@ describe('Metamask home page', () => {
setupSubmitRequestToBackgroundMocks(mockedRequests);

await act(async () => {
await integrationTestRender({
await integrationTestRender({
preloadedState: mockedMetamaskState,
backgroundConnection: backgroundConnectionMocked,
})
});
});

expect(screen.getByTestId('multi-rpc-edit-modal')).toBeInTheDocument();
Expand All @@ -116,22 +122,26 @@ describe('Metamask home page', () => {
setupSubmitRequestToBackgroundMocks(mockedRequests);

await act(async () => {
await integrationTestRender({
await integrationTestRender({
preloadedState: mockMetaMaskState,
backgroundConnection: backgroundConnectionMocked,
})
});
});

fireEvent.click(screen.getByTestId('network-display'));
expect(screen.queryByTestId('multichain-network-list-menu')).toBeInTheDocument();
expect(
screen.queryByTestId('multichain-network-list-menu'),
).toBeInTheDocument();

fireEvent.click(screen.getByTestId('network-list-item-options-button-0x2105'));
fireEvent.click(
screen.getByTestId('network-list-item-options-button-0x2105'),
);
fireEvent.click(screen.getByTestId('network-list-item-options-edit'));

expect(screen.queryByTestId('network-form-name-input')).toBeInTheDocument();

const networkNameInput = screen.getByTestId('network-form-network-name');
expect(networkNameInput).toHaveValue('Base Mainnet')
expect(networkNameInput).toHaveValue('Base Mainnet');
fireEvent.input(networkNameInput, { target: { value: 'New Base Name' } });
fireEvent.click(screen.getByTestId('network-form-save'));

Expand All @@ -142,9 +152,7 @@ describe('Metamask home page', () => {
mockedBackgroundConnection.submitRequestToBackground.mock.calls?.find(
(call) => call[0] === 'updateNetwork',
);
expect(updateNetworkCall?.[0]).toBe(
'updateNetwork',
);
expect(updateNetworkCall?.[0]).toBe('updateNetwork');
});

expect(updateNetworkCall?.[1]).toEqual(
Expand Down Expand Up @@ -174,9 +182,7 @@ describe('Metamask home page', () => {
}),
]),
defaultRpcEndpointIndex: 2,
blockExplorerUrls: expect.arrayContaining([
'https://basescan.org',
]),
blockExplorerUrls: expect.arrayContaining(['https://basescan.org']),
defaultBlockExplorerUrlIndex: 0,
}),
expect.objectContaining({
Expand All @@ -198,7 +204,7 @@ describe('Metamask home page', () => {
await integrationTestRender({
preloadedState: mockMetaMaskState,
backgroundConnection: backgroundConnectionMocked,
})
});
});

fireEvent.click(screen.getByTestId('network-display'));
Expand All @@ -210,26 +216,18 @@ describe('Metamask home page', () => {
mockedBackgroundConnection.submitRequestToBackground.mock.calls?.find(
(call) => call[0] === 'trackMetaMetricsEvent',
);
expect(networkMenuOpenedMetricsEvent?.[0]).toBe(
'trackMetaMetricsEvent',
);
expect(networkMenuOpenedMetricsEvent?.[0]).toBe('trackMetaMetricsEvent');
});

expect(networkMenuOpenedMetricsEvent?.[1]).toEqual(
expect.arrayContaining([
expect.objectContaining({
category: 'Navigation',
event: 'Network Menu Opened',
properties: {
location: 'App header',
chain_id: 'eip155:5'
},
category: 'Navigation',
properties: { location: 'App header', chain_id: 'eip155:11155111' },
environmentType: 'background',
page: {
path: '/',
title: 'Home',
url: '/'
}
page: { path: '/', title: 'Home', url: '/' },
referrer: undefined,
}),
]),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ exports[`Transaction Already Confirmed modal should match snapshot 1`] = `
>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-lg mm-modal-footer__button mm-button-secondary mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent mm-box--rounded-pill mm-box--border-color-primary-default box--border-style-solid box--border-width-1"
data-testid="mm-modal-cancel"
>
View on block explorer
</button>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-lg mm-modal-footer__button mm-button-primary mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-inverse mm-box--background-color-primary-default mm-box--rounded-pill"
data-testid="mm-modal-confirm"
data-theme="light"
>
Got it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ exports[`MultiRpcEditModal renders correctly with required props 1`] = `
>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-lg mm-button-base--block mm-modal-footer__button mm-button-primary mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-inverse mm-box--background-color-primary-default mm-box--rounded-pill"
data-testid="mm-modal-confirm"
data-theme="light"
>
accept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ exports[`<EditSpendingCapModal /> renders component 1`] = `
>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-lg mm-modal-footer__button mm-button-secondary mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent mm-box--rounded-pill mm-box--border-color-primary-default box--border-style-solid box--border-width-1"
data-testid="mm-modal-cancel"
>
Cancel
</button>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-lg mm-modal-footer__button mm-button-primary mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-inverse mm-box--background-color-primary-default mm-box--rounded-pill"
data-testid="mm-modal-confirm"
data-theme="light"
>
Save
Expand Down

0 comments on commit 1342825

Please sign in to comment.