Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom form check alerts #25259

Merged
merged 31 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a71a066
feat: add custom network new checkers
salimtb Jun 24, 2024
090ff13
fix: resolve conflicts
salimtb Jul 1, 2024
d0c343e
fix: fix test
salimtb Jul 1, 2024
99af0ad
fix: fix e2e tests
salimtb Jul 2, 2024
2369004
fix: fix PR comments
salimtb Jul 2, 2024
100ec24
fix: fix PR comments
salimtb Jul 2, 2024
218dcd6
fix: fix networks form props
salimtb Jul 3, 2024
57d27c9
fix: fix design review comments
salimtb Jul 4, 2024
74c30b8
fix: resolve conflicts && fix PR comments
salimtb Jul 4, 2024
558fbc9
fix: add test & clean
salimtb Jul 5, 2024
0f7fed2
fix: persist form
salimtb Jul 5, 2024
ffc2548
fix: fix network icon size
salimtb Jul 7, 2024
e718e19
fix: fix PR comments
salimtb Jul 10, 2024
28b74ed
fix: fix design
salimtb Jul 12, 2024
1bc243b
fix: fix PR comment
salimtb Jul 12, 2024
48bf5f5
fix: fix click outside
salimtb Jul 12, 2024
a5da15c
fix: add tooltip
salimtb Jul 13, 2024
436c943
fix: refacto form
salimtb Jul 13, 2024
3b56406
fix: fix tooltip touch
salimtb Jul 13, 2024
a2cf649
fix: fix unit tests
salimtb Jul 13, 2024
40f43b6
fix: add chainId tooltip
salimtb Jul 14, 2024
795e6cb
fix: remove drop down multi rpc
salimtb Jul 15, 2024
c57af70
fix: remove multi-rpc drop down menu
salimtb Jul 15, 2024
0b1b936
fix: fix unit tests
salimtb Jul 15, 2024
55d5fca
fix: fix linter
salimtb Jul 15, 2024
ca484d4
Fixed swap tests
davibroc Jul 15, 2024
857f42b
fix: fix comments PR
salimtb Jul 15, 2024
516a62e
fix: fix PR comments
salimtb Jul 16, 2024
389f159
fix PR comment
salimtb Jul 16, 2024
7c6a436
fix: fix unmatch chainId
salimtb Jul 16, 2024
b2f66a2
fix: fix chain list link
salimtb Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 17 additions & 10 deletions test/e2e/playwright/shared/pageObjects/network-controller-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export class NetworkController {

readonly addNetworkManuallyButton: Locator;

readonly networkTickerInput: Locator;

readonly approveBtn: Locator;

readonly saveBtn: Locator;
Expand All @@ -21,23 +19,32 @@ export class NetworkController {

readonly networkSearch: Locator;

readonly networkName: Locator;

readonly networkRpc: Locator;

readonly networkChainId: Locator;

readonly networkTicker: Locator;

constructor(page: Page) {
this.page = page;
this.networkDisplay = this.page.getByTestId('network-display');
this.addNetworkButton = this.page.getByText('Add network');
this.addNetworkManuallyButton = this.page.getByTestId(
'add-network-manually',
);
this.networkTickerInput = this.page.getByTestId(
'network-form-ticker-input',
);
this.saveBtn = this.page.getByRole('button', { name: 'Save' });
this.approveBtn = this.page.getByTestId('confirmation-submit-button');
this.switchToNetworkBtn = this.page.locator('button', {
hasText: 'Switch to',
});
this.gotItBtn = this.page.getByRole('button', { name: 'Got it' });
this.networkSearch = this.page.locator('input[type="search"]');
this.networkName = this.page.getByTestId('network-form-network-name');
this.networkRpc = this.page.getByTestId('network-form-rpc-url');
this.networkChainId = this.page.getByTestId('network-form-chain-id');
this.networkTicker = this.page.getByTestId('network-form-ticker-input');
}

async addCustomNetwork(options: {
Expand All @@ -50,11 +57,11 @@ export class NetworkController {
await this.addNetworkButton.click();
await this.addNetworkManuallyButton.click();

const formField = await this.page.$$('.form-field__input');
await formField[0].fill(options.name);
await formField[1].fill(options.url);
await formField[2].fill(options.chainID);
await this.networkTickerInput.fill(options.symbol);
await this.networkName.waitFor();
await this.networkName.fill(options.name);
await this.networkRpc.fill(options.url);
await this.networkChainId.fill(options.chainID);
await this.networkTicker.fill(options.symbol);
await this.saveBtn.click();
await this.switchToNetworkBtn.click();
}
Expand Down
10 changes: 7 additions & 3 deletions test/e2e/tests/network/add-custom-network.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ const selectors = {
saveButton: { text: 'Save', tag: 'button' },
updatedNetworkDropDown: { tag: 'span', text: 'Update Network' },
errorMessageInvalidUrl: {
tag: 'h6',
text: 'URLs require the appropriate HTTP/HTTPS prefix.',
},
warningSymbol: {
tag: 'h6',
text: 'URLs require the appropriate HTTP/HTTPS prefix.',
},
suggestedTicker: '[data-testid="network-form-ticker-suggestion"]',
Expand Down Expand Up @@ -802,6 +800,8 @@ describe('Custom network', function () {
);
await driver.fill(selectors.chainIdInputField, '1');
await driver.fill(selectors.tickerInputField, 'TST');
// fix flaky test
await driver.delay(regularDelayMs);
await driver.fill(selectors.explorerInputField, 'https://test.com');

const suggestedTicker = await driver.isElementPresent(
Expand Down Expand Up @@ -849,6 +849,9 @@ describe('Custom network', function () {
inputData.networkName,
);
await driver.fill(selectors.rpcUrlInputField, inputData.rpcUrl);

// fix flaky test
await driver.delay(regularDelayMs);
await driver.fill(selectors.chainIdInputField, inputData.chainId);
await driver.fill(selectors.tickerInputField, inputData.ticker);

Expand Down Expand Up @@ -945,7 +948,6 @@ async function failCandidateNetworkValidation(driver) {

const chainIdValidationMessageRawLocator = {
text: 'Could not fetch chain ID. Is your RPC URL correct?',
tag: 'h6',
};
await driver.waitForSelector(chainIdValidationMessageRawLocator);
await driver.waitForSelector('[data-testid="network-form-ticker-warning"]');
Expand Down Expand Up @@ -1047,6 +1049,8 @@ async function candidateNetworkIsNotValidated(driver) {
await driver.fill('[data-testid="network-form-ticker-input"]', 'cTH');
await blockExplorerURLInputEl.fill('https://block-explorer.url');

// fix flaky test
await driver.delay(regularDelayMs);
const saveButtonRawLocator = {
text: 'Save',
tag: 'button',
Expand Down
7 changes: 3 additions & 4 deletions test/e2e/tests/network/custom-rpc-history.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ describe('Custom RPC history', function () {
await rpcUrlInput.sendKeys(duplicateRpcUrl);
await driver.findElement({
text: 'This URL is currently used by the mainnet network.',
tag: 'h6',
});
},
);
Expand Down Expand Up @@ -144,7 +143,6 @@ describe('Custom RPC history', function () {
await chainIdInput.sendKeys(duplicateChainId);
await driver.findElement({
text: 'This Chain ID is currently used by the mainnet network.',
tag: 'h6',
});

await rpcUrlInput.clear();
Expand All @@ -160,7 +158,6 @@ describe('Custom RPC history', function () {

await driver.findElement({
text: 'Could not fetch chain ID. Is your RPC URL correct?',
tag: 'h6',
});
},
);
Expand Down Expand Up @@ -294,7 +291,9 @@ describe('Custom RPC history', function () {
value: customNetworkName,
});
// delete custom network in a modal
await driver.clickElement('.networks-tab__network-form .btn-danger');
await driver.clickElement(
'.networks-tab__network-form-footer .btn-danger',
);
await driver.findVisibleElement(
'[data-testid="confirm-delete-network-modal"]',
);
Expand Down
1 change: 0 additions & 1 deletion test/e2e/tests/network/update-network.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const selectors = {
saveButton: { text: 'Save', tag: 'button' },
updatedNetworkDropDown: { tag: 'span', text: 'Update Network' },
errorMessageInvalidUrl: {
tag: 'h6',
text: 'URLs require the appropriate HTTP/HTTPS prefix.',
},
networkNameInputField: '[data-testid="network-form-network-name"]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { useI18nContext } from '../../../hooks/useI18nContext';
import {
Box,
IconName,
ModalFocus,
Popover,
Expand Down Expand Up @@ -36,7 +37,7 @@ export const NetworkListItemMenu = ({
flip
>
<ModalFocus restoreFocus initialFocusRef={anchorElement}>
<div>
<Box>
{onEditClick ? (
<MenuItem
iconName={IconName.Edit}
Expand All @@ -48,7 +49,7 @@ export const NetworkListItemMenu = ({
}}
data-testid="network-list-item-options-edit"
>
{t('edit')}
<Text> {t('edit')}</Text>
</MenuItem>
) : null}
{onDeleteClick ? (
Expand All @@ -66,7 +67,7 @@ export const NetworkListItemMenu = ({
<Text color={TextColor.errorDefault}>{t('delete')}</Text>
</MenuItem>
) : null}
</div>
</Box>
</ModalFocus>
</Popover>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`NetworkListItem renders properly 1`] = `
<div>
<div
class="mm-box multichain-network-list-item mm-box--padding-4 mm-box--display-flex mm-box--gap-2 mm-box--justify-content-space-between mm-box--align-items-center mm-box--width-full mm-box--background-color-transparent"
class="mm-box multichain-network-list-item mm-box--padding-4 mm-box--display-flex mm-box--gap-4 mm-box--justify-content-space-between mm-box--align-items-center mm-box--width-full mm-box--background-color-transparent"
>
<div
class="mm-box mm-text mm-avatar-base mm-avatar-base--size-md mm-avatar-network mm-text--body-sm mm-text--text-transform-uppercase mm-box--display-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-full mm-box--border-color-transparent box--border-style-solid box--border-width-1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '../../../helpers/constants/design-system';
import {
AvatarNetwork,
AvatarNetworkSize,
Box,
ButtonIcon,
ButtonIconSize,
Expand All @@ -33,6 +34,7 @@ const MAXIMUM_CHARACTERS_WITHOUT_TOOLTIP = 20;
export const NetworkListItem = ({
name,
iconSrc,
iconSize = AvatarNetworkSize.Md,
selected = false,
focus = true,
onClick,
Expand Down Expand Up @@ -99,7 +101,7 @@ export const NetworkListItem = ({
return (
<Box
padding={4}
gap={2}
gap={4}
backgroundColor={selected ? Color.primaryMuted : Color.transparent}
className={classnames('multichain-network-list-item', {
'multichain-network-list-item--selected': selected,
Expand All @@ -121,6 +123,7 @@ export const NetworkListItem = ({
backgroundColor={getAvatarNetworkColor(name)}
name={name}
src={iconSrc}
size={iconSize}
/>
<Box
className="multichain-network-list-item__network-name"
Expand Down Expand Up @@ -170,6 +173,10 @@ NetworkListItem.propTypes = {
* Path to the Icon image
*/
iconSrc: PropTypes.string,
/**
* Icon network size
*/
iconSize: PropTypes.string,
/**
* Represents if the network item is selected
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AddRpcUrlModal should render correctly 1`] = `
<div>
<div
class="mm-box mm-box--padding-4"
>
<div
class="mm-box mm-form-text-field mm-box--display-flex mm-box--flex-direction-column"
>
<label
class="mm-box mm-text mm-label mm-label--html-for mm-form-text-field__label mm-text--body-sm-medium mm-text--font-weight-medium mm-box--display-inline-flex mm-box--align-items-center mm-box--color-text-default"
for="additional-rpc-url"
>
additionalRpcUrl
</label>
<div
class="mm-box mm-text-field mm-text-field--size-md mm-text-field--truncate mm-form-text-field__text-field mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--align-items-center mm-box--background-color-background-default mm-box--rounded-sm mm-box--border-width-1 box--border-style-solid"
>
<input
autocomplete="off"
class="mm-box mm-text mm-input mm-input--disable-state-styles mm-text-field__input mm-text--body-md mm-box--margin-0 mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--color-text-default mm-box--background-color-transparent mm-box--border-style-none"
focused="false"
id="additional-rpc-url"
type="text"
value=""
/>
</div>
</div>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-lg mm-button-primary mm-text--body-md-medium mm-box--margin-top-8 mm-box--margin-right-auto mm-box--margin-left-auto mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--display-block mm-box--justify-content-center mm-box--align-items-center mm-box--width-full mm-box--color-primary-inverse mm-box--background-color-primary-default mm-box--rounded-pill"
>
addUrl
</button>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import AddRpcUrlModal from './add-rpc-url-modal';

jest.mock('../../../../hooks/useI18nContext', () => ({
useI18nContext: jest.fn(),
}));

describe('AddRpcUrlModal', () => {
const useI18nContextMock = useI18nContext as jest.Mock;

beforeEach(() => {
useI18nContextMock.mockReturnValue((key: string) => key);
jest.clearAllMocks();
});

it('should render correctly', () => {
const { container } = render(<AddRpcUrlModal />);
expect(container).toMatchSnapshot();
});

it('should render the input field with the correct label', () => {
render(<AddRpcUrlModal />);
const inputLabel = screen.getByLabelText('additionalRpcUrl');
expect(inputLabel).toBeInTheDocument();
});

it('should render the "Add URL" button with correct text', () => {
render(<AddRpcUrlModal />);
const addButton = screen.getByRole('button', { name: 'addUrl' });
expect(addButton).toBeInTheDocument();
});

it('should call the appropriate function when "Add URL" button is clicked', () => {
const mockAddUrl = jest.fn();
render(<AddRpcUrlModal />);
const addButton = screen.getByRole('button', { name: 'addUrl' });
userEvent.click(addButton);
expect(mockAddUrl).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const AddRpcUrlModal = () => {
marginTop={8}
marginLeft={'auto'}
marginRight={'auto'}
onClick={() => ({})}
>
{t('addUrl')}
</ButtonPrimary>
Expand Down
Loading