Limit number of warnings in tests (#298)

This commit is contained in:
Bartłomiej Głownia 2022-04-25 18:33:49 +02:00 committed by GitHub
parent 3354fbb0c2
commit 2cdf349641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 75 additions and 56 deletions

View File

@ -1,5 +1,5 @@
import AccountsTable from './accounts-table';
import { act, render, screen } from '@testing-library/react';
import { act, render, screen, waitFor } from '@testing-library/react';
import type { Accounts_party_accounts } from './__generated__/Accounts';
import { AccountType } from '@vegaprotocol/types';
@ -27,30 +27,36 @@ test('should render successfully', async () => {
expect(baseElement).toBeTruthy();
});
});
test('Render correct columns', async () => {
await act(async () => {
render(<AccountsTable data={singleRowData} />);
await waitFor(async () => {
const headers = await screen.getAllByRole('columnheader');
expect(headers).toHaveLength(4);
expect(
headers.map((h) =>
h.querySelector('[ref="eText"]')?.textContent?.trim()
)
).toEqual(['Asset', 'Type', 'Market', 'Balance']);
});
});
const headers = screen.getAllByRole('columnheader');
expect(headers).toHaveLength(4);
expect(
headers.map((h) => h.querySelector('[ref="eText"]')?.textContent?.trim())
).toEqual(['Asset', 'Type', 'Market', 'Balance']);
});
test('Correct formatting applied', async () => {
await act(async () => {
render(<AccountsTable data={singleRowData} />);
});
const cells = screen.getAllByRole('gridcell');
const expectedValues = [
'tBTC',
singleRow.type,
'BTCUSD Monthly (30 Jun 2022)',
'1,256.00000',
];
cells.forEach((cell, i) => {
expect(cell).toHaveTextContent(expectedValues[i]);
await waitFor(async () => {
const cells = await screen.getAllByRole('gridcell');
const expectedValues = [
'tBTC',
singleRow.type,
'BTCUSD Monthly (30 Jun 2022)',
'1,256.00000',
];
cells.forEach((cell, i) => {
expect(cell).toHaveTextContent(expectedValues[i]);
});
});
});
});

View File

@ -11,7 +11,7 @@ import { AgGridDynamic as AgGrid } from '@vegaprotocol/ui-toolkit';
import { AgGridColumn } from 'ag-grid-react';
import type { AgGridReact } from 'ag-grid-react';
import type { Accounts_party_accounts } from './__generated__/Accounts';
import { getId as getRowNodeId } from './accounts-data-provider';
import { getId } from './accounts-data-provider';
interface AccountsTableProps {
data: Accounts_party_accounts[] | null;
@ -90,7 +90,7 @@ export const AccountsTable = forwardRef<AgGridReact, AccountsTableProps>(
style={{ width: '100%', height: '100%' }}
overlayNoRowsTemplate={t('No accounts')}
rowData={data}
getRowNodeId={getRowNodeId}
getRowId={({ data }) => getId(data)}
ref={ref}
defaultColDef={{
flex: 1,

View File

@ -2,7 +2,10 @@ import { forwardRef } from 'react';
import type { ValueFormatterParams } from 'ag-grid-community';
import { PriceCell, formatNumber, t } from '@vegaprotocol/react-helpers';
import { AgGridDynamic as AgGrid } from '@vegaprotocol/ui-toolkit';
import type { Markets_markets } from './__generated__/Markets';
import type {
Markets_markets,
Markets_markets_data_market,
} from './__generated__/Markets';
import { AgGridColumn } from 'ag-grid-react';
import type { AgGridReact } from 'ag-grid-react';
@ -11,7 +14,11 @@ interface MarketListTableProps {
onRowClicked: (marketId: string) => void;
}
export const getRowNodeId = (data: { id: string }) => data.id;
export const getRowId = ({
data,
}: {
data: Markets_markets | Markets_markets_data_market;
}) => data.id;
export const MarketListTable = forwardRef<AgGridReact, MarketListTableProps>(
({ data, onRowClicked }, ref) => {
@ -20,7 +27,7 @@ export const MarketListTable = forwardRef<AgGridReact, MarketListTableProps>(
style={{ width: '100%', height: '100%' }}
overlayNoRowsTemplate={t('No markets')}
rowData={data}
getRowNodeId={getRowNodeId}
getRowId={getRowId}
ref={ref}
defaultColDef={{
flex: 1,

View File

@ -3,7 +3,7 @@ import { produce } from 'immer';
import merge from 'lodash/merge';
import { useRouter } from 'next/router';
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
import { MarketListTable, getRowNodeId } from './market-list-table';
import { MarketListTable, getRowId } from './market-list-table';
import { useDataProvider } from '@vegaprotocol/react-helpers';
import type { AgGridReact } from 'ag-grid-react';
import type {
@ -23,7 +23,7 @@ export const MarketsContainer = () => {
return false;
}
const rowNode = gridRef.current.api.getRowNode(
getRowNodeId(delta.market)
getRowId({ data: delta.market })
);
if (rowNode) {
const updatedData = produce<Markets_markets_data>(

View File

@ -20,7 +20,7 @@ export const OrderList = forwardRef<AgGridReact, OrderListProps>(
overlayNoRowsTemplate="No orders"
defaultColDef={{ flex: 1, resizable: true }}
style={{ width: '100%', height: '100%' }}
getRowNodeId={(data) => data.id}
getRowId={({ data }) => data.id}
>
<AgGridColumn
headerName="Market"

View File

@ -7,7 +7,7 @@ import type { PositionSubscribe_positions } from './__generated__/PositionSubscr
import type { Positions_party_positions } from './__generated__/Positions';
import type { AgGridReact } from 'ag-grid-react';
import PositionsTable, { getRowNodeId } from './positions-table';
import PositionsTable, { getRowId } from './positions-table';
import { positionsDataProvider } from './positions-data-provider';
interface PositionsManagerProps {
@ -24,7 +24,7 @@ export const PositionsManager = ({ partyId }: PositionsManagerProps) => {
if (!gridRef.current?.api) {
return false;
}
const rowNode = gridRef.current.api.getRowNode(getRowNodeId(delta));
const rowNode = gridRef.current.api.getRowNode(getRowId({ data: delta }));
if (rowNode) {
const updatedData = produce<Positions_party_positions>(
rowNode.data,

View File

@ -1,4 +1,4 @@
import { act, render, screen } from '@testing-library/react';
import { act, render, screen, waitFor } from '@testing-library/react';
import PositionsTable from './positions-table';
import type { Positions_party_positions } from './__generated__/Positions';
import { MarketTradingMode } from '@vegaprotocol/types';
@ -61,38 +61,44 @@ test('should render successfully', async () => {
expect(baseElement).toBeTruthy();
});
});
test('Render correct columns', async () => {
await act(async () => {
render(<PositionsTable data={singleRowData} />);
await waitFor(async () => {
const headers = await screen.getAllByRole('columnheader');
expect(headers).toHaveLength(5);
expect(
headers.map((h) =>
h.querySelector('[ref="eText"]')?.textContent?.trim()
)
).toEqual([
'Market',
'Amount',
'Average Entry Price',
'Mark Price',
'Realised PNL',
]);
});
});
const headers = screen.getAllByRole('columnheader');
expect(headers).toHaveLength(5);
expect(
headers.map((h) => h.querySelector('[ref="eText"]')?.textContent?.trim())
).toEqual([
'Market',
'Amount',
'Average Entry Price',
'Mark Price',
'Realised PNL',
]);
});
test('Correct formatting applied', async () => {
await act(async () => {
render(<PositionsTable data={singleRowData} />);
await waitFor(async () => {
const cells = screen.getAllByRole('gridcell');
const expectedValues = [
singleRow.market.tradableInstrument.instrument.code,
'+100',
'11.29935',
'11.38885',
'+5',
];
cells.forEach((cell, i) => {
expect(cell).toHaveTextContent(expectedValues[i]);
});
expect(cells[cells.length - 1]).toHaveClass('color-vega-green');
});
});
const cells = screen.getAllByRole('gridcell');
const expectedValues = [
singleRow.market.tradableInstrument.instrument.code,
'+100',
'11.29935',
'11.38885',
'+5',
];
cells.forEach((cell, i) => {
expect(cell).toHaveTextContent(expectedValues[i]);
});
expect(cells[cells.length - 1]).toHaveClass('color-vega-green');
});

View File

@ -17,7 +17,7 @@ interface PositionsTableProps {
data: Positions_party_positions[] | null;
}
export const getRowNodeId = (data: { market: { id: string } }) =>
export const getRowId = ({ data }: { data: Positions_party_positions }) =>
data.market.id;
const alphanumericComparator = (a: string, b: string, isInverted: boolean) => {
@ -61,7 +61,7 @@ export const PositionsTable = forwardRef<AgGridReact, PositionsTableProps>(
style={{ width: '100%', height: '100%' }}
overlayNoRowsTemplate="No positions"
rowData={data}
getRowNodeId={getRowNodeId}
getRowId={getRowId}
ref={ref}
defaultColDef={{
flex: 1,

View File

@ -1,6 +1,6 @@
import { MockedProvider } from '@apollo/client/testing';
import { waitFor } from '@testing-library/react';
import { act, renderHook } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react-hooks/dom';
import { TxState } from './use-ethereum-transaction';
import type { ReactNode } from 'react';
import { useEthereumTransaction } from './use-ethereum-transaction';

View File

@ -55,7 +55,7 @@ export const TradesTable = forwardRef<AgGridReact, TradesTableProps>(
style={{ width: '100%', height: '100%' }}
overlayNoRowsTemplate={t('No trades')}
rowData={trades}
getRowNodeId={(data) => data.id}
getRowId={({ data }) => data.id}
ref={ref}
defaultColDef={{
flex: 1,