Skip to content

Commit

Permalink
Added more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VSaric committed Jan 30, 2023
1 parent 5514a44 commit 2c51f16
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export default class SignatureRequest extends PureComponent {
<Button
type="link"
className="signature-request__reject-all-button"
data-testid="signature-request-reject-all"
onClick={(e) => {
e.preventDefault();
this.handleCancelAll();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { fireEvent } from '@testing-library/react';
import configureMockStore from 'redux-mock-store';
import mockState from '../../../../test/data/mock-state.json';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
Expand Down Expand Up @@ -72,6 +73,10 @@ describe('Signature Request Component', () => {
hardwareWalletRequiresConnection={false}
clearConfirmTransaction={() => undefined}
cancel={() => undefined}
cancelAll={() => undefined}
mostRecentOverviewPage="/"
showRejectTransactionsConfirmationModal={() => undefined}
history={{ push: '/' }}
sign={() => undefined}
txData={{
msgParams,
Expand All @@ -85,6 +90,34 @@ describe('Signature Request Component', () => {
expect(container).toMatchSnapshot();
});

it('should render navigation', () => {
const msgParams = {
data: JSON.stringify(messageData),
version: 'V4',
origin: 'test',
};
const { queryByTestId } = renderWithProvider(
<SignatureRequest
hardwareWalletRequiresConnection={false}
clearConfirmTransaction={() => undefined}
cancel={() => undefined}
cancelAll={() => undefined}
mostRecentOverviewPage="/"
showRejectTransactionsConfirmationModal={() => undefined}
history={{ push: '/' }}
sign={() => undefined}
txData={{
msgParams,
}}
fromAccount={{ address: fromAddress }}
provider={{ type: 'rpc' }}
/>,
store,
);

expect(queryByTestId('navigation-container')).toBeInTheDocument();
});

it('should render a div message parsed without typeless data', () => {
messageData.message.do_not_display = 'one';
messageData.message.do_not_display_2 = {
Expand All @@ -100,6 +133,10 @@ describe('Signature Request Component', () => {
hardwareWalletRequiresConnection={false}
clearConfirmTransaction={() => undefined}
cancel={() => undefined}
cancelAll={() => undefined}
mostRecentOverviewPage="/"
showRejectTransactionsConfirmationModal={() => undefined}
history={{ push: '/' }}
sign={() => undefined}
txData={{
msgParams,
Expand All @@ -115,5 +152,128 @@ describe('Signature Request Component', () => {
expect(queryByText('do_not_display_2')).not.toBeInTheDocument();
expect(queryByText('two')).not.toBeInTheDocument();
});

it('should not render a reject multiple requests link if there is not multiple requests', () => {
const msgParams = {
data: JSON.stringify(messageData),
version: 'V4',
origin: 'test',
};
const { container } = renderWithProvider(
<SignatureRequest
hardwareWalletRequiresConnection={false}
clearConfirmTransaction={() => undefined}
cancel={() => undefined}
cancelAll={() => undefined}
mostRecentOverviewPage="/"
showRejectTransactionsConfirmationModal={() => undefined}
history={{ push: '/' }}
sign={() => undefined}
txData={{
msgParams,
}}
fromAccount={{ address: fromAddress }}
provider={{ type: 'rpc' }}
/>,
store,
);

expect(
container.querySelector('.signature-request__reject-all-button'),
).not.toBeInTheDocument();
});

it('should render a reject multiple requests link if there is multiple requests (greater than 1)', () => {
const msgParams = {
data: JSON.stringify(messageData),
version: 'V4',
origin: 'test',
};
const { container } = renderWithProvider(
<SignatureRequest
hardwareWalletRequiresConnection={false}
clearConfirmTransaction={() => undefined}
cancel={() => undefined}
cancelAll={() => undefined}
mostRecentOverviewPage="/"
showRejectTransactionsConfirmationModal={() => undefined}
history={{ push: '/' }}
sign={() => undefined}
txData={{
msgParams,
}}
fromAccount={{ address: fromAddress }}
provider={{ type: 'rpc' }}
unapprovedMessagesCount={2}
/>,
store,
);

expect(
container.querySelector('.signature-request__reject-all-button'),
).toBeInTheDocument();
});

it('should call reject all button when button is clicked', () => {
const msgParams = {
data: JSON.stringify(messageData),
version: 'V4',
origin: 'test',
};
const { container } = renderWithProvider(
<SignatureRequest
hardwareWalletRequiresConnection={false}
clearConfirmTransaction={() => undefined}
cancel={() => undefined}
cancelAll={() => undefined}
mostRecentOverviewPage="/"
showRejectTransactionsConfirmationModal={() => undefined}
history={{ push: '/' }}
sign={() => undefined}
txData={{
msgParams,
}}
fromAccount={{ address: fromAddress }}
provider={{ type: 'rpc' }}
unapprovedMessagesCount={2}
/>,
store,
);

const rejectRequestsLink = container.querySelector(
'.signature-request__reject-all-button',
);
fireEvent.click(rejectRequestsLink);
expect(rejectRequestsLink).toBeDefined();
});

it('should render text of reject all button', () => {
const msgParams = {
data: JSON.stringify(messageData),
version: 'V4',
origin: 'test',
};
const { getByText } = renderWithProvider(
<SignatureRequest
hardwareWalletRequiresConnection={false}
clearConfirmTransaction={() => undefined}
cancel={() => undefined}
cancelAll={() => undefined}
mostRecentOverviewPage="/"
showRejectTransactionsConfirmationModal={() => undefined}
history={{ push: '/' }}
sign={() => undefined}
txData={{
msgParams,
}}
fromAccount={{ address: fromAddress }}
provider={{ type: 'rpc' }}
unapprovedMessagesCount={2}
/>,
store,
);

expect(getByText('Reject 2 requests')).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ describe('Signature Request', () => {
push: sinon.spy(),
},
hardwareWalletRequiresConnection: false,
mostRecentOverviewPage: '/',
clearConfirmTransaction: sinon.spy(),
cancelMessage: sinon.spy(),
cancel: sinon.stub().resolves(),
showRejectTransactionsConfirmationModal: sinon.stub().resolves(),
cancelAll: sinon.stub().resolves(),
provider: {
type: 'rpc',
},
unapprovedMessagesCount: 2,
sign: sinon.stub().resolves(),
txData: {
msgParams: {
Expand Down Expand Up @@ -123,6 +127,14 @@ describe('Signature Request', () => {
expect(props.sign.calledOnce).toStrictEqual(true);
});

it('cancelAll', () => {
const cancelAll = screen.getByTestId('signature-request-reject-all');

fireEvent.click(cancelAll);

expect(props.cancelAll.calledOnce).toStrictEqual(false);
});

it('have user warning', () => {
const warningText = screen.getByText(
'Only sign this message if you fully understand the content and trust the requesting site.',
Expand Down

0 comments on commit 2c51f16

Please sign in to comment.