mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
95c37e1ba3
* feat: add yaml feature management Add yaml feature file per build type. Also add method to parse yaml and set enabled features env to true. The build process will then replace any process.env[feature] that exists on the config by its value * chore: add example for desktop * Added initial draft of build features * [TMP] Sync between computers * Is able to succesfully build stable extension with snaps feature * Removing var context from builds.yml * Add asssets to builds.yml * Minor bug fixes and removing debug logs * [WIP] Test changes * Removed TODOs * Fix regession bug Also * remove debug logs * merge Variables.set and Variables.setMany with an overload * Fix build, lint and a bunch of issues * Update LavaMoat policies * Re-add desktop build type * Fix some tests * Fix desktop build * Define some env variables used by MV3 * Fix lint * Fix remove-fenced-code tests * Fix README typo * Move new code * Fix missing asset copy * Move Jest env setup * Fix path for test after rebase * Fix code fences * Fix fencing and LavaMoat policies * Fix MMI code-fencing after rebase * Fix MMI code fencing after merge * Fix more MMI code fencing --------- Co-authored-by: cryptotavares <joao.tavares@consensys.net> Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com> Co-authored-by: Brad Decker <bhdecker84@gmail.com>
174 lines
5.6 KiB
JavaScript
174 lines
5.6 KiB
JavaScript
import React from 'react';
|
|
import configureMockStore from 'redux-mock-store';
|
|
import thunk from 'redux-thunk';
|
|
|
|
import {
|
|
renderWithProvider,
|
|
createSwapsMockStore,
|
|
setBackgroundConnection,
|
|
fireEvent,
|
|
} from '../../../../test/jest';
|
|
import {
|
|
Slippage,
|
|
QUOTES_EXPIRED_ERROR,
|
|
SWAP_FAILED_ERROR,
|
|
ERROR_FETCHING_QUOTES,
|
|
QUOTES_NOT_AVAILABLE_ERROR,
|
|
CONTRACT_DATA_DISABLED_ERROR,
|
|
OFFLINE_FOR_MAINTENANCE,
|
|
} from '../../../../shared/constants/swaps';
|
|
import AwaitingSwap from '.';
|
|
|
|
const middleware = [thunk];
|
|
|
|
const createProps = (customProps = {}) => {
|
|
return {
|
|
swapComplete: false,
|
|
txHash: 'txHash',
|
|
tokensReceived: 'tokens received:',
|
|
submittingSwap: true,
|
|
inputValue: 5,
|
|
maxSlippage: Slippage.default,
|
|
txId: 6571648590592143,
|
|
...customProps,
|
|
};
|
|
};
|
|
|
|
setBackgroundConnection({
|
|
stopPollingForQuotes: jest.fn(),
|
|
});
|
|
|
|
describe('AwaitingSwap', () => {
|
|
process.env.METAMASK_BUILD_TYPE = 'main';
|
|
|
|
it('renders the component with initial props', () => {
|
|
const store = configureMockStore()(createSwapsMockStore());
|
|
const { getByText, getByTestId } = renderWithProvider(
|
|
<AwaitingSwap {...createProps()} />,
|
|
store,
|
|
);
|
|
expect(getByText('Processing')).toBeInTheDocument();
|
|
expect(getByText('USDC')).toBeInTheDocument();
|
|
expect(getByText('View in activity')).toBeInTheDocument();
|
|
expect(
|
|
document.querySelector('.awaiting-swap__main-description'),
|
|
).toMatchSnapshot();
|
|
expect(getByText('View in activity')).toBeInTheDocument();
|
|
expect(getByTestId('page-container-footer-next')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders the component with for completed swap', () => {
|
|
const store = configureMockStore()(createSwapsMockStore());
|
|
const { getByText } = renderWithProvider(
|
|
<AwaitingSwap {...createProps({ swapComplete: true })} />,
|
|
store,
|
|
);
|
|
expect(getByText('Transaction complete')).toBeInTheDocument();
|
|
expect(getByText('tokens received: USDC')).toBeInTheDocument();
|
|
expect(getByText('View Swap at etherscan.io')).toBeInTheDocument();
|
|
expect(getByText('Create a new swap')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders the component with the "OFFLINE_FOR_MAINTENANCE" error', () => {
|
|
const store = configureMockStore(middleware)(createSwapsMockStore());
|
|
const props = createProps({
|
|
errorKey: OFFLINE_FOR_MAINTENANCE,
|
|
});
|
|
const { getByText } = renderWithProvider(
|
|
<AwaitingSwap {...props} />,
|
|
store,
|
|
);
|
|
expect(getByText('Offline for maintenance')).toBeInTheDocument();
|
|
expect(
|
|
getByText(
|
|
'MetaMask Swaps is undergoing maintenance. Please check back later.',
|
|
),
|
|
).toBeInTheDocument();
|
|
expect(getByText('Close')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders the component with the "SWAP_FAILED_ERROR" error', () => {
|
|
const store = configureMockStore(middleware)(createSwapsMockStore());
|
|
const props = createProps({
|
|
errorKey: SWAP_FAILED_ERROR,
|
|
});
|
|
const { getByText } = renderWithProvider(
|
|
<AwaitingSwap {...props} />,
|
|
store,
|
|
);
|
|
expect(getByText('Swap failed')).toBeInTheDocument();
|
|
fireEvent.click(getByText('support.metamask.io'));
|
|
expect(getByText('Try again')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders the component with the "QUOTES_EXPIRED_ERROR" error', () => {
|
|
const store = configureMockStore(middleware)(createSwapsMockStore());
|
|
const props = createProps({
|
|
errorKey: QUOTES_EXPIRED_ERROR,
|
|
});
|
|
const { getByText } = renderWithProvider(
|
|
<AwaitingSwap {...props} />,
|
|
store,
|
|
);
|
|
expect(getByText('Quotes timeout')).toBeInTheDocument();
|
|
expect(
|
|
getByText('Please request new quotes to get the latest rates.'),
|
|
).toBeInTheDocument();
|
|
expect(getByText('Try again')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders the component with the "ERROR_FETCHING_QUOTES" error', () => {
|
|
const store = configureMockStore(middleware)(createSwapsMockStore());
|
|
const props = createProps({
|
|
errorKey: ERROR_FETCHING_QUOTES,
|
|
});
|
|
const { getByText } = renderWithProvider(
|
|
<AwaitingSwap {...props} />,
|
|
store,
|
|
);
|
|
expect(getByText('Error fetching quotes')).toBeInTheDocument();
|
|
expect(
|
|
getByText(
|
|
'Hmmm... something went wrong. Try again, or if errors persist, contact customer support.',
|
|
),
|
|
).toBeInTheDocument();
|
|
expect(getByText('Back')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders the component with the "QUOTES_NOT_AVAILABLE_ERROR" error', () => {
|
|
const store = configureMockStore(middleware)(createSwapsMockStore());
|
|
const props = createProps({
|
|
errorKey: QUOTES_NOT_AVAILABLE_ERROR,
|
|
});
|
|
const { getByText } = renderWithProvider(
|
|
<AwaitingSwap {...props} />,
|
|
store,
|
|
);
|
|
expect(getByText('No quotes available')).toBeInTheDocument();
|
|
expect(
|
|
getByText('Try adjusting the amount or slippage settings and try again.'),
|
|
).toBeInTheDocument();
|
|
expect(getByText('Try again')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders the component with the "CONTRACT_DATA_DISABLED_ERROR" error', () => {
|
|
const store = configureMockStore(middleware)(createSwapsMockStore());
|
|
const props = createProps({
|
|
errorKey: CONTRACT_DATA_DISABLED_ERROR,
|
|
});
|
|
const { getByText } = renderWithProvider(
|
|
<AwaitingSwap {...props} />,
|
|
store,
|
|
);
|
|
expect(
|
|
getByText('Contract data is not enabled on your Ledger'),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
getByText(
|
|
'In the Ethereum app on your Ledger, go to "Settings" and allow contract data. Then, try your swap again.',
|
|
),
|
|
).toBeInTheDocument();
|
|
expect(getByText('Try again')).toBeInTheDocument();
|
|
});
|
|
});
|