From 45d6f43e745a67901cc4096865d819e39122ce09 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Sep 2023 15:25:50 +0100 Subject: [PATCH] chore(trading): deal ticket test to jest (#4842) --- .../trading-deal-ticket-basics.cy.ts | 106 ------------------ .../deal-ticket/deal-ticket.spec.tsx | 65 ++++++++++- 2 files changed, 63 insertions(+), 108 deletions(-) delete mode 100644 apps/trading-e2e/src/integration/trading-deal-ticket-basics.cy.ts diff --git a/apps/trading-e2e/src/integration/trading-deal-ticket-basics.cy.ts b/apps/trading-e2e/src/integration/trading-deal-ticket-basics.cy.ts deleted file mode 100644 index b892ca01a..000000000 --- a/apps/trading-e2e/src/integration/trading-deal-ticket-basics.cy.ts +++ /dev/null @@ -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'); - }); - }); - }); - } -); diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx index c672e93bc..aa2415762 100644 --- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx @@ -23,6 +23,7 @@ import { OrdersDocument } from '@vegaprotocol/orders'; import { formatForInput } from '@vegaprotocol/utils'; import type { PartialDeep } from 'type-fest'; import type { Market } from '@vegaprotocol/markets'; +import type { MarketData } from '@vegaprotocol/markets'; jest.mock('zustand'); jest.mock('./deal-ticket-fee-details', () => ({ @@ -40,18 +41,25 @@ const submit = jest.fn(); function generateJsx( mocks: MockedResponse[] = [], - marketOverrides: PartialDeep = {} + marketOverrides: PartialDeep = {}, + marketDataOverrides: Partial = {} ) { const joinedMarket: Market = { ...market, ...marketOverrides, } as Market; + + const joinedMarketData: MarketData = { + ...marketData, + ...marketDataOverrides, + } as MarketData; + return ( { }); it('can edit deal ticket', async () => { + // 7002-SORD-004 + // 7002-SORD-005 + // 7002-SORD-006 + // 7002-SORD-007 render(generateJsx()); // BUY is selected by default @@ -483,11 +495,31 @@ describe('DealTicket', () => { // Switch to limit order await userEvent.click(screen.getByTestId('order-type-Limit')); + expect(screen.getByTestId('order-type-Limit').dataset.state).toEqual( + 'checked' + ); // Check all TIF options shown expect(screen.getByTestId('order-tif').children).toHaveLength( 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 () => { @@ -654,4 +686,33 @@ describe('DealTicket', () => { new Date(screen.getByTestId(datePicker).value).getTime() ).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(); + }); + }); });