Skip to content

Commit

Permalink
test: e2e - simplify scrollToTheTop method
Browse files Browse the repository at this point in the history
  • Loading branch information
ljagiela committed Jan 25, 2025
1 parent 2a7d201 commit cd9d5b0
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 40 deletions.
3 changes: 2 additions & 1 deletion packages/e2e-tests/src/assert/nftAssert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import testContext from '../utils/testContext';
import { Asset } from '../data/Asset';
import adaHandleAssert from './adaHandleAssert';
import NftsCommon from '../elements/NFTs/nftsCommon';
import { scrollToTheTop } from '../utils/scrollUtils';

use(chaiSorted);

Expand Down Expand Up @@ -124,7 +125,7 @@ class NftAssert {
await NftsPage.waitForNft(nftName);
} catch {
if (!shouldBeDisplayed) {
await NftsPage.scrollToTheTop();
await scrollToTheTop();
}
}
const nftItem = await NftsPage.getNftContainer(nftName);
Expand Down
3 changes: 2 additions & 1 deletion packages/e2e-tests/src/assert/nftCreateFolderAssert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import NftsFolderPage from '../elements/NFTs/nftsFolderPage';
import adaHandleAssert from './adaHandleAssert';
import { browser } from '@wdio/globals';
import NftsCommon from '../elements/NFTs/nftsCommon';
import { scrollToTheTop } from '../utils/scrollUtils';

class NftCreateFolderAssert {
async assertSeeCreateFolderButton(shouldSee: boolean, mode: 'extended' | 'popup') {
Expand Down Expand Up @@ -100,7 +101,7 @@ class NftCreateFolderAssert {
async verifySeeAllOwnedNfts() {
const ownedNftNames = testContext.load('ownedNfts');

await TokenSelectionPage.scrollToTheTop(); // make sure we are starting from the top
await scrollToTheTop(TokenSelectionPage.ASSET_SELECTOR_CONTAINER); // make sure we are starting from the top

const displayedNftNames = await NftsCommon.getAllNftNamesWithScroll(
`${TokenSelectionPage.ASSET_SELECTOR_CONTAINER} ${TokenSelectionPage.NFT_CONTAINER}`
Expand Down
6 changes: 1 addition & 5 deletions packages/e2e-tests/src/elements/NFTs/nftsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ChainablePromiseArray } from 'webdriverio/build/types';
import { ChainablePromiseElement } from 'webdriverio';
import testContext from '../../utils/testContext';
import { browser } from '@wdio/globals';
import { scrollDownWithOffset, scrollToTheTop } from '../../utils/scrollUtils';
import { scrollDownWithOffset } from '../../utils/scrollUtils';
import NftsCommon from './nftsCommon';

class NftsPage {
Expand Down Expand Up @@ -108,10 +108,6 @@ class NftsPage {
}
);
}

async scrollToTheTop() {
await scrollToTheTop(`${this.LIST_CONTAINER} ${this.NFT_CONTAINER}`);
}
}

export default new NftsPage();
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import testContext from '../../utils/testContext';
import { generateRandomString } from '../../utils/textUtils';
import { TokenSearchResult } from './tokenSearchResult';
import { browser } from '@wdio/globals';
import { scrollDownWithOffset, scrollToTheTop } from '../../utils/scrollUtils';
import { scrollDownWithOffset } from '../../utils/scrollUtils';
import { ChainablePromiseElement } from 'webdriverio';

class TokenSelectionPage extends CommonDrawerElements {
Expand Down Expand Up @@ -186,15 +186,6 @@ class TokenSelectionPage extends CommonDrawerElements {
return tokenInfo;
};

getNftNames = async () => {
const nftInfo = [];
const numberOfNFTs = await this.nftNames.length;
for (let i = 0; i < numberOfNFTs; i++) {
nftInfo.push(await this.nftNames[i].getText());
}
return nftInfo;
};

searchAsset = async (assetName: string) => {
if (assetName === 'random characters') {
assetName = await generateRandomString(10);
Expand Down Expand Up @@ -251,10 +242,6 @@ class TokenSelectionPage extends CommonDrawerElements {
}
}
}

async scrollToTheTop() {
await scrollToTheTop(`${this.ASSET_SELECTOR_CONTAINER} ${this.NFT_CONTAINER}`);
}
}

export default new TokenSelectionPage();
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { byron, shelley } from '../data/AddressData';
import { AssetInput } from '../elements/newTransaction/assetInput';
import { AddressInput } from '../elements/AddressInput';
import NftsCommon from '../elements/NFTs/nftsCommon';
import { scrollToTheTop } from '../utils/scrollUtils';

export default new (class NewTransactionExtendedPageObject {
async setTwoAssetsForBundle(bundleIndex: number, assetValue1: number, assetValue2: number) {
Expand Down Expand Up @@ -81,7 +82,7 @@ export default new (class NewTransactionExtendedPageObject {
const nftNames = await NftsCommon.getAllNftNamesWithScroll(
`${TokenSelectionPage.ASSET_SELECTOR_CONTAINER} ${TokenSelectionPage.NFT_CONTAINER}`
);
await TokenSelectionPage.scrollToTheTop();
await scrollToTheTop();
let nftsCount = nftNames.length;
for (const nftName of nftNames) {
nftsCount--;
Expand Down
3 changes: 2 additions & 1 deletion packages/e2e-tests/src/steps/nftFoldersSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import testContext from '../utils/testContext';
import MenuHeader from '../elements/menuHeader';
import ToastMessage from '../elements/toastMessage';
import { visit } from '../utils/pageUtils';
import { scrollToTheTop } from '../utils/scrollUtils';

Given(/^all NFT folders are removed$/, async () => {
await IndexedDB.clearNFTFolders();
Expand Down Expand Up @@ -207,7 +208,7 @@ Then(/^I can see "Add NFT" button active$/, async () => {
When(
/^I (left|right) click on the NFT folder with name "([^"]*)"$/,
async (clickType: 'left' | 'right', folderName: string) => {
await NftsPage.scrollToTheTop();
await scrollToTheTop();
const nftFolder = await NftsPage.getFolder(folderName);
await nftFolder.click({ button: clickType });
}
Expand Down
24 changes: 7 additions & 17 deletions packages/e2e-tests/src/utils/scrollUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,11 @@ export const scrollDownWithOffset = async (elements: WebdriverIO.ElementArray):
}
};

export const scrollToTheTop = async (elementsSelector: string): Promise<void> => {
let elements = await $$(elementsSelector);
let previousFirstElementName = elements.length > 0 ? await elements[0].getText() : 'not_found';

while (elements.length > 0) {
const firstContainer = elements[0];
await scrollToWithYOffset(firstContainer, -30);

elements = await $$(elementsSelector);
const currentFirstElementName = elements.length > 0 ? await elements[0].getText() : 'not_found';

if (currentFirstElementName === previousFirstElementName) {
break;
}

previousFirstElementName = currentFirstElementName;
}
export const scrollToTheTop = async (parentSelector?: string): Promise<void> => {
const selector = parentSelector
? `${parentSelector} [data-test-id="virtuoso-item-list"]`
: '[data-test-id="virtuoso-item-list"]';
const listComponent = await $(selector);
await listComponent.scrollIntoView({ block: 'start', inline: 'start' });
await browser.pause(500);
};

0 comments on commit cd9d5b0

Please sign in to comment.