1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-04 23:14:56 +01:00
metamask-extension/ui/components/app/signature-request/signature-request.container.test.js
Thomas Huang 18e4af7690
Unit test proptype (#14868)
* Add missing props to advanced tab component test.

* Add icon size prop to site icon test

* Add hardwareWalletRequiresConnection prop to signature request test as a boolean

* Add setShowDetectedTokens prop to detect token test

* Set Setting description prop to be either object or string.
2022-06-06 19:30:07 -07:00

81 lines
2.6 KiB
JavaScript

import React from 'react';
import { Provider } from 'react-redux';
import sinon from 'sinon';
import configureMockStore from 'redux-mock-store';
import { mountWithRouter } from '../../../../test/lib/render-helpers';
import SignatureRequest from './signature-request.container';
describe('Signature Request', () => {
let wrapper;
const mockStore = {
metamask: {
provider: {
type: 'transparent',
},
accounts: {
'0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5': {
address: '0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5',
balance: '0x03',
},
},
cachedBalances: {},
selectedAddress: '0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5',
},
};
const store = configureMockStore()(mockStore);
const props = {
fromAccount: {
address: '0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5',
},
history: {
push: sinon.spy(),
},
hardwareWalletRequiresConnection: false,
clearConfirmTransaction: sinon.spy(),
cancelMessage: sinon.spy(),
cancel: sinon.stub().resolves(),
sign: sinon.stub().resolves(),
txData: {
msgParams: {
id: 1,
data:
'{"types":{"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}],"Person":[{"name":"name","type":"string"},{"name":"wallet","type":"address"}],"Mail":[{"name":"from","type":"Person"},{"name":"to","type":"Person"},{"name":"contents","type":"string"}]},"primaryType":"Mail","domain":{"name":"Ether Mail","version":"1","chainId":"4","verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"},"message":{"from":{"name":"Cow","wallet":"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"},"to":{"name":"Bob","wallet":"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"},"contents":"Hello, Bob!"}}',
from: '0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5',
origin: 'test.domain',
},
status: 'unapproved',
time: 1,
type: 'eth_sign',
},
};
beforeEach(() => {
wrapper = mountWithRouter(
<Provider store={store}>
<SignatureRequest.WrappedComponent {...props} />
</Provider>,
store,
);
});
afterEach(() => {
props.clearConfirmTransaction.resetHistory();
});
it('cancel', () => {
const cancelButton = wrapper.find('button.btn-secondary');
cancelButton.simulate('click');
expect(props.cancel.calledOnce).toStrictEqual(true);
});
it('sign', () => {
const signButton = wrapper.find('button.btn-primary');
signButton.simulate('click');
expect(props.sign.calledOnce).toStrictEqual(true);
});
});