Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
2022-10-04 18:55:05 +02:00
|
|
|
import thunk from 'redux-thunk';
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
renderWithProvider,
|
|
|
|
createSwapsMockStore,
|
2022-10-04 18:55:05 +02:00
|
|
|
setBackgroundConnection,
|
|
|
|
fireEvent,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../../../test/jest';
|
2022-10-04 18:55:05 +02:00
|
|
|
import {
|
2023-01-24 17:38:01 +01:00
|
|
|
Slippage,
|
2022-10-04 18:55:05 +02:00
|
|
|
QUOTES_EXPIRED_ERROR,
|
|
|
|
SWAP_FAILED_ERROR,
|
|
|
|
ERROR_FETCHING_QUOTES,
|
|
|
|
QUOTES_NOT_AVAILABLE_ERROR,
|
|
|
|
CONTRACT_DATA_DISABLED_ERROR,
|
|
|
|
OFFLINE_FOR_MAINTENANCE,
|
|
|
|
} from '../../../../shared/constants/swaps';
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
import AwaitingSwap from '.';
|
|
|
|
|
2022-10-04 18:55:05 +02:00
|
|
|
const middleware = [thunk];
|
|
|
|
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
const createProps = (customProps = {}) => {
|
|
|
|
return {
|
|
|
|
swapComplete: false,
|
|
|
|
txHash: 'txHash',
|
2021-07-30 13:35:30 +02:00
|
|
|
tokensReceived: 'tokens received:',
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
submittingSwap: true,
|
|
|
|
inputValue: 5,
|
2023-01-24 17:38:01 +01:00
|
|
|
maxSlippage: Slippage.default,
|
2022-11-04 17:14:43 +01:00
|
|
|
txId: 6571648590592143,
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
...customProps,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-10-04 18:55:05 +02:00
|
|
|
setBackgroundConnection({
|
|
|
|
stopPollingForQuotes: jest.fn(),
|
|
|
|
});
|
|
|
|
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
describe('AwaitingSwap', () => {
|
2023-02-02 21:37:53 +01:00
|
|
|
process.env.METAMASK_BUILD_TYPE = 'main';
|
|
|
|
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
it('renders the component with initial props', () => {
|
|
|
|
const store = configureMockStore()(createSwapsMockStore());
|
2022-10-04 18:55:05 +02:00
|
|
|
const { getByText, getByTestId } = renderWithProvider(
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
<AwaitingSwap {...createProps()} />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
expect(getByText('Processing')).toBeInTheDocument();
|
2022-10-04 18:55:05 +02:00
|
|
|
expect(getByText('USDC')).toBeInTheDocument();
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
expect(getByText('View in activity')).toBeInTheDocument();
|
|
|
|
expect(
|
2022-01-27 21:47:25 +01:00
|
|
|
document.querySelector('.awaiting-swap__main-description'),
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
).toMatchSnapshot();
|
2021-07-02 15:48:34 +02:00
|
|
|
expect(getByText('View in activity')).toBeInTheDocument();
|
2022-10-04 18:55:05 +02:00
|
|
|
expect(getByTestId('page-container-footer-next')).toBeInTheDocument();
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
});
|
2021-07-30 13:35:30 +02:00
|
|
|
|
|
|
|
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();
|
2022-10-04 18:55:05 +02:00
|
|
|
expect(getByText('tokens received: USDC')).toBeInTheDocument();
|
2021-09-24 19:14:07 +02:00
|
|
|
expect(getByText('View Swap at etherscan.io')).toBeInTheDocument();
|
2021-07-30 13:35:30 +02:00
|
|
|
expect(getByText('Create a new swap')).toBeInTheDocument();
|
|
|
|
});
|
2022-10-04 18:55:05 +02:00
|
|
|
|
|
|
|
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('metamask-flask.zendesk.com'));
|
|
|
|
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();
|
|
|
|
});
|
Increase Jest unit test coverage for the Swaps feature to ~25% (#10900)
* Swaps: Show a network name dynamically in a tooltip
* Replace âEthereumâ with â$1â, change âTestâ to âTestnetâ
* Replace ě´ë댏ě with $1
* Translate network names, use âEthereumâ by default if a translation is not available yet
* Reorder messages to resolve ESLint issues
* Add a snapshot test for the FeeCard component, increase Jest threshold
* Enable snapshot testing into external .snap files in ESLint
* Add the ânetworkNameEthereumâ key in ko/messages.json, remove default âEthereumâ value
* Throw an error if chain ID is not supported by the Swaps feature
* Use string literals when calling the `t` fn,
* Watch Jest tests silently (no React warnings in terminal, only errors)
* Add @testing-library/jest-dom, import it before running Jest tests
* Add snapshot testing of Swapsâ React components for happy paths, increase minimum threshold for Jest
* Add the test/jest folder for Jest setup and shared functions, use it in Swaps Jest tests
* Fix ESLint issues, update linting config
* Enable ESLint for .snap files (Jest snapshots), throw an error if a snapshot is bigger than 50 lines
* Donât run lint:fix for .snap files
* Move `createProps` outside of `describe` blocks, move store creation inside tests
* Use translations instead of keys, update a rendering function to load translations
* Make sure all Jest snapshots are shorter than 50 lines (default limit)
* Add / update props for Swaps tests
* Fix React warnings when running tests for Swaps
2021-04-21 21:34:35 +02:00
|
|
|
});
|