From 7c82144f37160b8cbf73d4e9cf01a1228935d6a8 Mon Sep 17 00:00:00 2001 From: Maciek Date: Mon, 3 Apr 2023 10:20:20 +0200 Subject: [PATCH] chore(trading): add metaKey detection - clean up some unit tests (#3337) --- libs/fills/src/lib/fills-table.spec.tsx | 35 +----- .../components/order-list/order-list.spec.tsx | 9 +- .../src/lib/positions-table.spec.tsx | 113 ++++++------------ 3 files changed, 46 insertions(+), 111 deletions(-) diff --git a/libs/fills/src/lib/fills-table.spec.tsx b/libs/fills/src/lib/fills-table.spec.tsx index c68567ea4..f1ee45630 100644 --- a/libs/fills/src/lib/fills-table.spec.tsx +++ b/libs/fills/src/lib/fills-table.spec.tsx @@ -7,7 +7,6 @@ import type { Trade } from './fills-data-provider'; import { FillsTable, getFeesBreakdown } from './fills-table'; import { generateFill } from './test-helpers'; -import { MemoryRouter } from 'react-router-dom'; describe('FillsTable', () => { let defaultFill: PartialDeep; @@ -37,11 +36,7 @@ describe('FillsTable', () => { it('correct columns are rendered', async () => { await act(async () => { - render( - - - - ); + render(); }); const headers = screen.getAllByRole('columnheader'); @@ -72,11 +67,7 @@ describe('FillsTable', () => { liquidityFee: '2', }, }); - render( - - - - ); + render(); const cells = screen.getAllByRole('gridcell'); const expectedValues = [ buyerFill.market?.tradableInstrument.instrument.name || '', @@ -109,11 +100,7 @@ describe('FillsTable', () => { liquidityFee: '1', }, }); - render( - - - - ); + render(); const cells = screen.getAllByRole('gridcell'); const expectedValues = [ @@ -142,9 +129,7 @@ describe('FillsTable', () => { aggressor: Schema.Side.SIDE_SELL, }); const { rerender } = render( - - - + ); expect( screen @@ -158,11 +143,7 @@ describe('FillsTable', () => { }, aggressor: Schema.Side.SIDE_BUY, }); - rerender( - - - - ); + rerender(); expect( screen @@ -179,11 +160,7 @@ describe('FillsTable', () => { }, aggressor: Schema.Side.SIDE_SELL, }); - render( - - - - ); + render(); const feeCell = screen .getAllByRole('gridcell') diff --git a/libs/orders/src/lib/components/order-list/order-list.spec.tsx b/libs/orders/src/lib/components/order-list/order-list.spec.tsx index 3d4f56538..20f66106e 100644 --- a/libs/orders/src/lib/components/order-list/order-list.spec.tsx +++ b/libs/orders/src/lib/components/order-list/order-list.spec.tsx @@ -13,7 +13,6 @@ import { limitOrder, marketOrder, } from '../mocks/generate-orders'; -import { MemoryRouter } from 'react-router-dom'; // Mock theme switcher to get around inconsistent mocking of zustand // stores @@ -37,11 +36,9 @@ const generateJsx = ( ) => { return ( - - - - - + + + ); }; diff --git a/libs/positions/src/lib/positions-table.spec.tsx b/libs/positions/src/lib/positions-table.spec.tsx index dc71063c7..e5fa8cddb 100644 --- a/libs/positions/src/lib/positions-table.spec.tsx +++ b/libs/positions/src/lib/positions-table.spec.tsx @@ -6,7 +6,6 @@ import type { Position } from './positions-data-providers'; import * as Schema from '@vegaprotocol/types'; import { PositionStatus, PositionStatusMapping } from '@vegaprotocol/types'; import type { ICellRendererParams } from 'ag-grid-community'; -import { MemoryRouter } from 'react-router-dom'; const singleRow: Position = { marketName: 'ETH/BTC (31 july 2022)', @@ -38,9 +37,7 @@ const singleRowData = [singleRow]; it('should render successfully', async () => { await act(async () => { const { baseElement } = render( - - - + ); expect(baseElement).toBeTruthy(); }); @@ -48,11 +45,7 @@ it('should render successfully', async () => { it('render correct columns', async () => { await act(async () => { - render( - - - - ); + render(); }); const headers = screen.getAllByRole('columnheader'); @@ -76,11 +69,7 @@ it('render correct columns', async () => { it('renders market name', async () => { await act(async () => { - render( - - - - ); + render(); }); 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 }), ]; await act(async () => { - render( - - - - ); + render(); }); expect(screen.getByText(breakingMarketName)).toBeTruthy(); @@ -105,9 +90,7 @@ it('add color and sign to amount, displays positive notional value', async () => let result: RenderResult; await act(async () => { result = render( - - - + ); }); 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'); await act(async () => { result.rerender( - - - + ); }); cells = screen.getAllByRole('gridcell'); @@ -137,9 +118,7 @@ it('displays mark price', async () => { let result: RenderResult; await act(async () => { result = render( - - - + ); }); @@ -148,18 +127,16 @@ it('displays mark price', async () => { await act(async () => { result.rerender( - - - + ); }); @@ -169,11 +146,7 @@ it('displays mark price', async () => { it('displays leverage', async () => { await act(async () => { - render( - - - - ); + render(); }); const cells = screen.getAllByRole('gridcell'); expect(cells[6].textContent).toEqual('1.1'); @@ -181,11 +154,7 @@ it('displays leverage', async () => { it('displays allocated margin', async () => { await act(async () => { - render( - - - - ); + render(); }); const cells = screen.getAllByRole('gridcell'); const cell = cells[7]; @@ -194,11 +163,7 @@ it('displays allocated margin', async () => { it('displays realised and unrealised PNL', async () => { await act(async () => { - render( - - - - ); + render(); }); const cells = screen.getAllByRole('gridcell'); expect(cells[9].textContent).toEqual('4.56'); @@ -207,15 +172,13 @@ it('displays realised and unrealised PNL', async () => { it('displays close button', async () => { await act(async () => { render( - - { - return; - }} - isReadOnly={false} - /> - + { + return; + }} + isReadOnly={false} + /> ); }); 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 () => { await act(async () => { render( - - { - return; - }} - isReadOnly={false} - /> - + { + return; + }} + isReadOnly={false} + /> ); }); const cells = screen.getAllByRole('gridcell');