diff --git a/apps/trading-e2e/src/integration/trading-accounts.cy.ts b/apps/trading-e2e/src/integration/trading-accounts.cy.ts index df4278580..2592bea40 100644 --- a/apps/trading-e2e/src/integration/trading-accounts.cy.ts +++ b/apps/trading-e2e/src/integration/trading-accounts.cy.ts @@ -1,3 +1,5 @@ +import { checkSorting } from '@vegaprotocol/cypress'; + beforeEach(() => { cy.mockTradingPage(); cy.mockWeb3Provider(); @@ -128,29 +130,4 @@ describe('accounts', { tags: '@smoke' }, () => { ); }); }); - function checkSorting( - column: string, - orderTabDefault: string[], - orderTabAsc: string[], - orderTabDesc: string[] - ) { - checkSortChange(orderTabDefault, column); - cy.get('.ag-header-container').within(() => { - cy.get(`[col-id="${column}"]`).click(); - }); - checkSortChange(orderTabAsc, column); - cy.get('.ag-header-container').within(() => { - cy.get(`[col-id="${column}"]`).click(); - }); - checkSortChange(orderTabDesc, column); - } - function checkSortChange(tabsArr: string[], column: string) { - cy.get('.ag-center-cols-container').within(() => { - tabsArr.forEach((entry, i) => { - cy.get(`[row-index="${i}"]`).within(() => { - cy.get(`[col-id="${column}"]`).should('have.text', tabsArr[i]); - }); - }); - }); - } }); diff --git a/apps/trading-e2e/src/integration/trading-positions.cy.ts b/apps/trading-e2e/src/integration/trading-positions.cy.ts index d3af225f8..cecd0732b 100644 --- a/apps/trading-e2e/src/integration/trading-positions.cy.ts +++ b/apps/trading-e2e/src/integration/trading-positions.cy.ts @@ -1,3 +1,4 @@ +import { checkSorting } from '@vegaprotocol/cypress'; import { aliasGQLQuery } from '@vegaprotocol/cypress'; import { marketsDataQuery } from '@vegaprotocol/mock'; @@ -61,6 +62,54 @@ describe('positions', { tags: '@smoke' }, () => { }); }); + describe('sorting by ag-grid columns should work well', () => { + it('sorting by Market', () => { + cy.visit('/#/markets/market-0'); + const marketsSortedDefault = [ + 'ACTIVE MARKET', + 'Apple Monthly (30 Jun 2022)', + ]; + const marketsSortedAsc = ['ACTIVE MARKET', 'Apple Monthly (30 Jun 2022)']; + const marketsSortedDesc = [ + 'Apple Monthly (30 Jun 2022)', + 'ACTIVE MARKET', + ]; + cy.getByTestId('Positions').click(); + checkSorting( + 'marketName', + marketsSortedDefault, + marketsSortedAsc, + marketsSortedDesc + ); + }); + it('sorting by notional', () => { + cy.visit('/#/markets/market-0'); + const marketsSortedDefault = ['276,761.40348', '46,126.90058']; + const marketsSortedAsc = ['46,126.90058', '276,761.40348']; + const marketsSortedDesc = ['276,761.40348', '46,126.90058']; + cy.getByTestId('Positions').click(); + checkSorting( + 'notional', + marketsSortedDefault, + marketsSortedAsc, + marketsSortedDesc + ); + }); + it('sorting by unrealisedPNL', () => { + cy.visit('/#/markets/market-0'); + const marketsSortedDefault = ['8.95', '-0.22519']; + const marketsSortedAsc = ['-0.22519', '8.95']; + const marketsSortedDesc = ['8.95', '-0.22519']; + cy.getByTestId('Positions').click(); + checkSorting( + 'unrealisedPNL', + marketsSortedDefault, + marketsSortedAsc, + marketsSortedDesc + ); + }); + }); + function validatePositionsDisplayed() { cy.getByTestId('tab-positions').should('be.visible'); cy.getByTestId('tab-positions').within(() => { diff --git a/libs/cypress/src/lib/utils.ts b/libs/cypress/src/lib/utils.ts index d58064b7e..9e13e3563 100644 --- a/libs/cypress/src/lib/utils.ts +++ b/libs/cypress/src/lib/utils.ts @@ -36,3 +36,29 @@ export async function promiseWithTimeout( return await Promise.race([promise, rejectAfterTimeout(time)]); } + +export const checkSorting = ( + column: string, + orderTabDefault: string[], + orderTabAsc: string[], + orderTabDesc: string[] +) => { + checkSortChange(orderTabDefault, column); + cy.get('.ag-header-container').within(() => { + cy.get(`[col-id="${column}"]`).click(); + }); + checkSortChange(orderTabAsc, column); + cy.get('.ag-header-container').within(() => { + cy.get(`[col-id="${column}"]`).click(); + }); + checkSortChange(orderTabDesc, column); +}; +const checkSortChange = (tabsArr: string[], column: string) => { + cy.get('.ag-center-cols-container').within(() => { + tabsArr.forEach((entry, i) => { + cy.get(`[row-index="${i}"]`).within(() => { + cy.get(`[col-id="${column}"]`).should('have.text', tabsArr[i]); + }); + }); + }); +};