mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
parent
ed702af8ce
commit
329e4b75ed
@ -7,7 +7,7 @@ export function getAccountNameErrorMessage(
|
|||||||
defaultAccountName,
|
defaultAccountName,
|
||||||
) {
|
) {
|
||||||
const isDuplicateAccountName = accounts.some(
|
const isDuplicateAccountName = accounts.some(
|
||||||
(item) => item.name === newAccountName,
|
(item) => item.name.toLowerCase() === newAccountName.toLowerCase(),
|
||||||
);
|
);
|
||||||
|
|
||||||
const isEmptyAccountName = newAccountName === '';
|
const isEmptyAccountName = newAccountName === '';
|
||||||
@ -25,7 +25,7 @@ export function getAccountNameErrorMessage(
|
|||||||
const isReservedAccountName = reservedRegEx.test(newAccountName);
|
const isReservedAccountName = reservedRegEx.test(newAccountName);
|
||||||
|
|
||||||
const isValidAccountName =
|
const isValidAccountName =
|
||||||
newAccountName === defaultAccountName || // What is written in the text field is the same as the placeholder
|
newAccountName.toLowerCase() === defaultAccountName.toLowerCase() || // What is written in the text field is the same as the placeholder
|
||||||
(!isDuplicateAccountName && !isReservedAccountName && !isEmptyAccountName);
|
(!isDuplicateAccountName && !isReservedAccountName && !isEmptyAccountName);
|
||||||
|
|
||||||
let errorMessage;
|
let errorMessage;
|
||||||
|
47
ui/helpers/utils/accounts.test.js
Normal file
47
ui/helpers/utils/accounts.test.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import { getAccountNameErrorMessage } from './accounts';
|
||||||
|
|
||||||
|
const mockAccounts = [{ name: 'Account 1' }, { name: 'Account 2' }];
|
||||||
|
|
||||||
|
const mockLocalization = { t: jest.fn().mockReturnValue('Account') };
|
||||||
|
|
||||||
|
describe('Accounts', () => {
|
||||||
|
it('does not allow duplicate names', () => {
|
||||||
|
const { isValidAccountName } = getAccountNameErrorMessage(
|
||||||
|
mockAccounts,
|
||||||
|
mockLocalization,
|
||||||
|
'Account 2',
|
||||||
|
'Account 3',
|
||||||
|
);
|
||||||
|
expect(isValidAccountName).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not allow reserved name patterns', () => {
|
||||||
|
const { isValidAccountName } = getAccountNameErrorMessage(
|
||||||
|
mockAccounts,
|
||||||
|
mockLocalization,
|
||||||
|
'Account 7',
|
||||||
|
'Account 3',
|
||||||
|
);
|
||||||
|
expect(isValidAccountName).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not allow reserved name patterns in lowercase', () => {
|
||||||
|
const { isValidAccountName } = getAccountNameErrorMessage(
|
||||||
|
mockAccounts,
|
||||||
|
mockLocalization,
|
||||||
|
'account 7',
|
||||||
|
'Account 3',
|
||||||
|
);
|
||||||
|
expect(isValidAccountName).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows proposed name in lowercase', () => {
|
||||||
|
const { isValidAccountName } = getAccountNameErrorMessage(
|
||||||
|
mockAccounts,
|
||||||
|
mockLocalization,
|
||||||
|
'account 3',
|
||||||
|
'Account 3',
|
||||||
|
);
|
||||||
|
expect(isValidAccountName).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user