chore(trading): add metaKey detection - clean up some unit tests (#3337)

This commit is contained in:
Maciek 2023-04-03 10:20:20 +02:00 committed by GitHub
parent 17ad0cc975
commit 7c82144f37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 111 deletions

View File

@ -7,7 +7,6 @@ import type { Trade } from './fills-data-provider';
import { FillsTable, getFeesBreakdown } from './fills-table'; import { FillsTable, getFeesBreakdown } from './fills-table';
import { generateFill } from './test-helpers'; import { generateFill } from './test-helpers';
import { MemoryRouter } from 'react-router-dom';
describe('FillsTable', () => { describe('FillsTable', () => {
let defaultFill: PartialDeep<Trade>; let defaultFill: PartialDeep<Trade>;
@ -37,11 +36,7 @@ describe('FillsTable', () => {
it('correct columns are rendered', async () => { it('correct columns are rendered', async () => {
await act(async () => { await act(async () => {
render( render(<FillsTable partyId="party-id" rowData={[generateFill()]} />);
<MemoryRouter>
<FillsTable partyId="party-id" rowData={[generateFill()]} />
</MemoryRouter>
);
}); });
const headers = screen.getAllByRole('columnheader'); const headers = screen.getAllByRole('columnheader');
@ -72,11 +67,7 @@ describe('FillsTable', () => {
liquidityFee: '2', liquidityFee: '2',
}, },
}); });
render( render(<FillsTable partyId={partyId} rowData={[{ ...buyerFill }]} />);
<MemoryRouter>
<FillsTable partyId={partyId} rowData={[{ ...buyerFill }]} />
</MemoryRouter>
);
const cells = screen.getAllByRole('gridcell'); const cells = screen.getAllByRole('gridcell');
const expectedValues = [ const expectedValues = [
buyerFill.market?.tradableInstrument.instrument.name || '', buyerFill.market?.tradableInstrument.instrument.name || '',
@ -109,11 +100,7 @@ describe('FillsTable', () => {
liquidityFee: '1', liquidityFee: '1',
}, },
}); });
render( render(<FillsTable partyId={partyId} rowData={[buyerFill]} />);
<MemoryRouter>
<FillsTable partyId={partyId} rowData={[buyerFill]} />
</MemoryRouter>
);
const cells = screen.getAllByRole('gridcell'); const cells = screen.getAllByRole('gridcell');
const expectedValues = [ const expectedValues = [
@ -142,9 +129,7 @@ describe('FillsTable', () => {
aggressor: Schema.Side.SIDE_SELL, aggressor: Schema.Side.SIDE_SELL,
}); });
const { rerender } = render( const { rerender } = render(
<MemoryRouter> <FillsTable partyId={partyId} rowData={[takerFill]} />
<FillsTable partyId={partyId} rowData={[takerFill]} />
</MemoryRouter>
); );
expect( expect(
screen screen
@ -158,11 +143,7 @@ describe('FillsTable', () => {
}, },
aggressor: Schema.Side.SIDE_BUY, aggressor: Schema.Side.SIDE_BUY,
}); });
rerender( rerender(<FillsTable partyId={partyId} rowData={[makerFill]} />);
<MemoryRouter>
<FillsTable partyId={partyId} rowData={[makerFill]} />
</MemoryRouter>
);
expect( expect(
screen screen
@ -179,11 +160,7 @@ describe('FillsTable', () => {
}, },
aggressor: Schema.Side.SIDE_SELL, aggressor: Schema.Side.SIDE_SELL,
}); });
render( render(<FillsTable partyId={partyId} rowData={[takerFill]} />);
<MemoryRouter>
<FillsTable partyId={partyId} rowData={[takerFill]} />
</MemoryRouter>
);
const feeCell = screen const feeCell = screen
.getAllByRole('gridcell') .getAllByRole('gridcell')

View File

@ -13,7 +13,6 @@ import {
limitOrder, limitOrder,
marketOrder, marketOrder,
} from '../mocks/generate-orders'; } from '../mocks/generate-orders';
import { MemoryRouter } from 'react-router-dom';
// Mock theme switcher to get around inconsistent mocking of zustand // Mock theme switcher to get around inconsistent mocking of zustand
// stores // stores
@ -37,11 +36,9 @@ const generateJsx = (
) => { ) => {
return ( return (
<MockedProvider> <MockedProvider>
<MemoryRouter> <VegaWalletContext.Provider value={context as VegaWalletContextShape}>
<VegaWalletContext.Provider value={context as VegaWalletContextShape}> <OrderListTable {...defaultProps} {...props} />
<OrderListTable {...defaultProps} {...props} /> </VegaWalletContext.Provider>
</VegaWalletContext.Provider>
</MemoryRouter>
</MockedProvider> </MockedProvider>
); );
}; };

View File

@ -6,7 +6,6 @@ import type { Position } from './positions-data-providers';
import * as Schema from '@vegaprotocol/types'; import * as Schema from '@vegaprotocol/types';
import { PositionStatus, PositionStatusMapping } from '@vegaprotocol/types'; import { PositionStatus, PositionStatusMapping } from '@vegaprotocol/types';
import type { ICellRendererParams } from 'ag-grid-community'; import type { ICellRendererParams } from 'ag-grid-community';
import { MemoryRouter } from 'react-router-dom';
const singleRow: Position = { const singleRow: Position = {
marketName: 'ETH/BTC (31 july 2022)', marketName: 'ETH/BTC (31 july 2022)',
@ -38,9 +37,7 @@ const singleRowData = [singleRow];
it('should render successfully', async () => { it('should render successfully', async () => {
await act(async () => { await act(async () => {
const { baseElement } = render( const { baseElement } = render(
<MemoryRouter> <PositionsTable rowData={[]} isReadOnly={false} />
<PositionsTable rowData={[]} isReadOnly={false} />
</MemoryRouter>
); );
expect(baseElement).toBeTruthy(); expect(baseElement).toBeTruthy();
}); });
@ -48,11 +45,7 @@ it('should render successfully', async () => {
it('render correct columns', async () => { it('render correct columns', async () => {
await act(async () => { await act(async () => {
render( render(<PositionsTable rowData={singleRowData} isReadOnly={true} />);
<MemoryRouter>
<PositionsTable rowData={singleRowData} isReadOnly={true} />
</MemoryRouter>
);
}); });
const headers = screen.getAllByRole('columnheader'); const headers = screen.getAllByRole('columnheader');
@ -76,11 +69,7 @@ it('render correct columns', async () => {
it('renders market name', async () => { it('renders market name', async () => {
await act(async () => { await act(async () => {
render( render(<PositionsTable rowData={singleRowData} isReadOnly={false} />);
<MemoryRouter>
<PositionsTable rowData={singleRowData} isReadOnly={false} />
</MemoryRouter>
);
}); });
expect(screen.getByText('ETH/BTC (31 july 2022)')).toBeTruthy(); expect(screen.getByText('ETH/BTC (31 july 2022)')).toBeTruthy();
}); });
@ -91,11 +80,7 @@ it('Does not fail if the market name does not match the split pattern', async ()
Object.assign({}, singleRow, { marketName: breakingMarketName }), Object.assign({}, singleRow, { marketName: breakingMarketName }),
]; ];
await act(async () => { await act(async () => {
render( render(<PositionsTable rowData={row} isReadOnly={false} />);
<MemoryRouter>
<PositionsTable rowData={row} isReadOnly={false} />
</MemoryRouter>
);
}); });
expect(screen.getByText(breakingMarketName)).toBeTruthy(); expect(screen.getByText(breakingMarketName)).toBeTruthy();
@ -105,9 +90,7 @@ it('add color and sign to amount, displays positive notional value', async () =>
let result: RenderResult; let result: RenderResult;
await act(async () => { await act(async () => {
result = render( result = render(
<MemoryRouter> <PositionsTable rowData={singleRowData} isReadOnly={false} />
<PositionsTable rowData={singleRowData} isReadOnly={false} />
</MemoryRouter>
); );
}); });
let cells = screen.getAllByRole('gridcell'); let cells = screen.getAllByRole('gridcell');
@ -118,12 +101,10 @@ it('add color and sign to amount, displays positive notional value', async () =>
expect(cells[1].textContent).toEqual('1,230.0'); expect(cells[1].textContent).toEqual('1,230.0');
await act(async () => { await act(async () => {
result.rerender( result.rerender(
<MemoryRouter> <PositionsTable
<PositionsTable rowData={[{ ...singleRow, openVolume: '-100' }]}
rowData={[{ ...singleRow, openVolume: '-100' }]} isReadOnly={false}
isReadOnly={false} />
/>
</MemoryRouter>
); );
}); });
cells = screen.getAllByRole('gridcell'); cells = screen.getAllByRole('gridcell');
@ -137,9 +118,7 @@ it('displays mark price', async () => {
let result: RenderResult; let result: RenderResult;
await act(async () => { await act(async () => {
result = render( result = render(
<MemoryRouter> <PositionsTable rowData={singleRowData} isReadOnly={false} />
<PositionsTable rowData={singleRowData} isReadOnly={false} />
</MemoryRouter>
); );
}); });
@ -148,18 +127,16 @@ it('displays mark price', async () => {
await act(async () => { await act(async () => {
result.rerender( result.rerender(
<MemoryRouter> <PositionsTable
<PositionsTable rowData={[
rowData={[ {
{ ...singleRow,
...singleRow, marketTradingMode:
marketTradingMode: Schema.MarketTradingMode.TRADING_MODE_OPENING_AUCTION,
Schema.MarketTradingMode.TRADING_MODE_OPENING_AUCTION, },
}, ]}
]} isReadOnly={false}
isReadOnly={false} />
/>
</MemoryRouter>
); );
}); });
@ -169,11 +146,7 @@ it('displays mark price', async () => {
it('displays leverage', async () => { it('displays leverage', async () => {
await act(async () => { await act(async () => {
render( render(<PositionsTable rowData={singleRowData} isReadOnly={false} />);
<MemoryRouter>
<PositionsTable rowData={singleRowData} isReadOnly={false} />
</MemoryRouter>
);
}); });
const cells = screen.getAllByRole('gridcell'); const cells = screen.getAllByRole('gridcell');
expect(cells[6].textContent).toEqual('1.1'); expect(cells[6].textContent).toEqual('1.1');
@ -181,11 +154,7 @@ it('displays leverage', async () => {
it('displays allocated margin', async () => { it('displays allocated margin', async () => {
await act(async () => { await act(async () => {
render( render(<PositionsTable rowData={singleRowData} isReadOnly={false} />);
<MemoryRouter>
<PositionsTable rowData={singleRowData} isReadOnly={false} />
</MemoryRouter>
);
}); });
const cells = screen.getAllByRole('gridcell'); const cells = screen.getAllByRole('gridcell');
const cell = cells[7]; const cell = cells[7];
@ -194,11 +163,7 @@ it('displays allocated margin', async () => {
it('displays realised and unrealised PNL', async () => { it('displays realised and unrealised PNL', async () => {
await act(async () => { await act(async () => {
render( render(<PositionsTable rowData={singleRowData} isReadOnly={false} />);
<MemoryRouter>
<PositionsTable rowData={singleRowData} isReadOnly={false} />
</MemoryRouter>
);
}); });
const cells = screen.getAllByRole('gridcell'); const cells = screen.getAllByRole('gridcell');
expect(cells[9].textContent).toEqual('4.56'); expect(cells[9].textContent).toEqual('4.56');
@ -207,15 +172,13 @@ it('displays realised and unrealised PNL', async () => {
it('displays close button', async () => { it('displays close button', async () => {
await act(async () => { await act(async () => {
render( render(
<MemoryRouter> <PositionsTable
<PositionsTable rowData={singleRowData}
rowData={singleRowData} onClose={() => {
onClose={() => { return;
return; }}
}} isReadOnly={false}
isReadOnly={false} />
/>
</MemoryRouter>
); );
}); });
const cells = screen.getAllByRole('gridcell'); const cells = screen.getAllByRole('gridcell');
@ -225,15 +188,13 @@ it('displays close button', async () => {
it('do not display close button if openVolume is zero', async () => { it('do not display close button if openVolume is zero', async () => {
await act(async () => { await act(async () => {
render( render(
<MemoryRouter> <PositionsTable
<PositionsTable rowData={[{ ...singleRow, openVolume: '0' }]}
rowData={[{ ...singleRow, openVolume: '0' }]} onClose={() => {
onClose={() => { return;
return; }}
}} isReadOnly={false}
isReadOnly={false} />
/>
</MemoryRouter>
); );
}); });
const cells = screen.getAllByRole('gridcell'); const cells = screen.getAllByRole('gridcell');