diff --git a/apps/trading-e2e/src/integration/deposit.cy.ts b/apps/trading-e2e/src/integration/deposit.cy.ts index ce071e291..aa6605207 100644 --- a/apps/trading-e2e/src/integration/deposit.cy.ts +++ b/apps/trading-e2e/src/integration/deposit.cy.ts @@ -1,7 +1,3 @@ -import { aliasQuery } from '@vegaprotocol/cypress'; -import { generateAssets } from '../support/mocks/generate-assets'; -import { generateNetworkParameters } from '../support/mocks/generate-network-parameters'; - const connectEthWalletBtn = 'connect-eth-wallet-btn'; const assetSelectField = 'select[name="asset"]'; const toAddressField = 'input[name="to"]'; @@ -12,10 +8,7 @@ describe('deposit form validation', { tags: '@smoke' }, () => { beforeEach(() => { cy.mockWeb3Provider(); cy.mockGQLSubscription(); - cy.mockGQL((req) => { - aliasQuery(req, 'NetworkParamsQuery', generateNetworkParameters()); - aliasQuery(req, 'Assets', generateAssets()); - }); + cy.mockTradingPage(); cy.visit('/portfolio/deposit'); // Deposit page requires connection Ethereum wallet first diff --git a/apps/trading-e2e/src/integration/global.cy.ts b/apps/trading-e2e/src/integration/global.cy.ts index 8797116ef..74e72b251 100644 --- a/apps/trading-e2e/src/integration/global.cy.ts +++ b/apps/trading-e2e/src/integration/global.cy.ts @@ -1,7 +1,6 @@ import { aliasQuery } from '@vegaprotocol/cypress'; import { connectVegaWallet } from '../support/vega-wallet'; import { generateNetworkParameters } from '../support/mocks/generate-network-parameters'; -import { generateChainId } from '../support/mocks/generate-chain-id'; describe('vega wallet', { tags: '@smoke' }, () => { const connectVegaBtn = 'connect-vega-wallet'; @@ -13,9 +12,7 @@ describe('vega wallet', { tags: '@smoke' }, () => { beforeEach(() => { // Using portfolio page as it requires vega wallet connection cy.visit('/portfolio'); - cy.mockGQL((req) => { - aliasQuery(req, 'ChainId', generateChainId()); - }); + cy.mockTradingPage(); cy.mockGQLSubscription(); cy.get('main[data-testid="portfolio"]').should('exist'); }); diff --git a/apps/trading-e2e/src/integration/home.cy.ts b/apps/trading-e2e/src/integration/home.cy.ts index 13fa69664..bcdbd03a2 100644 --- a/apps/trading-e2e/src/integration/home.cy.ts +++ b/apps/trading-e2e/src/integration/home.cy.ts @@ -1,13 +1,8 @@ import { aliasQuery } from '@vegaprotocol/cypress'; -import { MarketState } from '@vegaprotocol/types'; -import { mockTradingPage } from '../support/trading'; - describe('home', { tags: '@regression' }, () => { const selectMarketOverlay = 'select-market-list'; beforeEach(() => { - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); cy.mockGQLSubscription(); cy.visit('/'); }); diff --git a/apps/trading-e2e/src/integration/market-info.cy.ts b/apps/trading-e2e/src/integration/market-info.cy.ts index 0c85ab859..7a3296be0 100644 --- a/apps/trading-e2e/src/integration/market-info.cy.ts +++ b/apps/trading-e2e/src/integration/market-info.cy.ts @@ -1,5 +1,4 @@ import { MarketState, MarketTradingModeMapping } from '@vegaprotocol/types'; -import { mockTradingPage } from '../support/trading'; import { connectVegaWallet } from '../support/vega-wallet'; const marketInfoBtn = 'Info'; @@ -10,9 +9,7 @@ const externalLink = 'external-link'; describe('market info is displayed', { tags: '@smoke' }, () => { before(() => { - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); cy.mockGQLSubscription(); cy.visit('/markets/market-0'); cy.wait('@Market'); @@ -221,9 +218,7 @@ describe('market states', { tags: '@smoke' }, function () { states.forEach((marketState) => { describe(marketState, function () { before(function () { - cy.mockGQL((req) => { - mockTradingPage(req, marketState); - }); + cy.mockTradingPage(marketState); cy.mockGQLSubscription(); cy.visit('/markets/market-0'); cy.wait('@Market'); diff --git a/apps/trading-e2e/src/integration/market-summary.cy.ts b/apps/trading-e2e/src/integration/market-summary.cy.ts index a47e75883..84c2cf570 100644 --- a/apps/trading-e2e/src/integration/market-summary.cy.ts +++ b/apps/trading-e2e/src/integration/market-summary.cy.ts @@ -3,7 +3,6 @@ import { MarketState, MarketTradingMode, } from '@vegaprotocol/types'; -import { mockTradingPage } from '../support/trading'; const marketSummaryBlock = 'header-summary'; const marketExpiry = 'market-expiry'; @@ -19,14 +18,11 @@ const itemValue = 'item-value'; describe('Market trading page', () => { before(() => { - cy.mockGQL((req) => { - mockTradingPage( - req, - MarketState.STATE_ACTIVE, - MarketTradingMode.TRADING_MODE_MONITORING_AUCTION, - AuctionTrigger.AUCTION_TRIGGER_LIQUIDITY - ); - }); + cy.mockTradingPage( + MarketState.STATE_ACTIVE, + MarketTradingMode.TRADING_MODE_MONITORING_AUCTION, + AuctionTrigger.AUCTION_TRIGGER_LIQUIDITY + ); cy.mockGQLSubscription(); cy.visit('/markets/market-0'); cy.wait('@MarketData'); diff --git a/apps/trading-e2e/src/integration/markets.cy.ts b/apps/trading-e2e/src/integration/markets.cy.ts index 6b02ae6f7..1c98ff693 100644 --- a/apps/trading-e2e/src/integration/markets.cy.ts +++ b/apps/trading-e2e/src/integration/markets.cy.ts @@ -3,18 +3,14 @@ import { MarketState, MarketTradingMode, } from '@vegaprotocol/types'; -import { mockTradingPage } from '../support/trading'; describe('markets table', { tags: '@smoke' }, () => { beforeEach(() => { - cy.mockGQL((req) => { - mockTradingPage( - req, - MarketState.STATE_ACTIVE, - MarketTradingMode.TRADING_MODE_MONITORING_AUCTION, - AuctionTrigger.AUCTION_TRIGGER_LIQUIDITY - ); - }); + cy.mockTradingPage( + MarketState.STATE_ACTIVE, + MarketTradingMode.TRADING_MODE_MONITORING_AUCTION, + AuctionTrigger.AUCTION_TRIGGER_LIQUIDITY + ); cy.mockGQLSubscription(); cy.visit('/'); cy.wait('@Market'); diff --git a/apps/trading-e2e/src/integration/trading-accounts.cy.ts b/apps/trading-e2e/src/integration/trading-accounts.cy.ts index 09cd58a1c..04a2196d8 100644 --- a/apps/trading-e2e/src/integration/trading-accounts.cy.ts +++ b/apps/trading-e2e/src/integration/trading-accounts.cy.ts @@ -1,15 +1,8 @@ -import { MarketState } from '@vegaprotocol/types'; -import { mockTradingPage } from '../support/trading'; import { connectVegaWallet } from '../support/vega-wallet'; import { connectEthereumWallet } from '../support/ethereum-wallet'; -import { generateNetworkParameters } from '../support/mocks/generate-network-parameters'; -import { aliasQuery } from '@vegaprotocol/cypress'; beforeEach(() => { - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - aliasQuery(req, 'NetworkParamsQuery', generateNetworkParameters()); - }); + cy.mockTradingPage(); cy.mockWeb3Provider(); cy.mockGQLSubscription(); cy.visit('/markets/market-0'); diff --git a/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts b/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts index bf09ef84c..0c0454e59 100644 --- a/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts +++ b/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts @@ -3,7 +3,6 @@ import { MarketTradingMode, AuctionTrigger, } from '@vegaprotocol/types'; -import { mockTradingPage } from '../support/trading'; import { connectVegaWallet } from '../support/vega-wallet'; const orderSizeField = 'order-size'; @@ -123,9 +122,7 @@ const testOrder = (order: Order, expected?: Partial) => { describe('must submit order', { tags: '@smoke' }, () => { // 7002-SORD-039 before(() => { - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); cy.mockGQLSubscription(); cy.visit('/markets/market-0'); cy.wait('@Market'); @@ -205,9 +202,7 @@ describe('must submit order', { tags: '@smoke' }, () => { describe('deal ticket validation', { tags: '@smoke' }, () => { before(() => { - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); cy.visit('/markets/market-0'); cy.wait('@Market'); }); @@ -260,9 +255,7 @@ describe('deal ticket validation', { tags: '@smoke' }, () => { describe('deal ticket size validation', { tags: '@smoke' }, function () { before(() => { - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); cy.visit('/markets/market-0'); cy.wait('@Market'); connectVegaWallet(); @@ -289,9 +282,7 @@ describe('deal ticket size validation', { tags: '@smoke' }, function () { describe('limit order validations', { tags: '@smoke' }, () => { before(() => { - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); cy.visit('/markets/market-0'); cy.wait('@Market'); cy.getByTestId(toggleLimit).click(); @@ -345,9 +336,7 @@ describe('limit order validations', { tags: '@smoke' }, () => { describe('market order validations', { tags: '@smoke' }, () => { before(() => { - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); cy.visit('/markets/market-0'); cy.wait('@Market'); cy.getByTestId(toggleMarket).click(); @@ -398,14 +387,11 @@ describe('market order validations', { tags: '@smoke' }, () => { describe('suspended market validation', { tags: '@regression' }, () => { before(() => { - cy.mockGQL((req) => { - mockTradingPage( - req, - MarketState.STATE_SUSPENDED, - MarketTradingMode.TRADING_MODE_MONITORING_AUCTION, - AuctionTrigger.AUCTION_TRIGGER_LIQUIDITY - ); - }); + cy.mockTradingPage( + MarketState.STATE_SUSPENDED, + MarketTradingMode.TRADING_MODE_MONITORING_AUCTION, + AuctionTrigger.AUCTION_TRIGGER_LIQUIDITY + ); cy.visit('/markets/market-0'); cy.wait('@Market'); connectVegaWallet(); diff --git a/apps/trading-e2e/src/integration/trading-fills.cy.ts b/apps/trading-e2e/src/integration/trading-fills.cy.ts index 1df23f2ed..4cdb1bd0a 100644 --- a/apps/trading-e2e/src/integration/trading-fills.cy.ts +++ b/apps/trading-e2e/src/integration/trading-fills.cy.ts @@ -1,13 +1,11 @@ import { aliasQuery } from '@vegaprotocol/cypress'; import { generateFills } from '../support/mocks/generate-fills'; -import { MarketState } from '@vegaprotocol/types'; import { connectVegaWallet } from '../support/vega-wallet'; -import { mockTradingPage } from '../support/trading'; describe('fills', { tags: '@regression' }, () => { beforeEach(() => { + cy.mockTradingPage(); cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); aliasQuery(req, 'Fills', generateFills()); }); cy.mockGQLSubscription(); @@ -23,9 +21,7 @@ describe('fills', { tags: '@regression' }, () => { }); it('renders fills on trading tab', () => { - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); cy.visit('/markets/market-0'); cy.getByTestId('Fills').click(); cy.getByTestId('tab-fills').contains('Please connect Vega wallet'); diff --git a/apps/trading-e2e/src/integration/trading-orders.cy.ts b/apps/trading-e2e/src/integration/trading-orders.cy.ts index 8e8c87e5c..9d2bdc8d2 100644 --- a/apps/trading-e2e/src/integration/trading-orders.cy.ts +++ b/apps/trading-e2e/src/integration/trading-orders.cy.ts @@ -1,9 +1,4 @@ -import { - MarketState, - OrderRejectionReason, - OrderStatus, -} from '@vegaprotocol/types'; -import { mockTradingPage } from '../support/trading'; +import { OrderRejectionReason, OrderStatus } from '@vegaprotocol/types'; import { connectVegaWallet } from '../support/vega-wallet'; import { updateOrder, @@ -25,9 +20,7 @@ describe('orders list', { tags: '@smoke' }, () => { before(() => { const subscriptionMocks = getSubscriptionMocks(); cy.spy(subscriptionMocks, 'OrderSub'); - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); cy.mockGQLSubscription(subscriptionMocks); cy.visit('/markets/market-0'); cy.getByTestId('Orders').click(); @@ -132,9 +125,7 @@ describe('subscribe orders', { tags: '@smoke' }, () => { before(() => { const subscriptionMocks = getSubscriptionMocks(); cy.spy(subscriptionMocks, 'OrderSub'); - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); cy.mockGQLSubscription(subscriptionMocks); cy.visit('/markets/market-0'); cy.getByTestId('Orders').click(); diff --git a/apps/trading-e2e/src/integration/trading-positions.cy.ts b/apps/trading-e2e/src/integration/trading-positions.cy.ts index a47f059d1..8adf1f816 100644 --- a/apps/trading-e2e/src/integration/trading-positions.cy.ts +++ b/apps/trading-e2e/src/integration/trading-positions.cy.ts @@ -1,11 +1,8 @@ -import { MarketState } from '@vegaprotocol/types'; -import { mockTradingPage } from '../support/trading'; import { connectVegaWallet } from '../support/vega-wallet'; beforeEach(() => { - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); + cy.mockGQLSubscription(); }); diff --git a/apps/trading-e2e/src/integration/trading-trades.cy.ts b/apps/trading-e2e/src/integration/trading-trades.cy.ts index 733a2d3bd..56d4e1d1e 100644 --- a/apps/trading-e2e/src/integration/trading-trades.cy.ts +++ b/apps/trading-e2e/src/integration/trading-trades.cy.ts @@ -1,10 +1,5 @@ -import { MarketState } from '@vegaprotocol/types'; -import { mockTradingPage } from '../support/trading'; - beforeEach(() => { - cy.mockGQL((req) => { - mockTradingPage(req, MarketState.STATE_ACTIVE); - }); + cy.mockTradingPage(); cy.mockGQLSubscription(); cy.visit('/markets/market-0'); }); diff --git a/apps/trading-e2e/src/integration/withdraw.cy.ts b/apps/trading-e2e/src/integration/withdraw.cy.ts index b47a9cb18..00329c0bb 100644 --- a/apps/trading-e2e/src/integration/withdraw.cy.ts +++ b/apps/trading-e2e/src/integration/withdraw.cy.ts @@ -1,10 +1,4 @@ -import { aliasQuery } from '@vegaprotocol/cypress'; import { connectEthereumWallet } from '../support/ethereum-wallet'; -import { generateChainId } from '../support/mocks/generate-chain-id'; -import { generateAccounts } from '../support/mocks/generate-accounts'; -import { generateAssets } from '../support/mocks/generate-assets'; -import { generateNetworkParameters } from '../support/mocks/generate-network-parameters'; -import { generateWithdrawals } from '../support/mocks/generate-withdrawals'; import { connectVegaWallet } from '../support/vega-wallet'; describe('withdraw', { tags: '@smoke' }, () => { @@ -20,13 +14,7 @@ describe('withdraw', { tags: '@smoke' }, () => { beforeEach(() => { cy.mockWeb3Provider(); - cy.mockGQL((req) => { - aliasQuery(req, 'ChainId', generateChainId()); - aliasQuery(req, 'Withdrawals', generateWithdrawals()); - aliasQuery(req, 'NetworkParamsQuery', generateNetworkParameters()); - aliasQuery(req, 'Assets', generateAssets()); - aliasQuery(req, 'Accounts', generateAccounts()); - }); + cy.mockTradingPage(); cy.mockGQLSubscription(); cy.visit('/portfolio'); diff --git a/apps/trading-e2e/src/support/index.js b/apps/trading-e2e/src/support/index.js index d1ea36278..ebdd2d345 100644 --- a/apps/trading-e2e/src/support/index.js +++ b/apps/trading-e2e/src/support/index.js @@ -1,13 +1,6 @@ import '@vegaprotocol/cypress'; import 'cypress-real-events/support'; import registerCypressGrep from 'cypress-grep'; -import { aliasQuery } from '@vegaprotocol/cypress'; -import { generateChainId } from './mocks/generate-chain-id'; +import { addMockTradingPage } from './trading'; registerCypressGrep(); - -before(() => { - // Mock chainId fetch which happens on every page wallet connection - cy.mockGQL((req) => { - aliasQuery(req, 'ChainId', generateChainId()); - }); -}); +addMockTradingPage(); diff --git a/apps/trading-e2e/src/support/mocks/generate-statistics.ts b/apps/trading-e2e/src/support/mocks/generate-statistics.ts new file mode 100644 index 000000000..4b762e4db --- /dev/null +++ b/apps/trading-e2e/src/support/mocks/generate-statistics.ts @@ -0,0 +1,17 @@ +import type { StatisticsQuery } from '@vegaprotocol/environment'; +import merge from 'lodash/merge'; +import type { PartialDeep } from 'type-fest'; + +export const generateStatistics = ( + override?: PartialDeep +): StatisticsQuery => { + const defaultResult = { + statistics: { + __typename: 'Statistics', + chainId: 'test-chain-id', + blockHeight: '11', + }, + }; + + return merge(defaultResult, override); +}; diff --git a/apps/trading-e2e/src/support/trading.ts b/apps/trading-e2e/src/support/trading.ts index 7d4288fc2..8fe700357 100644 --- a/apps/trading-e2e/src/support/trading.ts +++ b/apps/trading-e2e/src/support/trading.ts @@ -1,13 +1,11 @@ import { aliasQuery } from '@vegaprotocol/cypress'; -import type { - MarketState, - MarketTradingMode, - AuctionTrigger, -} from '@vegaprotocol/types'; +import type { MarketTradingMode, AuctionTrigger } from '@vegaprotocol/types'; +import { MarketState } from '@vegaprotocol/types'; import type { CyHttpMessages } from 'cypress/types/net-stubbing'; import { generateAccounts } from './mocks/generate-accounts'; import { generateAsset, generateAssets } from './mocks/generate-assets'; import { generateCandles } from './mocks/generate-candles'; +import { generateChainId } from './mocks/generate-chain-id'; import { generateChart } from './mocks/generate-chart'; import { generateDealTicketQuery } from './mocks/generate-deal-ticket-query'; import { generateMarket, generateMarketData } from './mocks/generate-market'; @@ -18,16 +16,21 @@ import { generateMarketsData, generateMarketsCandles, } from './mocks/generate-markets'; +import { generateNetworkParameters } from './mocks/generate-network-parameters'; import { generateOrders } from './mocks/generate-orders'; import { generateMargins, generatePositions } from './mocks/generate-positions'; +import { generateStatistics } from './mocks/generate-statistics'; import { generateTrades } from './mocks/generate-trades'; +import { generateWithdrawals } from './mocks/generate-withdrawals'; -export const mockTradingPage = ( +const mockTradingPage = ( req: CyHttpMessages.IncomingHttpRequest, - state: MarketState, + state: MarketState = MarketState.STATE_ACTIVE, tradingMode?: MarketTradingMode, trigger?: AuctionTrigger ) => { + aliasQuery(req, 'ChainId', generateChainId()); + aliasQuery(req, 'Statistics', generateStatistics()); aliasQuery( req, 'Market', @@ -91,4 +94,30 @@ export const mockTradingPage = ( aliasQuery(req, 'Trades', generateTrades()); aliasQuery(req, 'Chart', generateChart()); aliasQuery(req, 'Candles', generateCandles()); + aliasQuery(req, 'Withdrawals', generateWithdrawals()); + aliasQuery(req, 'NetworkParamsQuery', generateNetworkParameters()); +}; + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface Chainable { + mockTradingPage( + state?: MarketState, + tradingMode?: MarketTradingMode, + trigger?: AuctionTrigger + ): void; + } + } +} +export const addMockTradingPage = () => { + Cypress.Commands.add( + 'mockTradingPage', + (state = MarketState.STATE_ACTIVE, tradingMode, trigger) => { + cy.mockGQL((req) => { + mockTradingPage(req, state, tradingMode, trigger); + }); + } + ); }; diff --git a/libs/environment/src/index.ts b/libs/environment/src/index.ts index e036a6e53..735d74739 100644 --- a/libs/environment/src/index.ts +++ b/libs/environment/src/index.ts @@ -6,3 +6,6 @@ export * from './hooks'; // Types export * from './types'; + +// Utils +export * from './utils/__generated__/Node';