2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
2021-06-23 23:35:25 +02:00
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
|
|
|
|
import { fireEvent } from '@testing-library/react';
|
2022-07-01 15:58:35 +02:00
|
|
|
import { SEND_STAGES } from '../../../ducks/send';
|
2021-06-23 23:35:25 +02:00
|
|
|
import { renderWithProvider } from '../../../../test/jest';
|
2022-03-16 23:15:03 +01:00
|
|
|
import { ASSET_TYPES } from '../../../../shared/constants/transaction';
|
2022-07-01 15:58:35 +02:00
|
|
|
import {
|
|
|
|
getInitialSendStateWithExistingTxState,
|
|
|
|
INITIAL_SEND_STATE_FOR_EXISTING_DRAFT,
|
|
|
|
} from '../../../../test/jest/mocks';
|
2021-03-16 22:00:08 +01:00
|
|
|
import SendHeader from './send-header.component';
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
const middleware = [thunk];
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
jest.mock('react-router-dom', () => {
|
|
|
|
const original = jest.requireActual('react-router-dom');
|
|
|
|
return {
|
|
|
|
...original,
|
|
|
|
useHistory: () => ({
|
|
|
|
push: jest.fn(),
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-06-23 23:35:25 +02:00
|
|
|
});
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
describe('SendHeader Component', () => {
|
|
|
|
describe('Title', () => {
|
2021-08-20 17:44:41 +02:00
|
|
|
it('should render "Send to" for INACTIVE or ADD_RECIPIENT stages', () => {
|
2021-06-23 23:35:25 +02:00
|
|
|
const { getByText, rerender } = renderWithProvider(
|
|
|
|
<SendHeader />,
|
|
|
|
configureMockStore(middleware)({
|
2022-07-01 15:58:35 +02:00
|
|
|
send: INITIAL_SEND_STATE_FOR_EXISTING_DRAFT,
|
2021-06-23 23:35:25 +02:00
|
|
|
gas: { basicEstimateStatus: 'LOADING' },
|
|
|
|
history: { mostRecentOverviewPage: 'activity' },
|
|
|
|
}),
|
|
|
|
);
|
2021-08-20 17:44:41 +02:00
|
|
|
expect(getByText('Send to')).toBeTruthy();
|
2021-06-23 23:35:25 +02:00
|
|
|
rerender(
|
|
|
|
<SendHeader />,
|
|
|
|
configureMockStore(middleware)({
|
2022-07-01 15:58:35 +02:00
|
|
|
send: {
|
|
|
|
...INITIAL_SEND_STATE_FOR_EXISTING_DRAFT,
|
|
|
|
stage: SEND_STAGES.ADD_RECIPIENT,
|
|
|
|
},
|
2021-06-23 23:35:25 +02:00
|
|
|
gas: { basicEstimateStatus: 'LOADING' },
|
|
|
|
history: { mostRecentOverviewPage: 'activity' },
|
|
|
|
}),
|
|
|
|
);
|
2021-08-20 17:44:41 +02:00
|
|
|
expect(getByText('Send to')).toBeTruthy();
|
2021-06-23 23:35:25 +02:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
it('should render "Send" for DRAFT stage when asset type is NATIVE', () => {
|
|
|
|
const { getByText } = renderWithProvider(
|
|
|
|
<SendHeader />,
|
|
|
|
configureMockStore(middleware)({
|
|
|
|
send: {
|
2022-07-01 15:58:35 +02:00
|
|
|
...INITIAL_SEND_STATE_FOR_EXISTING_DRAFT,
|
2021-06-23 23:35:25 +02:00
|
|
|
stage: SEND_STAGES.DRAFT,
|
2022-07-01 15:58:35 +02:00
|
|
|
asset: {
|
|
|
|
...INITIAL_SEND_STATE_FOR_EXISTING_DRAFT.asset,
|
|
|
|
type: ASSET_TYPES.NATIVE,
|
|
|
|
},
|
2021-06-23 23:35:25 +02:00
|
|
|
},
|
|
|
|
gas: { basicEstimateStatus: 'LOADING' },
|
|
|
|
history: { mostRecentOverviewPage: 'activity' },
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
expect(getByText('Send')).toBeTruthy();
|
|
|
|
});
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
it('should render "Send Tokens" for DRAFT stage when asset type is TOKEN', () => {
|
|
|
|
const { getByText } = renderWithProvider(
|
|
|
|
<SendHeader />,
|
|
|
|
configureMockStore(middleware)({
|
|
|
|
send: {
|
2022-07-01 15:58:35 +02:00
|
|
|
...getInitialSendStateWithExistingTxState({
|
|
|
|
asset: {
|
|
|
|
type: ASSET_TYPES.TOKEN,
|
|
|
|
},
|
|
|
|
}),
|
2021-06-23 23:35:25 +02:00
|
|
|
stage: SEND_STAGES.DRAFT,
|
|
|
|
},
|
|
|
|
gas: { basicEstimateStatus: 'LOADING' },
|
|
|
|
history: { mostRecentOverviewPage: 'activity' },
|
|
|
|
}),
|
|
|
|
);
|
2022-08-08 21:01:38 +02:00
|
|
|
expect(getByText('Send tokens')).toBeTruthy();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
it('should render "Edit" for EDIT stage', () => {
|
|
|
|
const { getByText } = renderWithProvider(
|
|
|
|
<SendHeader />,
|
|
|
|
configureMockStore(middleware)({
|
|
|
|
send: {
|
2022-07-01 15:58:35 +02:00
|
|
|
...INITIAL_SEND_STATE_FOR_EXISTING_DRAFT,
|
2021-06-23 23:35:25 +02:00
|
|
|
stage: SEND_STAGES.EDIT,
|
|
|
|
},
|
|
|
|
gas: { basicEstimateStatus: 'LOADING' },
|
|
|
|
history: { mostRecentOverviewPage: 'activity' },
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-06-23 23:35:25 +02:00
|
|
|
expect(getByText('Edit')).toBeTruthy();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
describe('Cancel Button', () => {
|
|
|
|
it('has a cancel button in header', () => {
|
|
|
|
const { getByText } = renderWithProvider(
|
|
|
|
<SendHeader />,
|
|
|
|
configureMockStore(middleware)({
|
2022-07-01 15:58:35 +02:00
|
|
|
send: INITIAL_SEND_STATE_FOR_EXISTING_DRAFT,
|
2021-06-23 23:35:25 +02:00
|
|
|
gas: { basicEstimateStatus: 'LOADING' },
|
|
|
|
history: { mostRecentOverviewPage: 'activity' },
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
expect(getByText('Cancel')).toBeTruthy();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2022-08-08 21:01:38 +02:00
|
|
|
it('has button label changed to Cancel edit in editing stage', () => {
|
2021-09-17 06:37:50 +02:00
|
|
|
const { getByText } = renderWithProvider(
|
|
|
|
<SendHeader />,
|
|
|
|
configureMockStore(middleware)({
|
2022-07-01 15:58:35 +02:00
|
|
|
send: {
|
|
|
|
...INITIAL_SEND_STATE_FOR_EXISTING_DRAFT,
|
|
|
|
stage: SEND_STAGES.EDIT,
|
|
|
|
},
|
2021-09-17 06:37:50 +02:00
|
|
|
gas: { basicEstimateStatus: 'LOADING' },
|
|
|
|
history: { mostRecentOverviewPage: 'activity' },
|
|
|
|
}),
|
|
|
|
);
|
2022-08-08 21:01:38 +02:00
|
|
|
expect(getByText('Cancel edit')).toBeTruthy();
|
2021-09-17 06:37:50 +02:00
|
|
|
});
|
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
it('resets send state when clicked', () => {
|
|
|
|
const store = configureMockStore(middleware)({
|
2022-07-01 15:58:35 +02:00
|
|
|
send: INITIAL_SEND_STATE_FOR_EXISTING_DRAFT,
|
2021-06-23 23:35:25 +02:00
|
|
|
gas: { basicEstimateStatus: 'LOADING' },
|
|
|
|
history: { mostRecentOverviewPage: 'activity' },
|
|
|
|
});
|
|
|
|
const { getByText } = renderWithProvider(<SendHeader />, store);
|
|
|
|
const expectedActions = [
|
|
|
|
{ type: 'send/resetSendState', payload: undefined },
|
|
|
|
];
|
|
|
|
fireEvent.click(getByText('Cancel'));
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|