renaming test files (#351)

* renaming test files

* add eslint plugin jest

* enable linting rule and additional rules

* fix a metric ton of linting errors

* fix lint errors

* remove export
This commit is contained in:
Dexter Edwards 2022-05-12 13:32:14 +01:00 committed by GitHub
parent 7266ac9b37
commit 107171d46a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 204 additions and 129 deletions

View File

@ -1,7 +1,7 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nrwl/nx", "eslint-plugin-unicorn", "jsx-a11y"],
"plugins": ["@nrwl/nx", "eslint-plugin-unicorn", "jsx-a11y", "jest"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
@ -66,6 +66,13 @@
]
}
},
{
"files": ["*.spec.ts", "*.spec.tsx"],
"extends": ["plugin:@nrwl/nx/typescript", "plugin:jest/recommended"],
"rules": {
"jest/consistent-test-it": ["error", { "fn": "it" }]
}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"],

View File

@ -3,6 +3,7 @@ import { render, screen } from '@testing-library/react';
import { TableWithTbody, TableRow, TableHeader, TableCell } from './index';
describe('Renders all table components', () => {
it('Renders table components', () => {
render(
<TableWithTbody data-testid="test-table">
<TableRow data-testid="test-tr">
@ -17,6 +18,7 @@ describe('Renders all table components', () => {
expect(screen.getByTestId('test-th')).toHaveTextContent('Title');
expect(screen.getByTestId('test-td')).toHaveTextContent('Content');
});
});
describe('Table row', () => {
it('should include classes based on custom "modifier" prop', () => {

View File

@ -10,7 +10,7 @@ describe('Truncate', () => {
expect(screen.getByTestId('truncate-test')).toBeInTheDocument();
});
it('it truncates as expected', () => {
it('truncates as expected', () => {
const test = 'randomstringblahblah';
const startChars = 3;
const endChars = 3;
@ -25,7 +25,7 @@ describe('Truncate', () => {
expect(screen.getByText(expectedString)).toBeInTheDocument();
});
it("it doesn't truncate if the string is too short", () => {
it("doesn't truncate if the string is too short", () => {
const test = 'randomstringblahblah';
const startChars = test.length;
const endChars = test.length;

View File

@ -24,7 +24,7 @@ const generateJsx = (
);
};
test('Not connected', () => {
it('Not connected', () => {
render(generateJsx({ keypair: null } as VegaWalletContextShape, props));
const button = screen.getByRole('button');
@ -34,7 +34,7 @@ test('Not connected', () => {
expect(props.setManageDialog).not.toHaveBeenCalled();
});
test('Connected', () => {
it('Connected', () => {
render(
generateJsx(
{ keypair: { pub: '123456__123456' } } as VegaWalletContextShape,

View File

@ -62,7 +62,7 @@ function setup(mock = networkParamsQueryMock) {
);
}
test('Prompt to connect opens dialog', async () => {
it('Prompt to connect opens dialog', async () => {
mockHookValue = defaultHookValue;
setup();
@ -78,17 +78,19 @@ test('Prompt to connect opens dialog', async () => {
expect(screen.getByTestId('web3-connector-list')).toBeInTheDocument();
});
test('Error message is shown', async () => {
it('Error message is shown', async () => {
const message = 'Opps! An error';
mockHookValue = { ...defaultHookValue, error: new Error(message) };
setup();
expect(screen.getByText('Loading...')).toBeInTheDocument();
expect(await screen.findByText(`Something went wrong: ${message}`));
expect(
await screen.findByText(`Something went wrong: ${message}`)
).toBeInTheDocument();
expect(screen.queryByText('Child')).not.toBeInTheDocument();
});
test('Checks that chain ID matches app ID', async () => {
it('Checks that chain ID matches app ID', async () => {
const expectedChainId = 4;
mockHookValue = {
...defaultHookValue,
@ -98,11 +100,13 @@ test('Checks that chain ID matches app ID', async () => {
setup();
expect(screen.getByText('Loading...')).toBeInTheDocument();
expect(await screen.findByText(`This app only works on chain ID: 3`));
expect(
await screen.findByText(`This app only works on chain ID: 3`)
).toBeInTheDocument();
expect(screen.queryByText('Child')).not.toBeInTheDocument();
});
test('Passes ethereum config to children', async () => {
it('Passes ethereum config to children', async () => {
mockHookValue = {
...defaultHookValue,
isActive: true,
@ -117,7 +121,7 @@ test('Passes ethereum config to children', async () => {
).toBeInTheDocument();
});
test('Shows no config found message if the network parameter doesnt exist', async () => {
it('Shows no config found message if the network parameter doesnt exist', async () => {
const mock: MockedResponse<NetworkParamsQuery> = {
request: {
query: NETWORK_PARAMS_QUERY,
@ -141,7 +145,7 @@ test('Shows no config found message if the network parameter doesnt exist', asyn
).toBeInTheDocument();
});
test('Shows message if ethereum config could not be parsed', async () => {
it('Shows message if ethereum config could not be parsed', async () => {
const mock: MockedResponse<NetworkParamsQuery> = {
request: {
query: NETWORK_PARAMS_QUERY,

View File

@ -13,5 +13,6 @@ jest.mock('@vegaprotocol/ui-toolkit', () => {
describe('Index', () => {
it('should render successfully', () => {
render(<Index />);
expect(true).toBeTruthy();
});
});

View File

@ -21,14 +21,14 @@ const singleRow: Accounts_party_accounts = {
};
const singleRowData = [singleRow];
test('should render successfully', async () => {
it('should render successfully', async () => {
await act(async () => {
const { baseElement } = render(<AccountsTable data={[]} />);
expect(baseElement).toBeTruthy();
});
});
test('Render correct columns', async () => {
it('Render correct columns', async () => {
await act(async () => {
render(<AccountsTable data={singleRowData} />);
await waitFor(async () => {
@ -43,7 +43,7 @@ test('Render correct columns', async () => {
});
});
test('Correct formatting applied', async () => {
it('Correct formatting applied', async () => {
await act(async () => {
render(<AccountsTable data={singleRowData} />);
await waitFor(async () => {

View File

@ -57,7 +57,7 @@ function generateJsx() {
);
}
test('Deal ticket defaults', () => {
it('Deal ticket defaults', () => {
render(generateJsx());
// Assert defaults are used
@ -82,7 +82,7 @@ test('Deal ticket defaults', () => {
);
});
test('Can edit deal ticket', () => {
it('Can edit deal ticket', () => {
render(generateJsx());
// Asssert changing values
@ -113,7 +113,7 @@ test('Can edit deal ticket', () => {
);
});
test('Handles TIF select box dependent on order type', () => {
it('Handles TIF select box dependent on order type', () => {
render(generateJsx());
// Check only IOC and

View File

@ -36,7 +36,7 @@ function setup(
return renderHook(() => useOrderSubmit(market), { wrapper });
}
test('Has the correct default state', () => {
it('Has the correct default state', () => {
const { result } = setup();
expect(typeof result.current.submit).toEqual('function');
expect(typeof result.current.reset).toEqual('function');
@ -45,7 +45,7 @@ test('Has the correct default state', () => {
expect(result.current.transaction.error).toEqual(null);
});
test('Should not sendTx if no keypair', async () => {
it('Should not sendTx if no keypair', async () => {
const mockSendTx = jest.fn();
const { result } = setup({ sendTx: mockSendTx, keypairs: [], keypair: null });
await act(async () => {
@ -54,7 +54,7 @@ test('Should not sendTx if no keypair', async () => {
expect(mockSendTx).not.toHaveBeenCalled();
});
test('Should not sendTx side is not specified', async () => {
it('Should not sendTx side is not specified', async () => {
const mockSendTx = jest.fn();
const keypair = {
pub: '0x123',
@ -70,7 +70,7 @@ test('Should not sendTx side is not specified', async () => {
expect(mockSendTx).not.toHaveBeenCalled();
});
test('Create an Id if a signature is returned', async () => {
it('Create an Id if a signature is returned', async () => {
const signature =
'597a7706491e6523c091bab1e4d655b62c45a224e80f6cd92ac366aa5dd9a070cc7dd3c6919cb07b81334b876c662dd43bdbe5e827c8baa17a089feb654fab0b';
const expectedId =
@ -106,7 +106,7 @@ test('Create an Id if a signature is returned', async () => {
expect(result.current.id).toEqual(expectedId);
});
test('Should submit a correctly formatted order', async () => {
it('Should submit a correctly formatted order', async () => {
const mockSendTx = jest.fn().mockReturnValue(Promise.resolve({}));
const keypair = {
pub: '0x123',

View File

@ -44,7 +44,7 @@ beforeEach(() => {
};
});
test('Form validation', async () => {
it('Form validation', async () => {
const mockUseVegaWallet = useVegaWallet as jest.Mock;
mockUseVegaWallet.mockReturnValue({ keypair: null });
@ -77,26 +77,32 @@ test('Form validation', async () => {
fireEvent.change(screen.getByLabelText('From (Ethereum address)'), {
target: { value: invalidEthereumAddress },
});
expect(await screen.findByText('Invalid Ethereum address'));
expect(
await screen.findByText('Invalid Ethereum address')
).toBeInTheDocument();
const invalidVegaKey = 'abc';
fireEvent.change(screen.getByLabelText('To (Vega key)'), {
target: { value: invalidVegaKey },
});
expect(await screen.findByText('Invalid Vega key'));
expect(await screen.findByText('Invalid Vega key')).toBeInTheDocument();
// Max amount validation
const amountMoreThanAvailable = '11';
fireEvent.change(screen.getByLabelText('Amount'), {
target: { value: amountMoreThanAvailable },
});
expect(await screen.findByText('Insufficient amount in Ethereum wallet'));
expect(
await screen.findByText('Insufficient amount in Ethereum wallet')
).toBeInTheDocument();
const amountMoreThanLimit = '21';
fireEvent.change(screen.getByLabelText('Amount'), {
target: { value: amountMoreThanLimit },
});
expect(await screen.findByText('Amount is above permitted maximum'));
expect(
await screen.findByText('Amount is above permitted maximum')
).toBeInTheDocument();
rerender(
<DepositForm
@ -109,7 +115,9 @@ test('Form validation', async () => {
fireEvent.change(screen.getByLabelText('Amount'), {
target: { value: amountMoreThanAllowance },
});
expect(await screen.findByText('Amount is above approved amount'));
expect(
await screen.findByText('Amount is above approved amount')
).toBeInTheDocument();
// Min amount validation
rerender(<DepositForm {...props} selectedAsset={asset} />); // Rerender with selected asset so we have asset.decimals
@ -119,7 +127,7 @@ test('Form validation', async () => {
target: { value: amountLessThanMinViable },
});
expect(await screen.findByText('Value is below minimum'));
expect(await screen.findByText('Value is below minimum')).toBeInTheDocument();
rerender(
<DepositForm
@ -131,10 +139,10 @@ test('Form validation', async () => {
fireEvent.change(screen.getByLabelText('Amount'), {
target: { value: amountLessThanLimit },
});
expect(await screen.findByText('Value is below minimum'));
expect(await screen.findByText('Value is below minimum')).toBeInTheDocument();
});
test('Approval', () => {
it('Approval', () => {
const mockUseVegaWallet = useVegaWallet as jest.Mock;
mockUseVegaWallet.mockReturnValue({ keypair: null });
@ -156,7 +164,7 @@ test('Approval', () => {
expect(props.submitApprove).toHaveBeenCalled();
});
test('Deposit', async () => {
it('Deposit', async () => {
const vegaKey =
'f8885edfa7ffdb6ed996ca912e9258998e47bf3515c885cf3c63fb56b15de36f';
const mockUseVegaWallet = useVegaWallet as jest.Mock;

View File

@ -7,7 +7,7 @@ import { forwardRef } from 'react';
jest.mock('./order-list');
test('Renders a loading state while awaiting orders', () => {
it('Renders a loading state while awaiting orders', () => {
jest.spyOn(useDataProviderHook, 'useDataProvider').mockReturnValue({
data: [],
loading: true,
@ -17,7 +17,7 @@ test('Renders a loading state while awaiting orders', () => {
expect(screen.getByText('Loading...')).toBeInTheDocument();
});
test('Renders an error state', () => {
it('Renders an error state', () => {
const errorMsg = 'Oops! An Error';
jest.spyOn(useDataProviderHook, 'useDataProvider').mockReturnValue({
data: [],
@ -30,7 +30,7 @@ test('Renders an error state', () => {
).toBeInTheDocument();
});
test('Renders the order list if orders provided', async () => {
it('Renders the order list if orders provided', async () => {
// @ts-ignore Orderlist is read only but we need to override with the forwardref to
// avoid warnings about padding refs
orderListMock.OrderList = forwardRef(() => <div>OrderList</div>);

View File

@ -10,7 +10,7 @@ import {
} from '@vegaprotocol/types';
import { OrderList } from './order-list';
test('No orders message shown', async () => {
it('No orders message shown', async () => {
await act(async () => {
render(<OrderList data={[]} />);
});
@ -75,7 +75,7 @@ const limitOrder: Orders_party_orders = {
rejectionReason: null,
};
test('Correct columns are rendered', async () => {
it('Correct columns are rendered', async () => {
await act(async () => {
render(<OrderList data={[marketOrder]} />);
});
@ -94,7 +94,7 @@ test('Correct columns are rendered', async () => {
]);
});
test('Correct formatting applied for market order', async () => {
it('Correct formatting applied for market order', async () => {
await act(async () => {
render(<OrderList data={[marketOrder]} />);
});
@ -115,7 +115,7 @@ test('Correct formatting applied for market order', async () => {
});
});
test('Correct formatting applied for GTT limit order', async () => {
it('Correct formatting applied for GTT limit order', async () => {
await act(async () => {
render(<OrderList data={[limitOrder]} />);
});
@ -137,7 +137,7 @@ test('Correct formatting applied for GTT limit order', async () => {
});
});
test('Correct formatting applied for a rejected order', async () => {
it('Correct formatting applied for a rejected order', async () => {
const rejectedOrder = {
...marketOrder,
status: OrderStatus.Rejected,

View File

@ -55,14 +55,14 @@ const singleRow: Positions_party_positions = {
};
const singleRowData = [singleRow];
test('should render successfully', async () => {
it('should render successfully', async () => {
await act(async () => {
const { baseElement } = render(<PositionsTable data={[]} />);
expect(baseElement).toBeTruthy();
});
});
test('Render correct columns', async () => {
it('Render correct columns', async () => {
await act(async () => {
render(<PositionsTable data={singleRowData} />);
await waitFor(async () => {
@ -83,7 +83,7 @@ test('Render correct columns', async () => {
});
});
test('Correct formatting applied', async () => {
it('Correct formatting applied', async () => {
await act(async () => {
render(<PositionsTable data={singleRowData} />);
await waitFor(async () => {

View File

@ -29,7 +29,7 @@ function setup(items: Items, rowNodes: Items) {
return gridApiMock;
}
test('Adds items', () => {
it('Adds items', () => {
const gridApiMock = setup(items, []);
expect(gridApiMock.applyTransaction).toHaveBeenCalledWith({
update: [],
@ -38,7 +38,7 @@ test('Adds items', () => {
});
});
test('Doesnt update rows without changes', () => {
it('Doesnt update rows without changes', () => {
const rowNodes: Array<{ id: string; value: number }> = [...items];
const gridApiMock = setup(items, rowNodes);
expect(gridApiMock.applyTransaction).toHaveBeenCalledWith({
@ -48,7 +48,7 @@ test('Doesnt update rows without changes', () => {
});
});
test('Update rows with changes', () => {
it('Update rows with changes', () => {
const rowNodes = [...items];
const updatedItems = [
{ id: '1', value: 10 },
@ -62,7 +62,7 @@ test('Update rows with changes', () => {
});
});
test('Updates and adds at the same time', () => {
it('Updates and adds at the same time', () => {
const newItem = { id: '3', value: 3 };
const updatedItem = { id: '2', value: 20 };
const gridApiMock = setup([newItem, updatedItem], [...items]);

View File

@ -1,6 +1,6 @@
import { determineId } from './determine-id';
test('It produces a known result for an ID', () => {
it('produces a known result for an ID', () => {
const res = determineId(
'cfe592d169f87d0671dd447751036d0dddc165b9c4b65e5a5060e2bbadd1aa726d4cbe9d3c3b327bcb0bff4f83999592619a2493f9bbd251fae99ce7ce766909'
);

View File

@ -16,7 +16,7 @@ const trade: TradeFields = {
},
};
test('Correct columns are rendered', async () => {
it('Correct columns are rendered', async () => {
await act(async () => {
render(<TradesTable data={[trade]} />);
});
@ -26,7 +26,7 @@ test('Correct columns are rendered', async () => {
expect(headers.map((h) => h.textContent?.trim())).toEqual(expectedHeaders);
});
test('Columns are formatted', async () => {
it('Number and data columns are formatted', async () => {
await act(async () => {
render(<TradesTable data={[trade]} />);
});
@ -42,7 +42,7 @@ test('Columns are formatted', async () => {
});
});
test('Columns are formatted', async () => {
it('Price and size columns are formatted', async () => {
const trade2 = {
...trade,
id: 'trade-id-2',

View File

@ -2,12 +2,12 @@ import { render, screen } from '@testing-library/react';
import { Callout } from '.';
import { Intent } from '../../utils/intent';
test('It renders content within callout', () => {
it('renders content within callout', () => {
render(<Callout>Content</Callout>);
expect(screen.getByTestId('callout')).toHaveTextContent('Content');
});
test('It renders title and icon', () => {
it('renders title and icon', () => {
render(<Callout iconName="endorsed" title="title" />);
expect(
screen.getByTestId('callout').querySelector('svg')
@ -17,14 +17,14 @@ test('It renders title and icon', () => {
const intents = Object.values(Intent).filter((i) => i !== Intent.Progress);
test.each(intents)('Applies class for %s', (intent) => {
it.each(intents)('Applies class for %s', (intent) => {
render(<Callout intent={intent} />);
expect(screen.getByTestId('callout')).toHaveClass(
`shadow-intent-${intent.toLowerCase()}`
);
});
test(`Applies class for progress`, () => {
it(`Applies class for progress`, () => {
render(<Callout intent={Intent.Progress} />);
expect(screen.getByTestId('callout')).toHaveClass(
'shadow-black',

View File

@ -14,7 +14,7 @@ afterAll(() => {
jest.useRealTimers();
});
test('CopyWithTooltip', async () => {
it('CopyWithTooltip', async () => {
const copyText = 'Text to be copied';
render(
<CopyWithTooltip text={copyText}>

View File

@ -1,22 +1,22 @@
import { render, screen } from '@testing-library/react';
import { EtherscanLink } from '.';
test('It renders a link with the text', () => {
it('renders a link with the text', () => {
render(<EtherscanLink text="foo" tx="tx" />);
expect(screen.getByText('foo')).toBeInTheDocument();
});
test('It renders a link with the tx hash if no text is provided', () => {
it('renders a link with the tx hash if no text is provided', () => {
render(<EtherscanLink tx="tx" />);
expect(screen.getByText('tx')).toBeInTheDocument();
});
test('It renders a link with the address if no text is provided', () => {
it('renders a link with the address if no text is provided', () => {
render(<EtherscanLink address="address" />);
expect(screen.getByText('address')).toBeInTheDocument();
});
test('It links to etherscan address', () => {
it('links to etherscan address', () => {
const hash = 'hash';
render(<EtherscanLink address={hash} />);
expect(screen.getByTestId('etherscan-link')).toHaveAttribute(
@ -25,7 +25,7 @@ test('It links to etherscan address', () => {
);
});
test('It links to etherscan transaction', () => {
it('links to etherscan transaction', () => {
const hash = 'hash';
render(<EtherscanLink tx={hash} />);
expect(screen.getByTestId('etherscan-link')).toHaveAttribute(

View File

@ -1,8 +1,6 @@
import { render, screen } from '@testing-library/react';
import { theme } from '@vegaprotocol/tailwindcss-config';
import { Sparkline } from './sparkline';
export const Colors = theme.colors;
const props = {
data: [

View File

@ -1,7 +1,7 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { Tooltip } from './tooltip';
test('Renders a tooltip', async () => {
it('Renders a tooltip', async () => {
const props = {
description: 'description',
children: <button>Tooltip</button>,
@ -13,7 +13,7 @@ test('Renders a tooltip', async () => {
expect(await screen.findByRole('tooltip')).toBeInTheDocument();
});
test('Doesnt render a tooltip if no description provided', () => {
it('Doesnt render a tooltip if no description provided', () => {
const props = {
description: undefined,
children: <button>Tooltip</button>,

View File

@ -1,6 +1,6 @@
import { includesLeftPadding, includesRightPadding } from './class-names';
test('includesLeftPadding detects class name which affects left padding', () => {
it('includesLeftPadding detects class name which affects left padding', () => {
expect(includesLeftPadding()).toEqual(false);
expect(includesLeftPadding('')).toEqual(false);
expect(includesLeftPadding('pl-8')).toEqual(true);
@ -19,7 +19,7 @@ test('includesLeftPadding detects class name which affects left padding', () =>
expect(includesLeftPadding('apx-16')).toEqual(false);
});
test('includesRightPadding detects class name which affects right padding', () => {
it('includesRightPadding detects class name which affects right padding', () => {
expect(includesRightPadding()).toEqual(false);
expect(includesRightPadding('')).toEqual(false);
expect(includesRightPadding('pr-8')).toEqual(true);

View File

@ -46,7 +46,7 @@ function generateJSX(
);
}
test('Renders list of connectors', () => {
it('Renders list of connectors', () => {
const { container, rerender } = render(generateJSX());
expect(container).toBeEmptyDOMElement();
rerender(generateJSX({ dialogOpen: true }));
@ -69,7 +69,7 @@ const fillInForm = () => {
return { wallet: walletValue, passphrase: passphraseValue };
};
test('Successful connection using rest auth form', async () => {
it('Successful connection using rest auth form', async () => {
const spy = jest
.spyOn(defaultProps.connectors['rest'] as RestConnector, 'authenticate')
.mockImplementation(() => Promise.resolve({ success: true, error: null }));
@ -97,7 +97,7 @@ test('Successful connection using rest auth form', async () => {
expect(defaultProps.setDialogOpen).toHaveBeenCalledWith(false);
});
test('Unsuccessful connection using rest auth form', async () => {
it('Unsuccessful connection using rest auth form', async () => {
// Error from service
let spy = jest
.spyOn(defaultProps.connectors['rest'] as RestConnector, 'authenticate')

View File

@ -1,3 +1,4 @@
/* eslint-disable jest/no-conditional-expect */
import { fireEvent, render, screen, within } from '@testing-library/react';
import { VegaWalletContext } from './context';
import type { VegaWalletContextShape, VegaKeyExtended } from './context';
@ -41,7 +42,7 @@ const generateJsx = (
);
};
test('Shows list of available keys and can disconnect', () => {
it('Shows list of available keys and can disconnect', () => {
render(generateJsx(context as VegaWalletContextShape, props));
const list = screen.getByTestId('keypair-list');

View File

@ -50,7 +50,7 @@ const generateJSX = () => (
</VegaWalletProvider>
);
test('Can connect, disconnect and retrieve keypairs', async () => {
it('Can connect, disconnect and retrieve keypairs', async () => {
const mockKeypairs = [{ pub: 'public key 1' }, { pub: 'public key 2' }];
jest
.spyOn(restConnector, 'connect')

View File

@ -24,7 +24,7 @@ function setup(context?: Partial<VegaWalletContextShape>) {
return renderHook(() => useVegaTransaction(), { wrapper });
}
test('Has the correct default state', () => {
it('Has the correct default state', () => {
const { result } = setup();
expect(result.current.transaction.status).toEqual(VegaTxStatus.Default);
expect(result.current.transaction.txHash).toEqual(null);
@ -34,7 +34,7 @@ test('Has the correct default state', () => {
expect(typeof result.current.send).toEqual('function');
});
test('If provider returns null status should be default', async () => {
it('If provider returns null status should be default', async () => {
const mockSendTx = jest.fn().mockReturnValue(Promise.resolve(null));
const { result } = setup({ sendTx: mockSendTx });
await act(async () => {
@ -43,7 +43,7 @@ test('If provider returns null status should be default', async () => {
expect(result.current.transaction.status).toEqual(VegaTxStatus.Default);
});
test('Handles a single error', async () => {
it('Handles a single error', async () => {
const errorMessage = 'Oops error!';
const mockSendTx = jest
.fn()
@ -56,7 +56,7 @@ test('Handles a single error', async () => {
expect(result.current.transaction.error).toEqual({ error: errorMessage });
});
test('Handles multiple errors', async () => {
it('Handles multiple errors', async () => {
const errorObj = {
errors: {
something: 'Went wrong!',
@ -71,7 +71,7 @@ test('Handles multiple errors', async () => {
expect(result.current.transaction.error).toEqual(errorObj);
});
test('Returns the signature if successful', async () => {
it('Returns the signature if successful', async () => {
const successObj = {
tx: {
inputData: 'input-data',

View File

@ -26,7 +26,7 @@ const generateJsx = (moreProps?: Partial<TransactionDialogProps>) => {
return <TransactionDialog {...props} {...moreProps} />;
};
test('Opens when tx starts and closes if the user rejects the tx', () => {
it('Opens when tx starts and closes if the user rejects the tx', () => {
const { container, rerender } = render(generateJsx());
// Dialog closed by default
@ -47,7 +47,7 @@ test('Opens when tx starts and closes if the user rejects the tx', () => {
expect(container).toBeEmptyDOMElement();
});
test('Doesn\t repoen if user dismissed the dialog', () => {
it('Doesn\t repoen if user dismissed the dialog', () => {
const { container, rerender } = render(
generateJsx({ status: EthTxStatus.Pending })
);
@ -62,7 +62,7 @@ test('Doesn\t repoen if user dismissed the dialog', () => {
expect(container).toBeEmptyDOMElement();
});
test('Dialog states', () => {
it('Dialog states', () => {
const { rerender } = render(generateJsx({ status: EthTxStatus.Requested }));
expect(screen.getByText('Confirm transaction')).toBeInTheDocument();
expect(screen.getByText('Confirm transaction in wallet')).toBeInTheDocument();
@ -89,7 +89,7 @@ test('Dialog states', () => {
expect(screen.getByText(errorMsg)).toBeInTheDocument();
});
test('Success state waits for confirmation event if provided', () => {
it('Success state waits for confirmation event if provided', () => {
const { rerender } = render(
generateJsx({ status: EthTxStatus.Complete, confirmed: false })
);

View File

@ -5,7 +5,7 @@ import { EthTxStatus } from './use-ethereum-transaction';
import type { ReactNode } from 'react';
import { useEthereumTransaction } from './use-ethereum-transaction';
import type { ethers } from 'ethers';
import { EthereumError } from '../lib/ethereum-error';
import { EthereumError } from './ethereum-error';
beforeAll(() => {
jest.useFakeTimers();
@ -56,7 +56,7 @@ function setup(perform: () => void) {
);
}
test('Ethereum transaction flow', async () => {
it('Ethereum transaction flow', async () => {
const { result } = setup(() => {
return mockContract.depositAsset({
assetSource: 'asset-source',
@ -114,7 +114,7 @@ test('Ethereum transaction flow', async () => {
});
});
test('Error handling', async () => {
it('Error handling', async () => {
const { result } = setup(() => {
throw new EthereumError(errorMsg, 500);
});

View File

@ -16,7 +16,7 @@ const props = {
desiredChainId: 3,
};
test('Dialog can be open or closed', () => {
it('Dialog can be open or closed', () => {
const { container, rerender } = render(<Web3ConnectDialog {...props} />);
expect(container).toBeEmptyDOMElement();
rerender(<Web3ConnectDialog {...props} dialogOpen={true} />);
@ -26,7 +26,7 @@ test('Dialog can be open or closed', () => {
).toBeInTheDocument();
});
test('Renders connection options', async () => {
it('Renders connection options', async () => {
const spyOnConnect = jest
.spyOn(foo, 'activate')
.mockReturnValue(Promise.resolve());

View File

@ -8,7 +8,7 @@ const [foo, fooHooks] = initializeConnector((actions) => new MetaMask(actions));
const connectors: [MetaMask, Web3ReactHooks][] = [[foo, fooHooks]];
test('Renders children', async () => {
it('Renders children', async () => {
await act(async () => {
render(
<Web3Provider connectors={connectors}>

View File

@ -24,7 +24,7 @@ function setup(mocks?: MockedResponse[]) {
return renderHook(() => useCompleteWithdraw(), { wrapper });
}
test('Should perform the Ethereum transaction with the fetched approval', async () => {
it('Should perform the Ethereum transaction with the fetched approval', async () => {
const withdrawalId = 'withdrawal-id';
const erc20WithdrawalApproval: Erc20Approval_erc20WithdrawalApproval = {
__typename: 'Erc20WithdrawalApproval',
@ -62,7 +62,7 @@ test('Should perform the Ethereum transaction with the fetched approval', async
});
});
test('Captures an error if the erc20Withdrawal is not found', async () => {
it('Captures an error if the erc20Withdrawal is not found', async () => {
const withdrawalId = 'withdrawal-id';
const mockERC20Approval: MockedResponse<Erc20Approval> = {
request: {
@ -93,7 +93,7 @@ test('Captures an error if the erc20Withdrawal is not found', async () => {
});
});
test('Captures an error if erc20 approval query fails', async () => {
it('Captures an error if erc20 approval query fails', async () => {
const withdrawalId = 'withdrawal-id';
const mockERC20Approval: MockedResponse<Erc20Approval> = {
request: {

View File

@ -102,7 +102,7 @@ beforeEach(() => {
};
});
test('Creates withdrawal and immediately submits Ethereum transaction', async () => {
it('Creates withdrawal and immediately submits Ethereum transaction', async () => {
const { result } = setup([mockERC20Approval]);
await act(async () => {
@ -146,7 +146,7 @@ test('Creates withdrawal and immediately submits Ethereum transaction', async ()
);
});
test('Doesnt perform Ethereum tx if cancelled', async () => {
it('Doesnt perform Ethereum tx if cancelled', async () => {
const { result } = setup([mockERC20Approval], true);
await act(async () => {
@ -167,7 +167,7 @@ test('Doesnt perform Ethereum tx if cancelled', async () => {
expect(mockPerform).not.toHaveBeenCalled();
});
test('Reset will reset both transactions', async () => {
it('Reset will reset both transactions', async () => {
const { result } = setup([mockERC20Approval]);
await act(async () => {

View File

@ -11,7 +11,7 @@ import type {
} from './__generated__/Withdrawals';
describe('updateQuery', () => {
test('Updates existing withdrawals', () => {
it('Updates existing withdrawals', () => {
const withdrawal = generateWithdrawal({
id: '1',
status: WithdrawalStatus.Open,
@ -32,7 +32,7 @@ describe('updateQuery', () => {
});
});
test('Adds new withdrawals', () => {
it('Adds new withdrawals', () => {
const withdrawal = generateWithdrawal({
id: '1',
amount: '100',
@ -53,7 +53,7 @@ describe('updateQuery', () => {
});
});
test('Creates new party if not present', () => {
it('Creates new party if not present', () => {
const withdrawalUpdate = generateWithdrawal({
id: '2',
});
@ -67,7 +67,7 @@ describe('updateQuery', () => {
});
});
test('Handles updates and inserts simultaneously', () => {
it('Handles updates and inserts simultaneously', () => {
const withdrawal1 = generateWithdrawal({
id: '1',
status: WithdrawalStatus.Open,

View File

@ -35,7 +35,7 @@ const generateJsx = (override?: PartialDeep<WithdrawDialogProps>) => {
return <WithdrawDialog {...props} />;
};
test('Dialog transaction states', () => {
it('Dialog transaction states', () => {
const { rerender } = render(
generateJsx({
vegaTx: {

View File

@ -29,7 +29,7 @@ beforeEach(() => {
const generateJsx = (props: WithdrawFormProps) => <WithdrawForm {...props} />;
test('Validation', async () => {
it('Validation', async () => {
const { rerender } = render(generateJsx(props));
fireEvent.submit(screen.getByTestId('withdraw-form'));
@ -86,7 +86,7 @@ test('Validation', async () => {
});
});
test('Use max button', () => {
it('Use max button', () => {
const asset = props.assets[0];
render(generateJsx({ ...props, selectedAsset: asset }));
@ -97,7 +97,7 @@ test('Use max button', () => {
);
});
test('Use connected Ethereum account', () => {
it('Use connected Ethereum account', () => {
render(generateJsx({ ...props, ethereumAccount: ethereumAddress }));
fireEvent.click(screen.getByText('Use connected'));

View File

@ -47,7 +47,7 @@ const generateJsx = (props: WithdrawManagerProps) => (
<WithdrawManager {...props} />
);
test('Valid form submission opens transaction dialog', async () => {
it('Valid form submission opens transaction dialog', async () => {
render(generateJsx(props));
submitValid();
expect(await screen.findByRole('dialog')).toBeInTheDocument();
@ -59,7 +59,7 @@ test('Valid form submission opens transaction dialog', async () => {
});
});
test('Expected Ethereum error closes the dialog', async () => {
it('Expected Ethereum error closes the dialog', async () => {
const { rerender } = render(generateJsx(props));
submitValid();
expect(await screen.findByRole('dialog')).toBeInTheDocument();
@ -75,7 +75,7 @@ test('Expected Ethereum error closes the dialog', async () => {
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
});
test('Correct min max values provided to form', async () => {
it('Correct min max values provided to form', async () => {
render(generateJsx(props));
// Set other fields to be valid
@ -103,11 +103,11 @@ test('Correct min max values provided to form', async () => {
target: { value: '2' },
});
fireEvent.submit(screen.getByTestId('withdraw-form'));
expect(await screen.findByText('Value is above maximum'));
expect(await screen.findByText('Value is above maximum')).toBeInTheDocument();
expect(mockSubmit).not.toBeCalled();
});
test('Initial asset id can preselect asset', async () => {
it('Initial asset id can preselect asset', async () => {
const asset = props.assets[0];
render(generateJsx({ ...props, initialAssetId: asset.id }));
expect(screen.getByLabelText('Asset')).toHaveValue(asset.id);

View File

@ -21,7 +21,7 @@ const generateJsx = (props: WithdrawalsTableProps) => (
</MockedProvider>
);
test('Renders the correct columns', async () => {
it('Renders the correct columns', async () => {
const withdrawal = generateWithdrawal();
await act(async () => {
render(generateJsx({ withdrawals: [withdrawal] }));
@ -66,49 +66,49 @@ describe('StatusCell', () => {
};
});
test('Open', () => {
it('Open', () => {
props.value = WithdrawalStatus.Finalized;
props.data.pendingOnForeignChain = false;
props.data.txHash = null;
render(<StatusCell {...props} />);
expect(screen.getByText('Open'));
expect(screen.getByText('Open')).toBeInTheDocument();
fireEvent.click(screen.getByText('Complete', { selector: 'button' }));
expect(mockComplete).toHaveBeenCalled();
});
test('Pending', () => {
it('Pending', () => {
props.value = WithdrawalStatus.Finalized;
props.data.pendingOnForeignChain = true;
props.data.txHash = '0x123';
render(<StatusCell {...props} />);
expect(screen.getByText('Pending'));
expect(screen.getByText('Pending')).toBeInTheDocument();
expect(screen.getByText('View on Etherscan')).toHaveAttribute(
'href',
expect.stringContaining(props.data.txHash)
);
});
test('Finalized', () => {
it('Finalized', () => {
props.value = WithdrawalStatus.Finalized;
props.data.pendingOnForeignChain = false;
props.data.txHash = '0x123';
render(<StatusCell {...props} />);
expect(screen.getByText('Finalized'));
expect(screen.getByText('Finalized')).toBeInTheDocument();
expect(screen.getByText('View on Etherscan')).toHaveAttribute(
'href',
expect.stringContaining(props.data.txHash)
);
});
test('Fallback', () => {
it('Fallback', () => {
props.value = WithdrawalStatus.Rejected;
props.data.pendingOnForeignChain = false;
props.data.txHash = '0x123';
render(<StatusCell {...props} />);
expect(screen.getByText('Rejected'));
expect(screen.getByText('Rejected')).toBeInTheDocument();
});
});

View File

@ -121,6 +121,7 @@
"eslint-config-prettier": "8.1.0",
"eslint-plugin-cypress": "^2.10.3",
"eslint-plugin-import": "2.25.2",
"eslint-plugin-jest": "^26.1.5",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-react": "7.27.0",
"eslint-plugin-react-hooks": "4.3.0",

View File

@ -5823,6 +5823,14 @@
"@typescript-eslint/types" "5.18.0"
"@typescript-eslint/visitor-keys" "5.18.0"
"@typescript-eslint/scope-manager@5.22.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.22.0.tgz#590865f244ebe6e46dc3e9cab7976fc2afa8af24"
integrity sha512-yA9G5NJgV5esANJCO0oF15MkBO20mIskbZ8ijfmlKIvQKg0ynVKfHZ15/nhAJN5m8Jn3X5qkwriQCiUntC9AbA==
dependencies:
"@typescript-eslint/types" "5.22.0"
"@typescript-eslint/visitor-keys" "5.22.0"
"@typescript-eslint/type-utils@5.18.0":
version "5.18.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.18.0.tgz#62dbfc8478abf36ba94a90ddf10be3cc8e471c74"
@ -5842,6 +5850,11 @@
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.18.0.tgz#4f0425d85fdb863071680983853c59a62ce9566e"
integrity sha512-bhV1+XjM+9bHMTmXi46p1Led5NP6iqQcsOxgx7fvk6gGiV48c6IynY0apQb7693twJDsXiVzNXTflhplmaiJaw==
"@typescript-eslint/types@5.22.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.22.0.tgz#50a4266e457a5d4c4b87ac31903b28b06b2c3ed0"
integrity sha512-T7owcXW4l0v7NTijmjGWwWf/1JqdlWiBzPqzAWhobxft0SiEvMJB56QXmeCQjrPuM8zEfGUKyPQr/L8+cFUBLw==
"@typescript-eslint/typescript-estree@5.10.1":
version "5.10.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.10.1.tgz#b268e67be0553f8790ba3fe87113282977adda15"
@ -5868,6 +5881,19 @@
semver "^7.3.5"
tsutils "^3.21.0"
"@typescript-eslint/typescript-estree@5.22.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.22.0.tgz#e2116fd644c3e2fda7f4395158cddd38c0c6df97"
integrity sha512-EyBEQxvNjg80yinGE2xdhpDYm41so/1kOItl0qrjIiJ1kX/L/L8WWGmJg8ni6eG3DwqmOzDqOhe6763bF92nOw==
dependencies:
"@typescript-eslint/types" "5.22.0"
"@typescript-eslint/visitor-keys" "5.22.0"
debug "^4.3.2"
globby "^11.0.4"
is-glob "^4.0.3"
semver "^7.3.5"
tsutils "^3.21.0"
"@typescript-eslint/utils@5.18.0":
version "5.18.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.18.0.tgz#27fc84cf95c1a96def0aae31684cb43a37e76855"
@ -5880,6 +5906,18 @@
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"
"@typescript-eslint/utils@^5.10.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.22.0.tgz#1f2c4897e2cf7e44443c848a13c60407861babd8"
integrity sha512-HodsGb037iobrWSUMS7QH6Hl1kppikjA1ELiJlNSTYf/UdMEwzgj0WIp+lBNb6WZ3zTwb0tEz51j0Wee3iJ3wQ==
dependencies:
"@types/json-schema" "^7.0.9"
"@typescript-eslint/scope-manager" "5.22.0"
"@typescript-eslint/types" "5.22.0"
"@typescript-eslint/typescript-estree" "5.22.0"
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"
"@typescript-eslint/visitor-keys@5.10.1":
version "5.10.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.10.1.tgz#29102de692f59d7d34ecc457ed59ab5fc558010b"
@ -5896,6 +5934,14 @@
"@typescript-eslint/types" "5.18.0"
eslint-visitor-keys "^3.0.0"
"@typescript-eslint/visitor-keys@5.22.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.22.0.tgz#f49c0ce406944ffa331a1cfabeed451ea4d0909c"
integrity sha512-DbgTqn2Dv5RFWluG88tn0pP6Ex0ROF+dpDO1TNNZdRtLjUr6bdznjA6f/qNqJLjd2PgguAES2Zgxh/JzwzETDg==
dependencies:
"@typescript-eslint/types" "5.22.0"
eslint-visitor-keys "^3.0.0"
"@vegaprotocol/smart-contracts-sdk@^1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@vegaprotocol/smart-contracts-sdk/-/smart-contracts-sdk-1.6.0.tgz#c689d5928148113dddbe39ed963c74817f432d5e"
@ -10854,6 +10900,13 @@ eslint-plugin-import@^2.25.2:
resolve "^1.22.0"
tsconfig-paths "^3.14.1"
eslint-plugin-jest@^26.1.5:
version "26.1.5"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-26.1.5.tgz#6cfca264818d6d6aa120b019dab4d62b6aa8e775"
integrity sha512-su89aDuljL9bTjEufTXmKUMSFe2kZUL9bi7+woq+C2ukHZordhtfPm4Vg+tdioHBaKf8v3/FXW9uV0ksqhYGFw==
dependencies:
"@typescript-eslint/utils" "^5.10.0"
eslint-plugin-jsx-a11y@6.5.1, eslint-plugin-jsx-a11y@^6.5.1:
version "6.5.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.5.1.tgz#cdbf2df901040ca140b6ec14715c988889c2a6d8"