2022-08-16 17:25:30 +02:00
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
2022-11-30 16:34:50 +01:00
|
|
|
import { fireEvent, screen } from '@testing-library/react';
|
2022-08-16 17:25:30 +02:00
|
|
|
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
|
|
|
|
import mockState from '../../../../test/data/mock-state.json';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
2022-11-30 16:34:50 +01:00
|
|
|
import configureStore from '../../../store/store';
|
2022-08-16 17:25:30 +02:00
|
|
|
import SignatureRequestOriginal from '.';
|
|
|
|
|
|
|
|
const MOCK_SIGN_DATA = JSON.stringify({
|
|
|
|
domain: {
|
|
|
|
name: 'happydapp.website',
|
|
|
|
},
|
|
|
|
message: {
|
|
|
|
string: 'haay wuurl',
|
|
|
|
number: 42,
|
|
|
|
},
|
|
|
|
primaryType: 'Mail',
|
|
|
|
types: {
|
|
|
|
EIP712Domain: [
|
|
|
|
{ name: 'name', type: 'string' },
|
|
|
|
{ name: 'version', type: 'string' },
|
|
|
|
{ name: 'chainId', type: 'uint256' },
|
|
|
|
{ name: 'verifyingContract', type: 'address' },
|
|
|
|
],
|
|
|
|
Group: [
|
|
|
|
{ name: 'name', type: 'string' },
|
|
|
|
{ name: 'members', type: 'Person[]' },
|
|
|
|
],
|
|
|
|
Mail: [
|
|
|
|
{ name: 'from', type: 'Person' },
|
|
|
|
{ name: 'to', type: 'Person[]' },
|
|
|
|
{ name: 'contents', type: 'string' },
|
|
|
|
],
|
|
|
|
Person: [
|
|
|
|
{ name: 'name', type: 'string' },
|
|
|
|
{ name: 'wallets', type: 'address[]' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-11-30 16:34:50 +01:00
|
|
|
const props = {
|
|
|
|
signMessage: jest.fn(),
|
|
|
|
cancelMessage: jest.fn(),
|
|
|
|
txData: {
|
|
|
|
msgParams: {
|
|
|
|
from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
data: MOCK_SIGN_DATA,
|
|
|
|
origin: 'https://happydapp.website/governance?futarchy=true',
|
|
|
|
},
|
|
|
|
type: MESSAGE_TYPE.ETH_SIGN,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const render = () => {
|
|
|
|
const store = configureStore({
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return renderWithProvider(<SignatureRequestOriginal {...props} />, store);
|
|
|
|
};
|
|
|
|
|
2022-08-16 17:25:30 +02:00
|
|
|
describe('SignatureRequestOriginal', () => {
|
|
|
|
const store = configureMockStore()(mockState);
|
|
|
|
|
|
|
|
it('should match snapshot', () => {
|
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<SignatureRequestOriginal {...props} />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
2022-11-30 16:34:50 +01:00
|
|
|
|
2023-01-31 16:29:23 +01:00
|
|
|
it('should render navigation', () => {
|
|
|
|
render();
|
|
|
|
const navigationContainer = screen.queryByTestId('navigation-container');
|
|
|
|
expect(navigationContainer).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
2022-11-30 16:34:50 +01:00
|
|
|
it('should render eth sign screen', () => {
|
|
|
|
render();
|
|
|
|
expect(screen.getByText('Signature request')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render warning for eth sign when sign button clicked', () => {
|
|
|
|
render();
|
2023-01-23 16:22:12 +01:00
|
|
|
const signButton = screen.getByTestId('page-container-footer-next');
|
2022-11-30 16:34:50 +01:00
|
|
|
|
|
|
|
fireEvent.click(signButton);
|
|
|
|
expect(screen.getByText('Your funds may be at risk')).toBeInTheDocument();
|
|
|
|
});
|
2022-08-16 17:25:30 +02:00
|
|
|
});
|