vega-frontend-monorepo/libs/positions/src/lib/positions-table.spec.tsx

106 lines
2.9 KiB
TypeScript
Raw Normal View History

import { act, render, screen, waitFor } from '@testing-library/react';
2022-03-25 12:32:14 +00:00
import PositionsTable from './positions-table';
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
const singleRow: Positions_party_positions = {
feat: trading page market summary & select markets modal opening from market title & fix: positions table realised PnL (#505) * feat: [#456] select markets modal opening from market title * feat: add a global zustand store for managing connect dialogs and landing dialog * feat: add tests * feat: [#456] make arrow configurable * feat: [#456] make arrow configurable * feat: [#456] trading tab active only on portfolio * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * fix: [#445] shallow routing from index (#484) * fix: [#445] shallow routing from index * fix: [#445] use link to redirect to market - an attempt to fix reload * fix: [#445] remove stretched link from last link - it makes all the other links unusable * fix: [#445] fix lint on select market list - remove stretched link * fix: [#456] put everything in landing folder to avoid conflicts * fix: remove condition for cypress for auto connecting * feat: [#456] add global store and fix href routing * feat: [#456] add global store and fix href routing * feat: [#456] add one more test * feat: [#154] pull market data summary * feat: [#154] move header above the trade grid child sections * feat: [#154] flex oerflow and styling updates for market summary * feat: [#154] fix styling * fix: [154] fix cyp tests and styling * fix: [#154] fix markets navigation cypress step * fix: [#154] fix for navigate to markets link * fix: failing tests from market change * fix: [#154] set nav items based on market id and show last viewed market on landing * fix: [#412] invalid decimal place on realised PnL field * fix: [#154] remove redundant curly braces * fix: [#154] show hyphen on volume if market data is undefined Co-authored-by: Matthew Russell <mattrussell36@gmail.com> Co-authored-by: dexturr <dexturr@users.noreply.github.com> Co-authored-by: Joe <joe@vega.xyz>
2022-06-06 16:19:56 +00:00
realisedPNL: '520000000',
openVolume: '10000',
unrealisedPNL: '895000',
averageEntryPrice: '1129935',
market: {
id: 'b7010da9dbe7fbab2b74d9d5642fc4a8a0ca93ef803d21fa60c2cacd0416bba0',
name: 'UNIDAI Monthly (30 Jun 2022)',
data: {
markPrice: '1138885',
marketTradingMode: MarketTradingMode.Continuous,
__typename: 'MarketData',
market: { __typename: 'Market', id: '123' },
},
positionDecimalPlaces: 2,
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];
it('should render successfully', async () => {
await act(async () => {
const { baseElement } = render(<PositionsTable data={[]} />);
expect(baseElement).toBeTruthy();
});
});
it('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',
]);
});
});
});
it('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.00',
'11.29935',
'11.38885',
feat: trading page market summary & select markets modal opening from market title & fix: positions table realised PnL (#505) * feat: [#456] select markets modal opening from market title * feat: add a global zustand store for managing connect dialogs and landing dialog * feat: add tests * feat: [#456] make arrow configurable * feat: [#456] make arrow configurable * feat: [#456] trading tab active only on portfolio * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * fix: [#445] shallow routing from index (#484) * fix: [#445] shallow routing from index * fix: [#445] use link to redirect to market - an attempt to fix reload * fix: [#445] remove stretched link from last link - it makes all the other links unusable * fix: [#445] fix lint on select market list - remove stretched link * fix: [#456] put everything in landing folder to avoid conflicts * fix: remove condition for cypress for auto connecting * feat: [#456] add global store and fix href routing * feat: [#456] add global store and fix href routing * feat: [#456] add one more test * feat: [#154] pull market data summary * feat: [#154] move header above the trade grid child sections * feat: [#154] flex oerflow and styling updates for market summary * feat: [#154] fix styling * fix: [154] fix cyp tests and styling * fix: [#154] fix markets navigation cypress step * fix: [#154] fix for navigate to markets link * fix: failing tests from market change * fix: [#154] set nav items based on market id and show last viewed market on landing * fix: [#412] invalid decimal place on realised PnL field * fix: [#154] remove redundant curly braces * fix: [#154] show hyphen on volume if market data is undefined Co-authored-by: Matthew Russell <mattrussell36@gmail.com> Co-authored-by: dexturr <dexturr@users.noreply.github.com> Co-authored-by: Joe <joe@vega.xyz>
2022-06-06 16:19:56 +00:00
'+5,200.000',
];
cells.forEach((cell, i) => {
expect(cell).toHaveTextContent(expectedValues[i]);
});
expect(cells[cells.length - 1]).toHaveClass('color-vega-green');
});
});
2022-03-25 12:32:14 +00:00
});