Skip to content

Commit b4f9049

Browse files
committed
test: e2e - simplify scrollToTheTop method
1 parent 2a7d201 commit b4f9049

File tree

7 files changed

+18
-31
lines changed

7 files changed

+18
-31
lines changed

packages/e2e-tests/src/assert/nftAssert.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import testContext from '../utils/testContext';
1111
import { Asset } from '../data/Asset';
1212
import adaHandleAssert from './adaHandleAssert';
1313
import NftsCommon from '../elements/NFTs/nftsCommon';
14+
import { scrollToTheTop } from '../utils/scrollUtils';
1415

1516
use(chaiSorted);
1617

@@ -124,7 +125,7 @@ class NftAssert {
124125
await NftsPage.waitForNft(nftName);
125126
} catch {
126127
if (!shouldBeDisplayed) {
127-
await NftsPage.scrollToTheTop();
128+
await scrollToTheTop();
128129
}
129130
}
130131
const nftItem = await NftsPage.getNftContainer(nftName);

packages/e2e-tests/src/assert/nftCreateFolderAssert.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import NftsFolderPage from '../elements/NFTs/nftsFolderPage';
1313
import adaHandleAssert from './adaHandleAssert';
1414
import { browser } from '@wdio/globals';
1515
import NftsCommon from '../elements/NFTs/nftsCommon';
16+
import { scrollToTheTop } from '../utils/scrollUtils';
1617

1718
class NftCreateFolderAssert {
1819
async assertSeeCreateFolderButton(shouldSee: boolean, mode: 'extended' | 'popup') {
@@ -100,7 +101,7 @@ class NftCreateFolderAssert {
100101
async verifySeeAllOwnedNfts() {
101102
const ownedNftNames = testContext.load('ownedNfts');
102103

103-
await TokenSelectionPage.scrollToTheTop(); // make sure we are starting from the top
104+
await scrollToTheTop(TokenSelectionPage.ASSET_SELECTOR_CONTAINER); // make sure we are starting from the top
104105

105106
const displayedNftNames = await NftsCommon.getAllNftNamesWithScroll(
106107
`${TokenSelectionPage.ASSET_SELECTOR_CONTAINER} ${TokenSelectionPage.NFT_CONTAINER}`

packages/e2e-tests/src/elements/NFTs/nftsPage.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ChainablePromiseArray } from 'webdriverio/build/types';
44
import { ChainablePromiseElement } from 'webdriverio';
55
import testContext from '../../utils/testContext';
66
import { browser } from '@wdio/globals';
7-
import { scrollDownWithOffset, scrollToTheTop } from '../../utils/scrollUtils';
7+
import { scrollDownWithOffset } from '../../utils/scrollUtils';
88
import NftsCommon from './nftsCommon';
99

1010
class NftsPage {
@@ -108,10 +108,6 @@ class NftsPage {
108108
}
109109
);
110110
}
111-
112-
async scrollToTheTop() {
113-
await scrollToTheTop(`${this.LIST_CONTAINER} ${this.NFT_CONTAINER}`);
114-
}
115111
}
116112

117113
export default new NftsPage();

packages/e2e-tests/src/elements/newTransaction/tokenSelectionPage.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import testContext from '../../utils/testContext';
44
import { generateRandomString } from '../../utils/textUtils';
55
import { TokenSearchResult } from './tokenSearchResult';
66
import { browser } from '@wdio/globals';
7-
import { scrollDownWithOffset, scrollToTheTop } from '../../utils/scrollUtils';
7+
import { scrollDownWithOffset } from '../../utils/scrollUtils';
88
import { ChainablePromiseElement } from 'webdriverio';
99

1010
class TokenSelectionPage extends CommonDrawerElements {
@@ -251,10 +251,6 @@ class TokenSelectionPage extends CommonDrawerElements {
251251
}
252252
}
253253
}
254-
255-
async scrollToTheTop() {
256-
await scrollToTheTop(`${this.ASSET_SELECTOR_CONTAINER} ${this.NFT_CONTAINER}`);
257-
}
258254
}
259255

260256
export default new TokenSelectionPage();

packages/e2e-tests/src/pageobject/newTransactionExtendedPageObject.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { byron, shelley } from '../data/AddressData';
66
import { AssetInput } from '../elements/newTransaction/assetInput';
77
import { AddressInput } from '../elements/AddressInput';
88
import NftsCommon from '../elements/NFTs/nftsCommon';
9+
import { scrollToTheTop } from '../utils/scrollUtils';
910

1011
export default new (class NewTransactionExtendedPageObject {
1112
async setTwoAssetsForBundle(bundleIndex: number, assetValue1: number, assetValue2: number) {
@@ -81,7 +82,7 @@ export default new (class NewTransactionExtendedPageObject {
8182
const nftNames = await NftsCommon.getAllNftNamesWithScroll(
8283
`${TokenSelectionPage.ASSET_SELECTOR_CONTAINER} ${TokenSelectionPage.NFT_CONTAINER}`
8384
);
84-
await TokenSelectionPage.scrollToTheTop();
85+
await scrollToTheTop();
8586
let nftsCount = nftNames.length;
8687
for (const nftName of nftNames) {
8788
nftsCount--;

packages/e2e-tests/src/steps/nftFoldersSteps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import testContext from '../utils/testContext';
1919
import MenuHeader from '../elements/menuHeader';
2020
import ToastMessage from '../elements/toastMessage';
2121
import { visit } from '../utils/pageUtils';
22+
import { scrollToTheTop } from '../utils/scrollUtils';
2223

2324
Given(/^all NFT folders are removed$/, async () => {
2425
await IndexedDB.clearNFTFolders();
@@ -207,7 +208,7 @@ Then(/^I can see "Add NFT" button active$/, async () => {
207208
When(
208209
/^I (left|right) click on the NFT folder with name "([^"]*)"$/,
209210
async (clickType: 'left' | 'right', folderName: string) => {
210-
await NftsPage.scrollToTheTop();
211+
await scrollToTheTop();
211212
const nftFolder = await NftsPage.getFolder(folderName);
212213
await nftFolder.click({ button: clickType });
213214
}

packages/e2e-tests/src/utils/scrollUtils.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,12 @@ export const scrollDownWithOffset = async (elements: WebdriverIO.ElementArray):
1919
}
2020
};
2121

22-
export const scrollToTheTop = async (elementsSelector: string): Promise<void> => {
23-
let elements = await $$(elementsSelector);
24-
let previousFirstElementName = elements.length > 0 ? await elements[0].getText() : 'not_found';
25-
26-
while (elements.length > 0) {
27-
const firstContainer = elements[0];
28-
await scrollToWithYOffset(firstContainer, -30);
29-
30-
elements = await $$(elementsSelector);
31-
const currentFirstElementName = elements.length > 0 ? await elements[0].getText() : 'not_found';
32-
33-
if (currentFirstElementName === previousFirstElementName) {
34-
break;
35-
}
36-
37-
previousFirstElementName = currentFirstElementName;
38-
}
22+
export const scrollToTheTop = async (parentSelector?: string): Promise<void> => {
23+
let selector = '';
24+
selector = parentSelector
25+
? `${parentSelector} [data-test-id="virtuoso-item-list"]`
26+
: '[data-test-id="virtuoso-item-list"]';
27+
const listComponent = await $(selector);
28+
await listComponent.scrollIntoView({ block: 'start', inline: 'start' });
29+
await browser.pause(500);
3930
};

0 commit comments

Comments
 (0)