-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display error names instead of codes
- Loading branch information
1 parent
f3fdfe2
commit 196b313
Showing
5 changed files
with
164 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { render } from '@testing-library/react' | ||
import { ErrorText } from './error-text' | ||
import { MessagingContext } from '../contexts/messaging-context' | ||
|
||
describe('ErrorText', () => { | ||
const { location } = window | ||
|
||
afterAll(() => { | ||
window.location = location | ||
}) | ||
|
||
const renderErrorText = (error: string) => | ||
render( | ||
<MessagingContext.Provider | ||
value={{ switchToFullWindow: () => {} } as any} | ||
> | ||
<ErrorText error={error} />, | ||
</MessagingContext.Provider> | ||
) | ||
|
||
describe('GIVEN known error', () => { | ||
it('should render message instead', () => { | ||
const { getByText } = renderErrorText('DeviceMismatch') | ||
expect( | ||
getByText(/Make sure you connected correct Ledger device/i) | ||
).toBeTruthy() | ||
}) | ||
|
||
describe('GIVEN "FailedToCreateTransport" error inside popup', () => { | ||
it('should display "first time" instructions', () => { | ||
Object.defineProperty(window, 'location', { | ||
value: new URL('https://popup.html/?isPopupWindow=true'), | ||
configurable: true, | ||
writable: true, | ||
}) | ||
const { getByText } = renderErrorText('FailedToCreateTransport') | ||
expect(getByText(/navigate to full window/i)).toBeTruthy() | ||
}) | ||
}) | ||
|
||
describe('GIVEN "FailedToCreateTransport" error outside popup', () => { | ||
it('should not display "first time" instructions', () => { | ||
Object.defineProperty(window, 'location', { | ||
value: new URL('https://popup.html'), | ||
configurable: true, | ||
writable: true, | ||
}) | ||
const { getByText } = renderErrorText('FailedToCreateTransport') | ||
expect(() => getByText(/navigate to full window/i)).toThrow() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('GIVEN unknown error', () => { | ||
it('should render error descriptor', () => { | ||
const { getByText } = renderErrorText('6e14') | ||
expect(getByText(/Unknown Error: BadBip32PathNetworkId/i)).toBeTruthy() | ||
}) | ||
|
||
it('should render error descriptor', () => { | ||
const { getByText } = renderErrorText('6f0f') | ||
expect(getByText(/Unknown Error: CxErrorEcInvalidPoint/i)).toBeTruthy() | ||
}) | ||
|
||
it('should render error itself', () => { | ||
const { getByText } = renderErrorText('xxxxx') | ||
expect(getByText(/Unknown Error: xxxxx/i)).toBeTruthy() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,2 @@ | ||
import { LedgerError, LedgerErrorResponse } from './constants' | ||
|
||
export const isKnownError = (statusCode: any): statusCode is LedgerError => | ||
Object.values(LedgerErrorResponse).includes(statusCode) | ||
|
||
export const getDataLength = (data: string) => | ||
Math.floor(data.length / 2).toString(16) |