diff --git a/apps/trading-e2e/src/integration/trading-accounts.cy.ts b/apps/trading-e2e/src/integration/trading-accounts.cy.ts deleted file mode 100644 index dd9412ce6..000000000 --- a/apps/trading-e2e/src/integration/trading-accounts.cy.ts +++ /dev/null @@ -1,127 +0,0 @@ -import { checkSorting } from '@vegaprotocol/cypress'; - -const dialogClose = 'dialog-close'; - -describe('accounts', { tags: '@smoke' }, () => { - beforeEach(() => { - cy.mockTradingPage(); - cy.mockWeb3Provider(); - cy.mockSubscription(); - cy.setVegaWallet(); - cy.visit('/#/markets/market-0'); - }); - - it('should open usage breakdown dialog when clicked on used', () => { - cy.getByTestId('Collateral').click(); - // 7001-COLL-009 - cy.get('[col-id="used"]').contains('1.01').click(); - const headers = ['Market', 'Account type', 'Balance', 'Margin health']; - cy.getByTestId('usage-breakdown').within(($headers) => { - cy.wrap($headers) - .get('.ag-header-cell-text') - .each(($header, i) => { - cy.wrap($header).should('have.text', headers[i]); - }); - }); - cy.getByTestId(dialogClose).click(); - }); - - describe('sorting by ag-grid columns should work well', () => { - before(() => { - const dialogs = Cypress.$('[data-testid="dialog-close"]:visible'); - if (dialogs.length > 0) { - dialogs.each((btn) => { - cy.wrap(btn).click(); - }); - } - cy.contains('Loading...').should('not.exist'); - }); - // 7001-COLL-010 - it('sorting by asset', () => { - cy.getByTestId('Collateral').click(); - const marketsSortedDefault = ['tBTC', 'tEURO', 'tDAI', 'tBTC']; - const marketsSortedAsc = ['tBTC', 'tBTC', 'tDAI', 'tEURO']; - const marketsSortedDesc = Array.from(marketsSortedAsc).reverse(); - checkSorting( - 'asset.symbol', - marketsSortedDefault, - marketsSortedAsc, - marketsSortedDesc - ); - }); - - it('sorting by total', () => { - cy.getByTestId('Collateral').click(); - const marketsSortedDefault = [ - '1,000.00002', - '1,000.01', - '1,000.00', - '1,000.00001', - ]; - const marketsSortedAsc = [ - '1,000.00', - '1,000.00001', - '1,000.00002', - '1,000.01', - ]; - const marketsSortedDesc = Array.from(marketsSortedAsc).reverse(); - - checkSorting( - 'total', - marketsSortedDefault, - marketsSortedAsc, - marketsSortedDesc - ); - }); - - it('sorting by used', () => { - cy.getByTestId('Collateral').click(); - // concat actual value with percentage value - // as cypress will pick up the entire cell contes - // textContent - const marketsSortedDefault = [ - '0.00' + '0.00%', - '0.01' + '0.00%', - '0.00' + '0.00%', - '0.00' + '0.00%', - ]; - const marketsSortedAsc = [ - '0.00' + '0.00%', - '0.00' + '0.00%', - '0.00' + '0.00%', - '0.01' + '0.00%', - ]; - const marketsSortedDesc = Array.from(marketsSortedAsc).reverse(); - checkSorting( - 'used', - marketsSortedDefault, - marketsSortedAsc, - marketsSortedDesc - ); - }); - - it('sorting by available', () => { - cy.getByTestId('Collateral').click(); - const marketsSortedDefault = [ - '1,000.00002', - '1,000.00', - '1,000.00', - '1,000.00001', - ]; - const marketsSortedAsc = [ - '1,000.00', - '1,000.00', - '1,000.00001', - '1,000.00002', - ]; - const marketsSortedDesc = Array.from(marketsSortedAsc).reverse(); - - checkSorting( - 'available', - marketsSortedDefault, - marketsSortedAsc, - marketsSortedDesc - ); - }); - }); -}); diff --git a/libs/accounts/src/lib/accounts-table.spec.tsx b/libs/accounts/src/lib/accounts-table.spec.tsx index 3f5051d55..737a66864 100644 --- a/libs/accounts/src/lib/accounts-table.spec.tsx +++ b/libs/accounts/src/lib/accounts-table.spec.tsx @@ -3,6 +3,7 @@ import * as Types from '@vegaprotocol/types'; import type { AccountFields } from './accounts-data-provider'; import { getAccountData } from './accounts-data-provider'; import { AccountTable } from './accounts-table'; +import userEvent from '@testing-library/user-event'; const singleRow = { __typename: 'AccountBalance', @@ -24,6 +25,26 @@ const singleRow = { } as AccountFields; const singleRowData = [singleRow]; +const secondRow = { + __typename: 'AccountBalance', + type: Types.AccountType.ACCOUNT_TYPE_MARGIN, + balance: '125600002', + market: { + __typename: 'Market', + id: '10cd0a793ad2887b340940337fa6d97a212e0e517fe8e9eab2b5ef3a38633f35', + }, + asset: { + __typename: 'Asset', + id: '5cfa87844724df6069b94e4c8a6f03af21907d7bc251593d08e4251043ee9f7c', + symbol: 'aBTC', + decimals: 5, + }, + available: '125600001', + used: '125600001', + total: '251200002', +} as AccountFields; +const multiRowData = [singleRow, secondRow]; + describe('AccountsTable', () => { it('should render correct columns', async () => { // 7001-COLL-001 @@ -68,6 +89,25 @@ describe('AccountsTable', () => { expect(rows?.childElementCount).toBe(1); }); + it('should sort assets', async () => { + // 7001-COLL-010 + const { container } = render( + null} + isReadOnly={false} + /> + ); + + const headerCell = screen.getByText('Asset'); + await userEvent.click(headerCell); + const rows = container.querySelectorAll( + '.ag-center-cols-container .ag-row' + ); + expect(rows[0].textContent).toContain('aBTC'); + expect(rows[1].textContent).toContain('tBTC'); + }); + it('should apply correct formatting in view as user mode', async () => { const { container } = render(