chore: fix chainId mock (#1777)

* chore: fix chainId popup

* chore: cleanup
This commit is contained in:
Radosław Szpiech 2022-10-19 13:14:52 +02:00 committed by GitHub
parent a6576132b1
commit ab760eee58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 93 additions and 133 deletions

View File

@ -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

View File

@ -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');
});

View File

@ -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('/');
});

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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<Order>) => {
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();

View File

@ -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');

View File

@ -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();

View File

@ -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();
});

View File

@ -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');
});

View File

@ -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');

View File

@ -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();

View File

@ -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>
): StatisticsQuery => {
const defaultResult = {
statistics: {
__typename: 'Statistics',
chainId: 'test-chain-id',
blockHeight: '11',
},
};
return merge(defaultResult, override);
};

View File

@ -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<Subject> {
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);
});
}
);
};

View File

@ -6,3 +6,6 @@ export * from './hooks';
// Types
export * from './types';
// Utils
export * from './utils/__generated__/Node';