2022-04-25 16:33:49 +00:00
|
|
|
import { act, render, screen, waitFor } from '@testing-library/react';
|
2022-03-25 12:32:14 +00:00
|
|
|
import PositionsTable from './positions-table';
|
2022-03-30 09:49:48 +00:00
|
|
|
import type { Positions_party_positions } from './__generated__/Positions';
|
2022-03-29 23:03:27 +00:00
|
|
|
import { MarketTradingMode } from '@vegaprotocol/types';
|
2022-03-25 12:32:14 +00:00
|
|
|
|
2022-03-29 16:52:35 +00:00
|
|
|
const singleRow: Positions_party_positions = {
|
2022-06-06 16:19:56 +00:00
|
|
|
realisedPNL: '520000000',
|
2022-06-23 22:00:58 +00:00
|
|
|
openVolume: '10000',
|
2022-03-29 15:26:09 +00:00
|
|
|
unrealisedPNL: '895000',
|
|
|
|
averageEntryPrice: '1129935',
|
|
|
|
market: {
|
|
|
|
id: 'b7010da9dbe7fbab2b74d9d5642fc4a8a0ca93ef803d21fa60c2cacd0416bba0',
|
|
|
|
name: 'UNIDAI Monthly (30 Jun 2022)',
|
2022-03-29 16:36:20 +00:00
|
|
|
data: {
|
|
|
|
markPrice: '1138885',
|
|
|
|
marketTradingMode: MarketTradingMode.Continuous,
|
|
|
|
__typename: 'MarketData',
|
|
|
|
market: { __typename: 'Market', id: '123' },
|
|
|
|
},
|
2022-06-23 22:00:58 +00:00
|
|
|
positionDecimalPlaces: 2,
|
2022-03-29 15:26:09 +00:00
|
|
|
decimalPlaces: 5,
|
|
|
|
tradableInstrument: {
|
|
|
|
instrument: {
|
|
|
|
id: '',
|
|
|
|
name: 'UNIDAI Monthly (30 Jun 2022)',
|
|
|
|
metadata: {
|
|
|
|
tags: [
|
|
|
|
'formerly:3C58ED2A4A6C5D7E',
|
|
|
|
'base:UNI',
|
|
|
|
'quote:DAI',
|
|
|
|
'class:fx/crypto',
|
|
|
|
'monthly',
|
|
|
|
'sector:defi',
|
|
|
|
],
|
|
|
|
__typename: 'InstrumentMetadata',
|
|
|
|
},
|
|
|
|
code: 'UNIDAI.MF21',
|
|
|
|
product: {
|
|
|
|
settlementAsset: {
|
|
|
|
id: '6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61',
|
|
|
|
symbol: 'tDAI',
|
|
|
|
name: 'tDAI TEST',
|
|
|
|
decimals: 5,
|
|
|
|
__typename: 'Asset',
|
|
|
|
},
|
|
|
|
quoteName: 'DAI',
|
|
|
|
__typename: 'Future',
|
|
|
|
},
|
|
|
|
__typename: 'Instrument',
|
|
|
|
},
|
|
|
|
__typename: 'TradableInstrument',
|
|
|
|
},
|
|
|
|
__typename: 'Market',
|
|
|
|
},
|
|
|
|
__typename: 'Position',
|
|
|
|
};
|
|
|
|
const singleRowData = [singleRow];
|
|
|
|
|
2022-05-12 12:32:14 +00:00
|
|
|
it('should render successfully', async () => {
|
2022-03-29 15:26:09 +00:00
|
|
|
await act(async () => {
|
2022-03-30 00:01:34 +00:00
|
|
|
const { baseElement } = render(<PositionsTable data={[]} />);
|
2022-03-29 15:26:09 +00:00
|
|
|
expect(baseElement).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2022-04-25 16:33:49 +00:00
|
|
|
|
2022-05-12 12:32:14 +00:00
|
|
|
it('Render correct columns', async () => {
|
2022-03-29 15:26:09 +00:00
|
|
|
await act(async () => {
|
2022-03-30 00:01:34 +00:00
|
|
|
render(<PositionsTable data={singleRowData} />);
|
2022-04-25 16:33:49 +00:00
|
|
|
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',
|
|
|
|
]);
|
|
|
|
});
|
2022-03-29 15:26:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-12 12:32:14 +00:00
|
|
|
it('Correct formatting applied', async () => {
|
2022-03-29 15:26:09 +00:00
|
|
|
await act(async () => {
|
2022-03-30 00:01:34 +00:00
|
|
|
render(<PositionsTable data={singleRowData} />);
|
2022-04-25 16:33:49 +00:00
|
|
|
await waitFor(async () => {
|
|
|
|
const cells = screen.getAllByRole('gridcell');
|
|
|
|
const expectedValues = [
|
|
|
|
singleRow.market.tradableInstrument.instrument.code,
|
2022-06-23 22:00:58 +00:00
|
|
|
'+100.00',
|
2022-04-25 16:33:49 +00:00
|
|
|
'11.29935',
|
|
|
|
'11.38885',
|
2022-06-06 16:19:56 +00:00
|
|
|
'+5,200.000',
|
2022-04-25 16:33:49 +00:00
|
|
|
];
|
|
|
|
cells.forEach((cell, i) => {
|
|
|
|
expect(cell).toHaveTextContent(expectedValues[i]);
|
|
|
|
});
|
|
|
|
expect(cells[cells.length - 1]).toHaveClass('color-vega-green');
|
|
|
|
});
|
2022-03-29 15:26:09 +00:00
|
|
|
});
|
2022-03-25 12:32:14 +00:00
|
|
|
});
|