Skip to content

Commit

Permalink
Merge branch 'main' into test/update-hw-wallet-test
Browse files Browse the repository at this point in the history
  • Loading branch information
wklos-iohk authored Apr 19, 2024
2 parents a643649 + 6aa6964 commit 140e590
Show file tree
Hide file tree
Showing 21 changed files with 402 additions and 419 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { StakePoolListItem } from '../../elements/multidelegation/StakePoolListI
import Tooltip from '../../elements/Tooltip';
import testContext from '../../utils/testContext';
import { StakePoolGridCard } from '../../elements/multidelegation/StakePoolGridCard';
import { StakePoolListColumnName } from '../../types/staking';
import { SortingOrder } from '../../types/sortingOrder';
import { mapColumnNameStringToEnum, sortColumnContent } from '../../utils/stakePoolListContent';
import { StakePoolListColumn } from '../../enums/StakePoolListColumn';

class MultidelegationPageAssert {
assertSeeStakingOnPoolsCounter = async (poolsCount: number) => {
Expand Down Expand Up @@ -188,36 +192,37 @@ class MultidelegationPageAssert {
expect(await firstStakePool.ticker.getText()).to.equal(expectedTicker);
};

assertSeeTooltipForColumn = async (columnName: string) => {
assertSeeTooltipForColumn = async (column: StakePoolListColumn) => {
await MultidelegationPage.tooltip.waitForStable();
await MultidelegationPage.tooltip.waitForDisplayed();
let expectedTooltipText;
switch (columnName) {
case 'Ticker':
switch (column) {
case StakePoolListColumn.Ticker:
expectedTooltipText = await t('browsePools.tooltips.ticker', 'staking');
break;
case 'Saturation':
case StakePoolListColumn.Saturation:
expectedTooltipText = await t('browsePools.tooltips.saturation', 'staking');
break;
case 'ROS':
case StakePoolListColumn.ROS:
expectedTooltipText = await t('browsePools.tooltips.ros', 'staking');
break;
case 'Cost':
case StakePoolListColumn.Cost:
expectedTooltipText = await t('browsePools.tooltips.cost', 'staking');
break;
case 'Margin':
case StakePoolListColumn.Margin:
expectedTooltipText = await t('browsePools.tooltips.margin', 'staking');
break;
case 'Blocks':
case StakePoolListColumn.Blocks:
expectedTooltipText = await t('browsePools.tooltips.blocks', 'staking');
break;
case 'Pledge':
case StakePoolListColumn.Pledge:
expectedTooltipText = await t('browsePools.tooltips.pledge', 'staking');
break;
case 'Live Stake':
case StakePoolListColumn.LiveStake:
expectedTooltipText = await t('browsePools.tooltips.liveStake', 'staking');
break;
default:
throw new Error(`Unsupported column name: ${columnName}`);
throw new Error(`Unsupported column name: ${column}`);
}
expect(await MultidelegationPage.tooltip.getText()).to.equal(expectedTooltipText);
};
Expand Down Expand Up @@ -300,6 +305,39 @@ class MultidelegationPageAssert {
const cardsInARow = Math.floor(rowWidth / cardWidth);
expect(cardsInARow).to.equal(expectedCardsCount);
};

assertSeeColumnSortingIndicator = async (column: StakePoolListColumnName, order: 'ascending' | 'descending') => {
await (
await MultidelegationPage.getColumnSortingIndicator(mapColumnNameStringToEnum(column), order)
).waitForDisplayed();
};

assertSeeStakePoolsSorted = async (
stakePoolsDisplayType: 'list rows' | 'cards',
sortingOption: StakePoolListColumnName,
order: SortingOrder,
poolLimit?: number
) => {
await MultidelegationPage.waitForPoolsCounterToBeGreaterThanZero();
poolLimit ??= await MultidelegationPage.getNumberOfPoolsFromCounter();
if (stakePoolsDisplayType === 'cards') {
// TODO: add code to handle grid cards - LW-10284
throw new Error('Please add validation for grid cards sorting');
} else {
const columnContent = await MultidelegationPage.extractColumnContent(
mapColumnNameStringToEnum(sortingOption),
poolLimit
);
const sortedColumnContent = await sortColumnContent(
columnContent,
mapColumnNameStringToEnum(sortingOption),
order
);

expect(columnContent).to.not.be.empty;
expect(columnContent).to.deep.equal(sortedColumnContent);
}
};
}

export default new MultidelegationPageAssert();
17 changes: 0 additions & 17 deletions packages/e2e-tests/src/assert/stakingPageAssert.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import StakingPage from '../elements/staking/stakingPage';
import { TestnetPatterns } from '../support/patterns';
import webTester from '../actor/webTester';
import StakingInfoComponent from '../elements/staking/stakingInfoComponent';
import { t } from '../utils/translationService';
import { StakePoolListItem } from '../elements/staking/StakePoolListItem';
import StakingSuccessDrawer from '../elements/staking/StakingSuccessDrawer';
import { Logger } from '../support/logger';
import StakingExtendedPageObject from '../pageobject/stakingExtendedPageObject';
import { sortColumnContent } from '../utils/stakePoolListContent';
import { expect } from 'chai';
import { StakePool } from '../data/expectedStakePoolsData';
import StakingPasswordDrawer from '../elements/staking/StakingPasswordDrawer';
Expand Down Expand Up @@ -114,18 +109,6 @@ class StakingPageAssert {
});
};

assertStakePoolItemsOrder = async (columnName: string, order: string) => {
const stakePoolListItem = new StakePoolListItem();
await webTester.waitUntilSeeElement(stakePoolListItem.container(), 60_000);
const columnContent: string[] = await StakingExtendedPageObject.extractColumnContent(columnName);
Logger.log(`EXTRACTED DATA: ${columnContent}`);
const sortedColumnContent = await sortColumnContent(columnContent, columnName, order);
Logger.log(`SORTED DATA: ${sortedColumnContent}`);

expect(columnContent).to.not.be.empty;
expect(columnContent).to.deep.equal(sortedColumnContent);
};

assertSeeStakingPasswordDrawer = async () => {
await StakingPasswordDrawer.title.waitForDisplayed();
expect(await StakingPasswordDrawer.title.getText()).to.equal(
Expand Down
153 changes: 130 additions & 23 deletions packages/e2e-tests/src/elements/multidelegation/MultidelegationPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import StakePoolDetails from '../staking/stakePoolDetails';
import testContext from '../../utils/testContext';
import { isPopupMode } from '../../utils/pageUtils';
import CommonDrawerElements from '../CommonDrawerElements';
import { StakePoolListColumnType } from '../../types/staking';
import { StakePoolListItem } from './StakePoolListItem';
import { StakePoolGridCard } from './StakePoolGridCard';
import StakePoolDetailsDrawer from './StakePoolDetailsDrawer';
import MoreOptionsComponent from './MoreOptionsComponent';
import { StakePoolListColumn } from '../../enums/StakePoolListColumn';

class MultidelegationPage {
private ACTIVITY_TAB = '[data-testid="activity-tab"]';
Expand Down Expand Up @@ -41,6 +41,7 @@ class MultidelegationPage {
private COLUMN_HEADER_BLOCKS = '[data-testid="stake-pool-list-header-blocks"]';
private COLUMN_HEADER_PLEDGE = '[data-testid="stake-pool-list-header-pledge"]';
private COLUMN_HEADER_LIVE_STAKE = '[data-testid="stake-pool-list-header-liveStake"]';
private COLUMN_SORTING_INDICATOR_TEMPLATE = '[data-testid="stake-pool-sort-order-###"]';
private MANAGE_STAKING_BTN_NEXT = '[data-testid="preferences-next-button"]';
private CONFIRMATION_BTN_NEXT = '[data-testid="stake-pool-confirmation-btn"]';
private DELEGATED_POOL_ITEM = '[data-testid="delegated-pool-item"]';
Expand Down Expand Up @@ -73,6 +74,7 @@ class MultidelegationPage {
private STAKE_POOL_CARD_SKELETON = '[data-testid="stake-pool-card-skeleton"]';
private SELCECTED_STAKE_POOLS_IN_GRID_VIEW = '[data-testid="selected-pools-list"] [data-testid="stake-pool-card"]';
private SELCECTED_STAKE_POOLS_IN_LIST_VIEW = '[data-testid="selected-pools-list"] [data-testid="stake-pool-item"]';
private POOLS_COUNTER = '[data-testid="pools-counter"]';

get title() {
return SectionTitle.sectionTitle;
Expand Down Expand Up @@ -214,6 +216,10 @@ class MultidelegationPage {
return $(this.MANAGE_BTN);
}

get poolsCounter() {
return $(this.POOLS_COUNTER);
}

delegatedPoolLogo(index: number): ChainablePromiseElement<WebdriverIO.Element> {
return $$(this.DELEGATED_POOL_ITEM)[index].$(this.DELEGATED_POOL_LOGO);
}
Expand Down Expand Up @@ -300,6 +306,43 @@ class MultidelegationPage {
)) as WebdriverIO.Element;
}

async getColumnSortingIndicator(columnName: StakePoolListColumn, order: 'ascending' | 'descending') {
const orderDirection = order === 'ascending' ? 'asc' : 'desc';
const orderDirectionSelector = `${this.COLUMN_SORTING_INDICATOR_TEMPLATE.replace('###', orderDirection)}`;
let selector = '';

switch (columnName) {
case StakePoolListColumn.Ticker:
selector = `${this.COLUMN_HEADER_TICKER} ${orderDirectionSelector}`;
break;
case StakePoolListColumn.Saturation:
selector = `${this.COLUMN_HEADER_SATURATION} ${orderDirectionSelector}`;
break;
case StakePoolListColumn.ROS:
selector = `${this.COLUMN_HEADER_ROS} ${orderDirectionSelector}`;
break;
case StakePoolListColumn.Cost:
selector = `${this.COLUMN_HEADER_COST} ${orderDirectionSelector}`;
break;
case StakePoolListColumn.Margin:
selector = `${this.COLUMN_HEADER_MARGIN} ${orderDirectionSelector}`;
break;
case StakePoolListColumn.Blocks:
selector = `${this.COLUMN_HEADER_BLOCKS} ${orderDirectionSelector}`;
break;
case StakePoolListColumn.Pledge:
selector = `${this.COLUMN_HEADER_PLEDGE} ${orderDirectionSelector}`;
break;
case StakePoolListColumn.LiveStake:
selector = `${this.COLUMN_HEADER_LIVE_STAKE} ${orderDirectionSelector}`;
break;
default:
throw new Error(`Unsupported column name: ${columnName}`);
}

return $(selector);
}

async clickAndGetTabStateAttribute(tab: 'Overview' | 'Browse pools') {
let tabElement;
switch (tab) {
Expand Down Expand Up @@ -418,68 +461,69 @@ class MultidelegationPage {
await poolItem.click();
}

async hoverOverColumnWithName(columnName: StakePoolListColumnType) {
async hoverOverColumn(column: StakePoolListColumn) {
let header;
switch (columnName) {
case 'Ticker':

switch (column) {
case StakePoolListColumn.Ticker:
header = await this.columnHeaderTicker;
break;
case 'Saturation':
case StakePoolListColumn.Saturation:
header = await this.columnHeaderSaturation;
break;
case 'ROS':
case StakePoolListColumn.ROS:
header = await this.columnHeaderROS;
break;
case 'Cost':
case StakePoolListColumn.Cost:
header = await this.columnHeaderCost;
break;
case 'Margin':
case StakePoolListColumn.Margin:
header = await this.columnHeaderMargin;
break;
case 'Blocks':
case StakePoolListColumn.Blocks:
header = await this.columnHeaderBlocks;
break;
case 'Pledge':
case StakePoolListColumn.Pledge:
header = await this.columnHeaderPledge;
break;
case 'Live Stake':
case StakePoolListColumn.LiveStake:
header = await this.columnHeaderLiveStake;
break;
default:
throw new Error(`Unsupported column name: ${columnName}`);
throw new Error(`Unsupported column name: ${column}`);
}
// make hovering over ANTD component more stable
await header?.$('span span span').moveTo();
}

async clickOnColumnWithName(columnName: StakePoolListColumnType) {
switch (columnName) {
case 'Ticker':
async clickOnColumn(column: StakePoolListColumn) {
switch (column) {
case StakePoolListColumn.Ticker:
await this.columnHeaderTicker.click();
break;
case 'Saturation':
case StakePoolListColumn.Saturation:
await this.columnHeaderSaturation.click();
break;
case 'ROS':
case StakePoolListColumn.ROS:
await this.columnHeaderROS.click();
break;
case 'Cost':
case StakePoolListColumn.Cost:
await this.columnHeaderCost.click();
break;
case 'Margin':
case StakePoolListColumn.Margin:
await this.columnHeaderMargin.click();
break;
case 'Blocks':
case StakePoolListColumn.Blocks:
await this.columnHeaderBlocks.click();
break;
case 'Pledge':
case StakePoolListColumn.Pledge:
await this.columnHeaderPledge.click();
break;
case 'Live Stake':
case StakePoolListColumn.LiveStake:
await this.columnHeaderLiveStake.click();
break;
default:
throw new Error(`Unsupported column name: ${columnName}`);
throw new Error(`Unsupported column name: ${column}`);
}
}

Expand Down Expand Up @@ -543,6 +587,69 @@ class MultidelegationPage {
const selectedTickers = await this.getTickersOfSelectedPools(viewType);
testContext.save('selectedTickers', selectedTickers);
}

async getNumberOfPoolsFromCounter(): Promise<number> {
const poolsCounterText = await this.poolsCounter.getText();
return Number(Number(poolsCounterText.replace(/.*\(/, '').replace(')', '').replace(',', '')));
}

async waitForPoolsCounterToBeGreaterThanZero(): Promise<void> {
await this.poolsCounter.waitForDisplayed();
await browser.waitUntil(async () => (await this.getNumberOfPoolsFromCounter()) > 0, {
timeoutMsg: 'No stake pools!'
});
}

async extractColumnContent(columnName: StakePoolListColumn, poolLimit = 100): Promise<string[]> {
const columnContent: string[] = [];

await this.listContainer.waitForStable();
await browser.pause(500);

for (let i = 0; i < poolLimit; i++) {
const displayedPoolsCounter = await this.displayedPools.length;
const listItem = new StakePoolListItem(i);
// Load more pools if all visible ones were processed
if (i % (displayedPoolsCounter - 1) === 0) {
await listItem.container.scrollIntoView();
await this.stakePoolListRowSkeleton.waitForExist({
reverse: true,
interval: 100,
timeout: 30_000
});
}
switch (columnName) {
case StakePoolListColumn.Ticker:
columnContent.push(await listItem.ticker.getText());
break;
case StakePoolListColumn.Saturation:
columnContent.push(await listItem.saturation.getText());
break;
case StakePoolListColumn.ROS:
columnContent.push(await listItem.ros.getText());
break;
case StakePoolListColumn.Cost:
columnContent.push(await listItem.cost.getText());
break;
case StakePoolListColumn.Margin:
columnContent.push(await listItem.margin.getText());
break;
case StakePoolListColumn.Blocks:
columnContent.push(await listItem.blocks.getText());
break;
case StakePoolListColumn.Pledge:
columnContent.push(await listItem.pledge.getText());
break;
case StakePoolListColumn.LiveStake:
columnContent.push(await listItem.liveStake.getText());
break;
default:
throw new Error(`Not supported column name: ${columnName}`);
}
}

return columnContent;
}
}

export default new MultidelegationPage();
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ChainablePromiseElement } from 'webdriverio';

export class StakePoolListItem {
private SELECTED_POOLS_LIST = '[data-testid="selected-pools-list"]';
private AVAILABLE_POOLS_LIST = '[data-testid="stake-pool-list-scroll-wrapper"]';
private LIST_ITEM = '[data-testid="stake-pool-item"]';
private CHECKBOX = '[data-testid="stake-pool-list-checkbox"]';
private TICKER = '[data-testid="stake-pool-list-ticker"]';
Expand All @@ -18,9 +17,9 @@ export class StakePoolListItem {
protected listItem;

constructor(index = 0, isOnSelectedPoolsList = false) {
this.listItem = $(isOnSelectedPoolsList ? this.SELECTED_POOLS_LIST : this.AVAILABLE_POOLS_LIST).$$(this.LIST_ITEM)[
index
];
this.listItem = $(
isOnSelectedPoolsList ? `${this.SELECTED_POOLS_LIST} ${this.LIST_ITEM}` : `[data-item-index="${index}"]`
);
}

get container(): ChainablePromiseElement<WebdriverIO.Element | undefined> {
Expand Down
Loading

0 comments on commit 140e590

Please sign in to comment.