2022-06-01 14:21:36 +00:00
|
|
|
import { fireEvent, render, screen } from '@testing-library/react';
|
2022-12-08 21:13:30 +00:00
|
|
|
import * as Schema from '@vegaprotocol/types';
|
2022-10-28 12:41:33 +00:00
|
|
|
|
2022-12-13 13:31:28 +00:00
|
|
|
import { SelectAllMarketsTableBody } from './select-market';
|
2022-10-28 12:41:33 +00:00
|
|
|
|
2022-10-04 08:37:31 +00:00
|
|
|
import type {
|
|
|
|
MarketWithCandles,
|
|
|
|
MarketWithData,
|
|
|
|
MarketData,
|
|
|
|
} from '@vegaprotocol/market-list';
|
2022-11-08 07:23:38 +00:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2022-11-30 11:02:59 +00:00
|
|
|
import { MockedProvider } from '@apollo/client/testing';
|
2022-10-03 17:28:32 +00:00
|
|
|
type Market = MarketWithCandles & MarketWithData;
|
|
|
|
|
|
|
|
type PartialMarket = Partial<
|
|
|
|
Omit<Market, 'data'> & { data: Partial<MarketData> }
|
|
|
|
>;
|
|
|
|
|
|
|
|
const MARKET_A: PartialMarket = {
|
2022-09-13 10:14:06 +00:00
|
|
|
__typename: 'Market',
|
|
|
|
id: '1',
|
|
|
|
decimalPlaces: 2,
|
2022-11-15 12:31:25 +00:00
|
|
|
tradingMode: Schema.MarketTradingMode.TRADING_MODE_CONTINUOUS,
|
2022-09-13 10:14:06 +00:00
|
|
|
tradableInstrument: {
|
|
|
|
__typename: 'TradableInstrument',
|
|
|
|
instrument: {
|
|
|
|
__typename: 'Instrument',
|
|
|
|
id: '1',
|
|
|
|
code: 'ABCDEF',
|
|
|
|
name: 'ABCDEF 1-Day',
|
|
|
|
product: {
|
|
|
|
__typename: 'Future',
|
2022-10-03 17:28:32 +00:00
|
|
|
quoteName: 'ABCDEF',
|
2022-09-13 10:14:06 +00:00
|
|
|
settlementAsset: {
|
|
|
|
__typename: 'Asset',
|
2022-11-23 23:42:22 +00:00
|
|
|
id: 'asset-ABC',
|
2022-10-03 17:28:32 +00:00
|
|
|
decimals: 2,
|
2022-09-13 10:14:06 +00:00
|
|
|
symbol: 'ABC',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
metadata: {
|
|
|
|
__typename: 'InstrumentMetadata',
|
|
|
|
tags: ['ABC', 'DEF'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fees: {
|
|
|
|
__typename: 'Fees',
|
|
|
|
factors: {
|
|
|
|
__typename: 'FeeFactors',
|
|
|
|
infrastructureFee: '0.01',
|
|
|
|
liquidityFee: '0.01',
|
|
|
|
makerFee: '0.01',
|
|
|
|
},
|
|
|
|
},
|
2022-10-03 17:28:32 +00:00
|
|
|
data: {
|
|
|
|
__typename: 'MarketData',
|
|
|
|
market: {
|
|
|
|
__typename: 'Market',
|
|
|
|
id: '1',
|
|
|
|
},
|
|
|
|
markPrice: '90',
|
2022-11-15 12:31:25 +00:00
|
|
|
trigger: Schema.AuctionTrigger.AUCTION_TRIGGER_OPENING,
|
2022-12-02 00:33:30 +00:00
|
|
|
marketState: Schema.MarketState.STATE_PENDING,
|
|
|
|
marketTradingMode: Schema.MarketTradingMode.TRADING_MODE_OPENING_AUCTION,
|
2022-10-03 17:28:32 +00:00
|
|
|
indicativeVolume: '1000',
|
|
|
|
},
|
|
|
|
candles: [
|
|
|
|
{
|
|
|
|
__typename: 'Candle',
|
|
|
|
high: '100',
|
|
|
|
low: '10',
|
|
|
|
open: '10',
|
|
|
|
close: '80',
|
|
|
|
volume: '1000',
|
2022-11-02 15:47:15 +00:00
|
|
|
periodStart: '2022-11-01T15:49:00Z',
|
2022-10-03 17:28:32 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
__typename: 'Candle',
|
|
|
|
high: '10',
|
|
|
|
low: '1',
|
|
|
|
open: '1',
|
|
|
|
close: '100',
|
|
|
|
volume: '1000',
|
2022-11-02 15:47:15 +00:00
|
|
|
periodStart: '2022-11-01T15:50:00Z',
|
2022-10-03 17:28:32 +00:00
|
|
|
},
|
|
|
|
],
|
2022-09-13 10:14:06 +00:00
|
|
|
};
|
|
|
|
|
2022-10-03 17:28:32 +00:00
|
|
|
const MARKET_B: PartialMarket = {
|
2022-09-13 10:14:06 +00:00
|
|
|
__typename: 'Market',
|
|
|
|
id: '2',
|
|
|
|
decimalPlaces: 2,
|
2022-11-30 11:02:59 +00:00
|
|
|
positionDecimalPlaces: 0,
|
2022-11-15 12:31:25 +00:00
|
|
|
tradingMode: Schema.MarketTradingMode.TRADING_MODE_CONTINUOUS,
|
2022-09-13 10:14:06 +00:00
|
|
|
tradableInstrument: {
|
|
|
|
__typename: 'TradableInstrument',
|
|
|
|
instrument: {
|
|
|
|
__typename: 'Instrument',
|
|
|
|
id: '2',
|
|
|
|
code: 'XYZ',
|
|
|
|
name: 'XYZ 1-Day',
|
|
|
|
product: {
|
|
|
|
__typename: 'Future',
|
2022-10-03 17:28:32 +00:00
|
|
|
quoteName: 'XYZ',
|
2022-09-13 10:14:06 +00:00
|
|
|
settlementAsset: {
|
|
|
|
__typename: 'Asset',
|
2022-11-23 23:42:22 +00:00
|
|
|
id: 'asset-XYZ',
|
2022-10-03 17:28:32 +00:00
|
|
|
decimals: 2,
|
2022-09-13 10:14:06 +00:00
|
|
|
symbol: 'XYZ',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
metadata: {
|
|
|
|
__typename: 'InstrumentMetadata',
|
|
|
|
tags: ['XYZ'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fees: {
|
|
|
|
__typename: 'Fees',
|
|
|
|
factors: {
|
|
|
|
__typename: 'FeeFactors',
|
|
|
|
infrastructureFee: '0.01',
|
|
|
|
liquidityFee: '0.01',
|
|
|
|
makerFee: '0.01',
|
|
|
|
},
|
|
|
|
},
|
2022-10-03 17:28:32 +00:00
|
|
|
data: {
|
|
|
|
__typename: 'MarketData',
|
|
|
|
market: {
|
|
|
|
__typename: 'Market',
|
|
|
|
id: '2',
|
2022-09-13 10:14:06 +00:00
|
|
|
},
|
2022-10-03 17:28:32 +00:00
|
|
|
markPrice: '123.123',
|
2022-11-15 12:31:25 +00:00
|
|
|
trigger: Schema.AuctionTrigger.AUCTION_TRIGGER_OPENING,
|
2022-12-02 00:33:30 +00:00
|
|
|
marketState: Schema.MarketState.STATE_PENDING,
|
|
|
|
marketTradingMode: Schema.MarketTradingMode.TRADING_MODE_OPENING_AUCTION,
|
2022-10-03 17:28:32 +00:00
|
|
|
indicativeVolume: '2000',
|
|
|
|
},
|
2022-09-13 10:14:06 +00:00
|
|
|
candles: [
|
|
|
|
{
|
2022-10-03 17:28:32 +00:00
|
|
|
__typename: 'Candle',
|
2022-09-13 10:14:06 +00:00
|
|
|
high: '100',
|
|
|
|
low: '10',
|
|
|
|
open: '10',
|
|
|
|
close: '80',
|
|
|
|
volume: '1000',
|
2022-11-02 15:47:15 +00:00
|
|
|
periodStart: '2022-11-01T15:49:00Z',
|
2022-09-13 10:14:06 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
feat: market list mega dropdown (rich popover) (#889)
* feat: use MarketList query only
* fix: remove Market.ts from index
* feat: 30 refactor dialog, market list, change query
* feat: #30 add indicativeVolume, total fees, tooltip, large dialog, tooltip accepts html description
* fix: #30 total fees display in tooltip
* fix: #30 toggle title on dialog open
* fix: #30 fix order, price, high, low utils
* fix: #30 fix test for market utils
* feat: #30 add popover with markets to select
* feat: #30 storybook popover
* feat: #30 remove border on trigger and add some other classes
* fix: #30 fix format check with format:write
* feat: #30 add tooltip on taker fee
* feat: #30 add tooltip on taker fee
* fix: #30 format on select market list
* fix: #30 remove unknown cast in test mock data
* fix: #30 show markets where you have open positions
* fix: #30 double check if open positions
* fix: #30 dialog has only small/large sizes
* feat: #30 add border on trigger and change padding and no wrap
* fix: #30 if fees or factors are not found
* fix: #30 remove markets.cy tests as markets page is now gone
* fix #30 remove view full market list test
* fix: #30 add rotating arrow on market title
* fix: #30 add ease-in-out on popover
* fix: #30 add ease-in-out on popover
* fix: #30 align select a market table
* fix: #30 select a market title
* fix: #30 select a market title
* fix: #30 fix any validateDOMnesting issues
* fix: #30 show loading market data
* fix: #30 add list of header columns
* fix: #30 add list of header columns
* fix: #30 small refactoring after review
* fix: #30 update bold undreline class names
* fix: #30 add large-mobile size
* feat: #30 refactor select markets tables to render array of columns
* fix: #30 remove size from select market dialog
* fix: #30 add extra file for columns
* fix: #30 update formtting
* fix: #30 make sure popup closes on same market navigation
* fix: rename market-utils, add calcCandle methods, store market id on select
* fix: useMemo ondata and marketPositionData + orderbook stories fix
* feat: #30 add open volume positions
* fix: add market summary back
* fix: update formatting
* fix: use currentcolor on arrow
* fix: create all markets page
* fix: add overflow-y auto
* fix: enlarge select market to get started dialog
* fix: revert markets container
* fix: use query to fix flickering on position markets
* fix: edit unordered list in tooltips
* fix: fix tooltip table
* fix: fix home.cy.ts
* chore: skip /markets tests
2022-08-11 11:56:35 +00:00
|
|
|
describe('SelectMarket', () => {
|
|
|
|
it('should render the SelectAllMarketsTableBody', () => {
|
|
|
|
const onSelect = jest.fn();
|
2022-10-03 17:28:32 +00:00
|
|
|
const onCellClick = jest.fn();
|
2022-06-10 15:07:44 +00:00
|
|
|
const { container } = render(
|
2022-11-08 07:23:38 +00:00
|
|
|
<MemoryRouter>
|
|
|
|
<SelectAllMarketsTableBody
|
|
|
|
markets={[MARKET_A as Market, MARKET_B as Market]}
|
|
|
|
onCellClick={onCellClick}
|
|
|
|
onSelect={onSelect}
|
|
|
|
/>
|
2022-11-30 11:02:59 +00:00
|
|
|
</MemoryRouter>,
|
|
|
|
{ wrapper: MockedProvider }
|
2022-06-01 14:21:36 +00:00
|
|
|
);
|
2022-09-13 10:14:06 +00:00
|
|
|
expect(screen.getByText('ABCDEF')).toBeTruthy(); // name
|
|
|
|
expect(screen.getByText('25.00%')).toBeTruthy(); // price change
|
|
|
|
expect(container).toHaveTextContent(/1,000/); // volume
|
2022-10-28 12:41:33 +00:00
|
|
|
fireEvent.click(screen.getAllByTestId(`market-link-1`)[0]);
|
2022-09-13 10:14:06 +00:00
|
|
|
expect(onSelect).toHaveBeenCalledWith('1');
|
2022-05-23 12:21:54 +00:00
|
|
|
});
|
|
|
|
});
|