From 40ce40fc9a05ea53d8c76e6b10af5a09783e4b00 Mon Sep 17 00:00:00 2001 From: Filip Sekulic Date: Fri, 10 Feb 2023 16:23:11 +0100 Subject: [PATCH] Covered more test cases --- ...m-page-container-content.component.test.js | 43 ++++++++++ .../signature-request-original.test.js | 33 ++++++++ .../signature-request.component.test.js | 82 +++++++++++++++++++ 3 files changed, 158 insertions(+) diff --git a/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.test.js b/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.test.js index ed13a3987295..b8d55a8ebabc 100644 --- a/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.test.js +++ b/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.test.js @@ -47,6 +47,13 @@ describe('Confirm Page Container Content', () => { disabled: true, origin: 'http://localhost:4200', hideTitle: false, + txData: { + securityProviderResponse: { + flagAsDangerous: undefined, + reason: 'Some reason...', + reason_header: 'Some reason header...', + }, + }, }; }); @@ -126,4 +133,40 @@ describe('Confirm Page Container Content', () => { expect(queryByText('Address Book Account 1')).not.toBeInTheDocument(); }); + + it('should render SecurityProviderBannerMessage component properly', () => { + const { queryByText } = renderWithProvider( + , + store, + ); + + expect(queryByText('Request not verified')).toBeInTheDocument(); + expect( + queryByText( + 'Because of an error, this request was not verified by the security provider. Proceed with caution.', + ), + ).toBeInTheDocument(); + expect( + queryByText('This is based on information from'), + ).toBeInTheDocument(); + }); + + it('should not render SecurityProviderBannerMessage component when flagAsDangerous is 0', () => { + props.txData.securityProviderResponse = { + flagAsDangerous: 0, + }; + + const { queryByText } = renderWithProvider( + , + store, + ); + + expect(queryByText('Request not verified')).toBeNull(); + expect( + queryByText( + 'Because of an error, this request was not verified by the security provider. Proceed with caution.', + ), + ).toBeNull(); + expect(queryByText('This is based on information from')).toBeNull(); + }); }); diff --git a/ui/components/app/signature-request-original/signature-request-original.test.js b/ui/components/app/signature-request-original/signature-request-original.test.js index 5f7e04c93fac..071878a3222d 100644 --- a/ui/components/app/signature-request-original/signature-request-original.test.js +++ b/ui/components/app/signature-request-original/signature-request-original.test.js @@ -49,6 +49,11 @@ const props = { origin: 'https://happydapp.website/governance?futarchy=true', }, type: MESSAGE_TYPE.ETH_SIGN, + securityProviderResponse: { + flagAsDangerous: undefined, + reason: 'Some reason...', + reason_header: 'Some reason header...', + }, }, }; @@ -115,4 +120,32 @@ describe('SignatureRequestOriginal', () => { expect(getByText('Message \\u202E test:')).toBeInTheDocument(); expect(getByText('Hi, \\u202E Alice!')).toBeInTheDocument(); }); + + it('should render SecurityProviderBannerMessage component properly', () => { + render(); + expect(screen.getByText('Request not verified')).toBeInTheDocument(); + expect( + screen.getByText( + 'Because of an error, this request was not verified by the security provider. Proceed with caution.', + ), + ).toBeInTheDocument(); + expect( + screen.getByText('This is based on information from'), + ).toBeInTheDocument(); + }); + + it('should not render SecurityProviderBannerMessage component when flagAsDangerous is 0', () => { + props.txData.securityProviderResponse = { + flagAsDangerous: 0, + }; + + render(); + expect(screen.queryByText('Request not verified')).toBeNull(); + expect( + screen.queryByText( + 'Because of an error, this request was not verified by the security provider. Proceed with caution.', + ), + ).toBeNull(); + expect(screen.queryByText('This is based on information from')).toBeNull(); + }); }); diff --git a/ui/components/app/signature-request/signature-request.component.test.js b/ui/components/app/signature-request/signature-request.component.test.js index 5a26ba073942..f479a6456359 100644 --- a/ui/components/app/signature-request/signature-request.component.test.js +++ b/ui/components/app/signature-request/signature-request.component.test.js @@ -275,5 +275,87 @@ describe('Signature Request Component', () => { expect(getByText('Reject 2 requests')).toBeInTheDocument(); }); + + it('should render SecurityProviderBannerMessage component properly', () => { + const msgParams = { + data: JSON.stringify(messageData), + version: 'V4', + origin: 'test', + }; + + const { queryByText } = renderWithProvider( + undefined} + cancel={() => undefined} + cancelAll={() => undefined} + mostRecentOverviewPage="/" + showRejectTransactionsConfirmationModal={() => undefined} + history={{ push: '/' }} + sign={() => undefined} + txData={{ + msgParams, + securityProviderResponse: { + flagAsDangerous: undefined, + reason: 'Some reason...', + reason_header: 'Some reason header...', + }, + }} + fromAccount={{ address: fromAddress }} + provider={{ type: 'rpc' }} + unapprovedMessagesCount={2} + />, + store, + ); + + expect(queryByText('Request not verified')).toBeInTheDocument(); + expect( + queryByText( + 'Because of an error, this request was not verified by the security provider. Proceed with caution.', + ), + ).toBeInTheDocument(); + expect( + queryByText('This is based on information from'), + ).toBeInTheDocument(); + }); + + it('should not render SecurityProviderBannerMessage component when flagAsDangerous is 0', () => { + const msgParams = { + data: JSON.stringify(messageData), + version: 'V4', + origin: 'test', + }; + + const { queryByText } = renderWithProvider( + undefined} + cancel={() => undefined} + cancelAll={() => undefined} + mostRecentOverviewPage="/" + showRejectTransactionsConfirmationModal={() => undefined} + history={{ push: '/' }} + sign={() => undefined} + txData={{ + msgParams, + securityProviderResponse: { + flagAsDangerous: 0, + }, + }} + fromAccount={{ address: fromAddress }} + provider={{ type: 'rpc' }} + unapprovedMessagesCount={2} + />, + store, + ); + + expect(queryByText('Request not verified')).toBeNull(); + expect( + queryByText( + 'Because of an error, this request was not verified by the security provider. Proceed with caution.', + ), + ).toBeNull(); + expect(queryByText('This is based on information from')).toBeNull(); + }); }); });