1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/index.test.js
Olusegun Akintayo 4fa4930c8a
Add friendly error handling when background throws an error before listening for connection (#14461)
* When background port closes, UI should display a user friendly error.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove console.log

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

A couple of fixes
    1. Use timeout in metaRPCClientFactory to check if UI can't
       communicate with bg
    2. Refactor locale setup
    3. Fixed wording/capitalization
    4. Fix locales usage so that linting works
    5. Refactor CSS

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

do not simulate errorwq

Refactor loading css

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove the onDisconnect event handler in ui as this is handled in
metarpcclientfactory

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Do not throw in bg

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Fix PR comments

Remove unused message 'failedToLoadMessage'

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Move usage of locales to shared/** so that linter can see it.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Do not simulate error.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

metarpc can handle multiple requests, responseHandled should be a map.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

reload metamask button on critical error

Use metamask state (if available) to the locale, else read locale files
manually.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

use constant and numeric separator

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

refactor error utils

remove error simulation

Memoize setupLocale function

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

test cases

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Do not simulate error

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

1. store should be metamask state
2. code refactorings.
Tests: mock setupLocale

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Mock fetchLocale instead
Test setup locale

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

UI/CSS changes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Do not simulate failure

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* spell MetaMask correctly

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Rename state to mockStore

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* we should clean up this.responseHandled[id] in the error case.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Fixed PR comments.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* clean up response handled.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
2022-06-08 00:37:15 +04:00

71 lines
2.0 KiB
JavaScript

import { setupLocale } from '.';
const enMessages = {
troubleStarting: {
message:
'MetaMask had trouble starting. This error could be intermittent, so try restarting the extension.',
},
restartMetamask: {
message: 'Restart MetaMask',
},
stillGettingMessage: {
message: 'Still getting this message?',
},
sendBugReport: {
message: 'Send us a bug report.',
},
};
const esMessages = {
troubleStarting: {
message:
'MetaMask tuvo problemas para iniciarse. Este error podría ser intermitente, así que intente reiniciar la extensión.',
},
restartMetamask: {
message: 'Reiniciar metamáscara',
},
sendBugReport: {
message: 'Envíenos un informe de errores.',
},
};
jest.mock('./helpers/utils/i18n-helper', () => ({
fetchLocale: jest.fn((locale) => (locale === 'en' ? enMessages : esMessages)),
loadRelativeTimeFormatLocaleData: jest.fn(),
}));
describe('Index Tests', () => {
it('should get locale messages by calling setupLocale', async () => {
let result = await setupLocale('en');
const { currentLocaleMessages: clm, enLocaleMessages: elm } = result;
expect(clm).toBeDefined();
expect(elm).toBeDefined();
expect(clm.troubleStarting).toStrictEqual(enMessages.troubleStarting);
expect(clm.restartMetamask).toStrictEqual(enMessages.restartMetamask);
expect(clm.stillGettingMessage).toStrictEqual(
enMessages.stillGettingMessage,
);
expect(clm.sendBugReport).toStrictEqual(enMessages.sendBugReport);
result = await setupLocale('es');
const { currentLocaleMessages: clm2, enLocaleMessages: elm2 } = result;
expect(clm2).toBeDefined();
expect(elm2).toBeDefined();
expect(clm2.troubleStarting).toStrictEqual(esMessages.troubleStarting);
expect(clm2.restartMetamask).toStrictEqual(esMessages.restartMetamask);
expect(clm2.stillGettingMessage).toBeUndefined();
expect(elm2.stillGettingMessage).toStrictEqual(
enMessages.stillGettingMessage,
);
expect(clm2.sendBugReport).toStrictEqual(esMessages.sendBugReport);
});
});