chore(trading): deal ticket test to jest (#4842)
This commit is contained in:
parent
41760f2956
commit
45d6f43e74
@ -1,106 +0,0 @@
|
|||||||
import * as Schema from '@vegaprotocol/types';
|
|
||||||
import { mockConnectWallet } from '@vegaprotocol/cypress';
|
|
||||||
import {
|
|
||||||
orderPriceField,
|
|
||||||
placeOrderBtn,
|
|
||||||
toggleLimit,
|
|
||||||
toggleLong,
|
|
||||||
toggleMarket,
|
|
||||||
toggleShort,
|
|
||||||
} from '../support/deal-ticket';
|
|
||||||
|
|
||||||
describe('deal ticket basics', { tags: '@smoke' }, () => {
|
|
||||||
before(() => {
|
|
||||||
cy.mockTradingPage();
|
|
||||||
cy.mockSubscription();
|
|
||||||
cy.clearAllLocalStorage();
|
|
||||||
cy.setOnBoardingViewed();
|
|
||||||
cy.visit('/#/markets/market-0');
|
|
||||||
cy.wait('@Markets');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('must show place order button and connect wallet if wallet is not connected', () => {
|
|
||||||
// 0003-WTXN-001
|
|
||||||
cy.getByTestId('connect-vega-wallet'); // Not connected
|
|
||||||
cy.getByTestId(placeOrderBtn).should('exist');
|
|
||||||
cy.getByTestId('order-connect-wallet').should('exist');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('must be able to select order direction - long/short', function () {
|
|
||||||
// 7002-SORD-004
|
|
||||||
cy.getByTestId(toggleShort).click().next('input').should('be.checked');
|
|
||||||
cy.getByTestId(toggleLong).click().next('input').should('be.checked');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('must be able to select order type - limit/market', function () {
|
|
||||||
// 7002-SORD-005
|
|
||||||
// 7002-SORD-006
|
|
||||||
// 7002-SORD-007
|
|
||||||
cy.getByTestId(toggleLimit).click().next('input').should('be.checked');
|
|
||||||
cy.getByTestId(toggleMarket).click().next('input').should('be.checked');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('order connect vega wallet button should connect', () => {
|
|
||||||
mockConnectWallet();
|
|
||||||
cy.getByTestId(toggleLimit).click();
|
|
||||||
cy.getByTestId(orderPriceField).clear().type('101');
|
|
||||||
cy.getByTestId('order-connect-wallet').click();
|
|
||||||
cy.getByTestId('dialog-content').should('be.visible');
|
|
||||||
cy.getByTestId('connectors-list')
|
|
||||||
.find('[data-testid="connector-jsonRpc"]')
|
|
||||||
.click();
|
|
||||||
cy.wait('@walletReq');
|
|
||||||
cy.getByTestId(placeOrderBtn).should('be.visible');
|
|
||||||
cy.getByTestId(toggleLimit).next('input').should('be.checked');
|
|
||||||
cy.getByTestId(orderPriceField).should('have.value', '101');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sidebar should be open after reload', () => {
|
|
||||||
cy.mockTradingPage();
|
|
||||||
cy.getByTestId('deal-ticket-form').should('be.visible');
|
|
||||||
cy.getByTestId('Order').click();
|
|
||||||
cy.getByTestId('deal-ticket-form').should('not.exist');
|
|
||||||
cy.reload();
|
|
||||||
cy.getByTestId('deal-ticket-form').should('be.visible');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe(
|
|
||||||
'market states not accepting orders',
|
|
||||||
{ tags: '@smoke', testIsolation: true },
|
|
||||||
function () {
|
|
||||||
//7002-SORD-062
|
|
||||||
//7002-SORD-063
|
|
||||||
//7002-SORD-066
|
|
||||||
|
|
||||||
const states = [
|
|
||||||
Schema.MarketState.STATE_REJECTED,
|
|
||||||
Schema.MarketState.STATE_CANCELLED,
|
|
||||||
Schema.MarketState.STATE_CLOSED,
|
|
||||||
Schema.MarketState.STATE_SETTLED,
|
|
||||||
Schema.MarketState.STATE_TRADING_TERMINATED,
|
|
||||||
];
|
|
||||||
|
|
||||||
states.forEach((marketState) => {
|
|
||||||
describe(marketState, function () {
|
|
||||||
beforeEach(function () {
|
|
||||||
cy.mockTradingPage(marketState);
|
|
||||||
cy.mockSubscription();
|
|
||||||
cy.setVegaWallet();
|
|
||||||
cy.visit('/#/markets/market-0');
|
|
||||||
});
|
|
||||||
it('must display that market is not accepting orders', function () {
|
|
||||||
cy.getByTestId('deal-ticket-error-message-summary').should(
|
|
||||||
'have.text',
|
|
||||||
`This market is ${marketState
|
|
||||||
.split('_')
|
|
||||||
.pop()
|
|
||||||
?.toLowerCase()} and not accepting orders`
|
|
||||||
);
|
|
||||||
// 7002-SORD-060
|
|
||||||
cy.getByTestId('place-order').should('be.enabled');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
@ -23,6 +23,7 @@ import { OrdersDocument } from '@vegaprotocol/orders';
|
|||||||
import { formatForInput } from '@vegaprotocol/utils';
|
import { formatForInput } from '@vegaprotocol/utils';
|
||||||
import type { PartialDeep } from 'type-fest';
|
import type { PartialDeep } from 'type-fest';
|
||||||
import type { Market } from '@vegaprotocol/markets';
|
import type { Market } from '@vegaprotocol/markets';
|
||||||
|
import type { MarketData } from '@vegaprotocol/markets';
|
||||||
|
|
||||||
jest.mock('zustand');
|
jest.mock('zustand');
|
||||||
jest.mock('./deal-ticket-fee-details', () => ({
|
jest.mock('./deal-ticket-fee-details', () => ({
|
||||||
@ -40,18 +41,25 @@ const submit = jest.fn();
|
|||||||
|
|
||||||
function generateJsx(
|
function generateJsx(
|
||||||
mocks: MockedResponse[] = [],
|
mocks: MockedResponse[] = [],
|
||||||
marketOverrides: PartialDeep<Market> = {}
|
marketOverrides: PartialDeep<Market> = {},
|
||||||
|
marketDataOverrides: Partial<MarketData> = {}
|
||||||
) {
|
) {
|
||||||
const joinedMarket: Market = {
|
const joinedMarket: Market = {
|
||||||
...market,
|
...market,
|
||||||
...marketOverrides,
|
...marketOverrides,
|
||||||
} as Market;
|
} as Market;
|
||||||
|
|
||||||
|
const joinedMarketData: MarketData = {
|
||||||
|
...marketData,
|
||||||
|
...marketDataOverrides,
|
||||||
|
} as MarketData;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MockedProvider mocks={[...mocks]}>
|
<MockedProvider mocks={[...mocks]}>
|
||||||
<VegaWalletContext.Provider value={{ pubKey, isReadOnly: false } as any}>
|
<VegaWalletContext.Provider value={{ pubKey, isReadOnly: false } as any}>
|
||||||
<DealTicket
|
<DealTicket
|
||||||
market={joinedMarket}
|
market={joinedMarket}
|
||||||
marketData={marketData}
|
marketData={joinedMarketData}
|
||||||
marketPrice={marketPrice}
|
marketPrice={marketPrice}
|
||||||
submit={submit}
|
submit={submit}
|
||||||
onDeposit={jest.fn()}
|
onDeposit={jest.fn()}
|
||||||
@ -462,6 +470,10 @@ describe('DealTicket', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can edit deal ticket', async () => {
|
it('can edit deal ticket', async () => {
|
||||||
|
// 7002-SORD-004
|
||||||
|
// 7002-SORD-005
|
||||||
|
// 7002-SORD-006
|
||||||
|
// 7002-SORD-007
|
||||||
render(generateJsx());
|
render(generateJsx());
|
||||||
|
|
||||||
// BUY is selected by default
|
// BUY is selected by default
|
||||||
@ -483,11 +495,31 @@ describe('DealTicket', () => {
|
|||||||
|
|
||||||
// Switch to limit order
|
// Switch to limit order
|
||||||
await userEvent.click(screen.getByTestId('order-type-Limit'));
|
await userEvent.click(screen.getByTestId('order-type-Limit'));
|
||||||
|
expect(screen.getByTestId('order-type-Limit').dataset.state).toEqual(
|
||||||
|
'checked'
|
||||||
|
);
|
||||||
|
|
||||||
// Check all TIF options shown
|
// Check all TIF options shown
|
||||||
expect(screen.getByTestId('order-tif').children).toHaveLength(
|
expect(screen.getByTestId('order-tif').children).toHaveLength(
|
||||||
Object.keys(Schema.OrderTimeInForce).length
|
Object.keys(Schema.OrderTimeInForce).length
|
||||||
);
|
);
|
||||||
|
// Switch to market order
|
||||||
|
await userEvent.click(screen.getByTestId('order-type-Market'));
|
||||||
|
expect(screen.getByTestId('order-type-Market').dataset.state).toEqual(
|
||||||
|
'checked'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Switch to short order
|
||||||
|
await userEvent.click(screen.getByTestId('order-side-SIDE_SELL'));
|
||||||
|
expect(screen.getByTestId('order-side-SIDE_SELL').dataset.state).toEqual(
|
||||||
|
'checked'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Switch to long order
|
||||||
|
await userEvent.click(screen.getByTestId('order-side-SIDE_BUY'));
|
||||||
|
expect(screen.getByTestId('order-side-SIDE_BUY').dataset.state).toEqual(
|
||||||
|
'checked'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('validates size field', async () => {
|
it('validates size field', async () => {
|
||||||
@ -654,4 +686,33 @@ describe('DealTicket', () => {
|
|||||||
new Date(screen.getByTestId<HTMLInputElement>(datePicker).value).getTime()
|
new Date(screen.getByTestId<HTMLInputElement>(datePicker).value).getTime()
|
||||||
).toEqual(now);
|
).toEqual(now);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('market states not accepting orders', () => {
|
||||||
|
const states = [
|
||||||
|
Schema.MarketState.STATE_REJECTED,
|
||||||
|
Schema.MarketState.STATE_CANCELLED,
|
||||||
|
Schema.MarketState.STATE_CLOSED,
|
||||||
|
Schema.MarketState.STATE_SETTLED,
|
||||||
|
Schema.MarketState.STATE_TRADING_TERMINATED,
|
||||||
|
];
|
||||||
|
|
||||||
|
it.each(states)('handles state %s correctly', async (marketState) => {
|
||||||
|
const marketOverrides = { state: marketState };
|
||||||
|
const marketDataOverrides = { marketState: marketState };
|
||||||
|
render(generateJsx([], marketOverrides, marketDataOverrides));
|
||||||
|
|
||||||
|
const text = `This market is ${marketState
|
||||||
|
.split('_')
|
||||||
|
.pop()
|
||||||
|
?.toLowerCase()} and not accepting orders`;
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(
|
||||||
|
screen.getByTestId('deal-ticket-error-message-summary')
|
||||||
|
).toHaveTextContent(text);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(screen.getByTestId('place-order')).toBeEnabled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user