Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MMI] Add Signature-request-original.component unit test #21090

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import {
Size,
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
IconColor,
DISPLAY,
BLOCK_SIZES,
Display,
BlockSize,
TextVariant,
BackgroundColor,
///: END:ONLY_INCLUDE_IN
} from '../../../helpers/constants/design-system';
import {
Box,
ButtonLink,
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
Icon,
Expand All @@ -46,7 +47,6 @@ import {
import BlockaidBannerAlert from '../security-provider-banner-alert/blockaid-banner-alert/blockaid-banner-alert';
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
import Box from '../../ui/box/box';
///: END:ONLY_INCLUDE_IN
import ConfirmPageContainerNavigation from '../confirm-page-container/confirm-page-container-navigation';
import SecurityProviderBannerMessage from '../security-provider-banner-message/security-provider-banner-message';
Expand Down Expand Up @@ -172,8 +172,8 @@ export default class SignatureRequestOriginal extends Component {
this.props.fromAccount.address ? null : (
<Box
className="request-signature__mismatch-info"
display={DISPLAY.FLEX}
width={BLOCK_SIZES.FULL}
Display={Display.Flex}
width={BlockSize.Full}
padding={4}
marginBottom={4}
backgroundColor={BackgroundColor.primaryMuted}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
rejectPendingApproval,
completedTx,
} from '../../../store/actions';
import { shortenAddress } from '../../../helpers/utils/util';
import SignatureRequestOriginal from '.';

jest.mock('../../../store/actions', () => ({
Expand Down Expand Up @@ -52,26 +53,29 @@ const MOCK_SIGN_DATA = JSON.stringify({
},
});

const address = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc';

const props = {
signMessage: jest.fn(),
cancelMessage: jest.fn(),
txData: {
msgParams: {
from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
from: address,
data: MOCK_SIGN_DATA,
origin: 'https://happydapp.website/governance?futarchy=true',
},
type: MESSAGE_TYPE.ETH_SIGN,
},
selectedAccount: {
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
address,
},
};

const render = (txData = props.txData) => {
const render = ({ txData = props.txData, selectedAddress = address } = {}) => {
const store = configureStore({
metamask: {
...mockState.metamask,
selectedAddress,
},
});

Expand Down Expand Up @@ -145,7 +149,7 @@ describe('SignatureRequestOriginal', () => {
},
type: MESSAGE_TYPE.ETH_SIGN_TYPED_DATA,
};
const { getByText } = render(txData);
const { getByText } = render({ txData });
expect(getByText('Message \\u202E test:')).toBeInTheDocument();
expect(getByText('Hi, \\u202E Alice!')).toBeInTheDocument();
});
Expand Down Expand Up @@ -196,4 +200,17 @@ describe('SignatureRequestOriginal', () => {
render();
expect(screen.getByText('This is a deceptive request')).toBeInTheDocument();
});

it('should display mismatch info when selected account address and from account address are not the same', () => {
const selectedAddress = '0xeb9e64b93097bc15f01f13eae97015c57ab64823';
const mismatchAccountText = `Your selected account (${shortenAddress(
selectedAddress,
)}) is different than the account trying to sign (${shortenAddress(
address,
)})`;

render({ selectedAddress });

expect(screen.getByText(mismatchAccountText)).toBeInTheDocument();
});
});
Loading