Skip to content

Commit ed1cdc1

Browse files
authored
Merge pull request #128 from synonymdev/feat/home-redesign
[e2e updates] Feat/home redesign adjustments
2 parents 7a7472e + 96fb5fc commit ed1cdc1

17 files changed

Lines changed: 215 additions & 219 deletions

test/helpers/actions.ts

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ export async function elementsByText(text: string, timeout = 8000): Promise<Chai
134134
*/
135135
export async function expectText(
136136
text: string,
137-
{ visible = true, strategy = 'exact', timeout = 30_000 }: { visible?: boolean; strategy?: RetrieveStrategy; timeout?: number } = {}
137+
{
138+
visible = true,
139+
strategy = 'exact',
140+
timeout = 30_000,
141+
}: { visible?: boolean; strategy?: RetrieveStrategy; timeout?: number } = {}
138142
) {
139143
const el = await elementByText(text, strategy);
140144
if (!visible) {
@@ -295,9 +299,13 @@ export async function getTotalBalance(): Promise<number> {
295299
return Number(digits);
296300
}
297301

298-
export type BalanceCondition = 'eq' | 'gt' | 'gte' | 'lt' | 'lte';
302+
export type BalanceCondition = 'eq' | 'gt' | 'gte' | 'lt' | 'lte' | 'neq';
299303

300-
function checkBalanceCondition(value: number, expected: number, condition: BalanceCondition): boolean {
304+
function checkBalanceCondition(
305+
value: number,
306+
expected: number,
307+
condition: BalanceCondition
308+
): boolean {
301309
switch (condition) {
302310
case 'eq':
303311
return value === expected;
@@ -309,6 +317,8 @@ function checkBalanceCondition(value: number, expected: number, condition: Balan
309317
return value < expected;
310318
case 'lte':
311319
return value <= expected;
320+
case 'neq':
321+
return value !== expected;
312322
}
313323
}
314324

@@ -363,10 +373,10 @@ export async function expectTotalBalance(
363373
return expectBalanceWithWait(getTotalBalance, 'total', expected, options);
364374
}
365375

366-
export async function tap(testId: string) {
376+
export async function tap(testId: string, { timeout = 30_000 }: { timeout?: number } = {}) {
367377
const el = await elementById(testId);
368-
await el.waitForDisplayed();
369-
await sleep(150); // Allow time for the element to settle
378+
await el.waitForDisplayed({ timeout });
379+
await sleep(200); // Allow time for the element to settle
370380
await el.click();
371381
await sleep(100);
372382
}
@@ -632,14 +642,7 @@ export async function completeOnboarding({ isFirstTime = true } = {}) {
632642
}
633643

634644
// Wait for wallet to be created
635-
for (let i = 1; i <= 3; i++) {
636-
try {
637-
await tap('WalletOnboardingClose');
638-
break;
639-
} catch {
640-
if (i === 3) throw new Error('Tapping "WalletOnboardingClose" timeout');
641-
}
642-
}
645+
await elementById('TotalBalance-primary').waitForDisplayed({ timeout: 60_000 });
643646
}
644647

645648
export async function restoreWallet(
@@ -752,7 +755,11 @@ export async function waitForAnyText(texts: string[], timeout: number) {
752755
await browser.waitUntil(
753756
async () => {
754757
for (const text of texts) {
755-
if (await elementByText(text, 'contains').isDisplayed().catch(() => false)) {
758+
if (
759+
await elementByText(text, 'contains')
760+
.isDisplayed()
761+
.catch(() => false)
762+
) {
756763
return true;
757764
}
758765
}
@@ -770,7 +777,11 @@ export async function waitForTextToDisappear(texts: string[], timeout: number) {
770777
await browser.waitUntil(
771778
async () => {
772779
for (const text of texts) {
773-
if (await elementByText(text, 'contains').isDisplayed().catch(() => false)) {
780+
if (
781+
await elementByText(text, 'contains')
782+
.isDisplayed()
783+
.catch(() => false)
784+
) {
774785
return false;
775786
}
776787
}
@@ -870,8 +881,7 @@ export async function switchAndFundEachAddressType({
870881
);
871882
}
872883
}
873-
const moneyText = await elementByIdWithin('TotalBalance-primary', 'MoneyText');
874-
await expect(moneyText).toHaveText(formatSats(satsPerAddressType * (i + 1)));
884+
await expectTotalBalance(satsPerAddressType * (i + 1));
875885

876886
fundedAddresses.push({ type: addressType, address });
877887

@@ -909,7 +919,9 @@ export async function transferSavingsToSpending({
909919
await tap('TransferToSpending');
910920
await sleep(800);
911921

912-
const hasSpendingIntro = await elementById('SpendingIntro-button').isDisplayed().catch(() => false);
922+
const hasSpendingIntro = await elementById('SpendingIntro-button')
923+
.isDisplayed()
924+
.catch(() => false);
913925
if (hasSpendingIntro) {
914926
await tap('SpendingIntro-button');
915927
await sleep(800);
@@ -964,7 +976,6 @@ export async function transferSavingsToSpending({
964976
await expectTextWithin('Activity-1', 'Transfer', { timeout: 60_000 });
965977
await expectTextWithin('Activity-1', '-');
966978
await tap('NavigationBack');
967-
968979
} else {
969980
await dismissBackgroundPaymentsTimedSheet({ triggerTimedSheet: false });
970981
await dismissQuickPayIntro({ triggerTimedSheet: true });
@@ -973,7 +984,6 @@ export async function transferSavingsToSpending({
973984
}
974985

975986
export async function transferSpendingToSavings() {
976-
977987
await tap('ActivitySpending');
978988
await tap('TransferToSavings');
979989
await sleep(800);
@@ -1107,8 +1117,6 @@ export async function receiveOnchainFunds({
11071117
blocksToMine?: number;
11081118
expectHighBalanceWarning?: boolean;
11091119
} = {}) {
1110-
const formattedSats = formatSats(sats);
1111-
11121120
// receive some first
11131121
const address = await getReceiveAddress();
11141122
await swipeFullScreen('down');
@@ -1118,8 +1126,9 @@ export async function receiveOnchainFunds({
11181126

11191127
await mineBlocks(blocksToMine);
11201128

1121-
const moneyText = await elementByIdWithin('TotalBalance-primary', 'MoneyText');
1122-
await expect(moneyText).toHaveText(formattedSats);
1129+
await expectTotalBalance(sats);
1130+
await expectSavingsBalance(sats);
1131+
await expectSpendingBalance(0);
11231132

11241133
await dismissBackupTimedSheet({ triggerTimedSheet: true });
11251134
if (expectHighBalanceWarning) {
@@ -1152,7 +1161,11 @@ export type ToastId =
11521161

11531162
export async function waitForToast(
11541163
toastId: ToastId,
1155-
{ waitToDisappear = false, dismiss = true , timeout = 30_000 }: { waitToDisappear?: boolean; dismiss?: boolean; timeout?: number } = {}
1164+
{
1165+
waitToDisappear = false,
1166+
dismiss = true,
1167+
timeout = 30_000,
1168+
}: { waitToDisappear?: boolean; dismiss?: boolean; timeout?: number } = {}
11561169
) {
11571170
await elementById(toastId).waitForDisplayed({ timeout });
11581171
if (waitToDisappear) {
@@ -1166,7 +1179,7 @@ export async function waitForToast(
11661179

11671180
/** Acknowledges the received payment notification by tapping the button.
11681181
*/
1169-
export async function acknowledgeReceivedPayment( { timeout = 20_000 }: { timeout?: number } = {}) {
1182+
export async function acknowledgeReceivedPayment({ timeout = 20_000 }: { timeout?: number } = {}) {
11701183
await elementById('ReceivedTransaction').waitForDisplayed({ timeout });
11711184
await sleep(500);
11721185
await tap('ReceivedTransactionButton');
@@ -1404,17 +1417,19 @@ export async function enterAddressViaScanPrompt(
14041417
}
14051418

14061419
export async function deleteAllDefaultWidgets() {
1420+
await swipeFullScreen('up');
1421+
await swipeFullScreen('up');
14071422
await tap('WidgetsEdit');
1408-
for (const w of ['Bitcoin Price', 'Bitcoin Blocks', 'Bitcoin Headlines']) {
1423+
for (const w of ['Bitcoin Price', 'Bitcoin Blocks', 'Bitkit Suggestions']) {
14091424
tap(w + '_WidgetActionDelete');
14101425
await elementByText('Yes, Delete').waitForDisplayed();
14111426
await elementByText('Yes, Delete').click();
14121427
await elementById(w).waitForDisplayed({ reverse: true, timeout: 5000 });
1413-
await sleep(500);
1428+
await sleep(1000);
14141429
}
14151430
await tap('WidgetsEdit');
14161431
await elementById('PriceWidget').waitForDisplayed({ reverse: true });
1417-
await elementById('NewsWidget').waitForDisplayed({ reverse: true });
1432+
await elementById('SuggestionsWidget').waitForDisplayed({ reverse: true });
14181433
await elementById('BlocksWidget').waitForDisplayed({ reverse: true });
14191434
}
14201435

test/helpers/constants.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ export function getBackend(): Backend {
3333

3434
export const electrumHost =
3535
getBackend() === 'regtest'
36-
? process.env.ELECTRUM_HOST ?? 'electrs.bitkit.stag0.blocktank.to'
36+
? (process.env.ELECTRUM_HOST ?? 'electrs.bitkit.stag0.blocktank.to')
3737
: getBackend() === 'mainnet'
38-
? process.env.ELECTRUM_HOST ?? 'electrum.bitkit.to'
39-
: process.env.ELECTRUM_HOST ?? '127.0.0.1';
38+
? (process.env.ELECTRUM_HOST ?? 'electrum.bitkit.to')
39+
: (process.env.ELECTRUM_HOST ?? '127.0.0.1');
4040
export const electrumPort = Number.parseInt(
41-
process.env.ELECTRUM_PORT ?? (getBackend() === 'regtest' ? '9999' : getBackend() === 'mainnet' ? '50001' : '60001'),
41+
process.env.ELECTRUM_PORT ??
42+
(getBackend() === 'regtest' ? '9999' : getBackend() === 'mainnet' ? '50001' : '60001'),
4243
10
4344
);
4445

test/specs/backup.e2e.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
receiveOnchainFunds,
1313
restoreWallet,
1414
sleep,
15+
swipeFullScreen,
1516
tap,
1617
typeText,
1718
waitForBackup,
@@ -90,7 +91,8 @@ describe('@backup - Backup', () => {
9091
await tap('WidgetSave');
9192
}
9293
await elementById('PriceWidget').waitForDisplayed();
93-
94+
await elementById('SuggestionsWidget').waitForDisplayed({ reverse: true });
95+
await elementById('BlocksWidget').waitForDisplayed({ reverse: true });
9496
// - backup seed and restore wallet //
9597
const seed = await getSeed();
9698
await waitForBackup();
@@ -102,7 +104,11 @@ describe('@backup - Backup', () => {
102104
const moneyFiatSymbol = await elementByIdWithin('TotalBalance', 'MoneyFiatSymbol');
103105
await expect(moneyFiatSymbol).toHaveText('£');
104106
// check widget
107+
await swipeFullScreen('up');
105108
await elementById('PriceWidget').waitForDisplayed();
109+
await elementById('SuggestionsWidget').waitForDisplayed({ reverse: true });
110+
await elementById('BlocksWidget').waitForDisplayed({ reverse: true });
111+
await swipeFullScreen('down');
106112
// check metadata
107113
await tap('ActivitySavings');
108114
await tap('Activity-1');

test/specs/boost.e2e.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ describe('@boost - Boost', () => {
4444
await receiveOnchainFunds({ sats: 100_000, blocksToMine: 0 });
4545

4646
// check Activity
47-
await swipeFullScreen('up');
4847
await expectTextWithin('ActivityShort-0', '100 000');
4948
await expectTextWithin('ActivityShort-0', '+');
5049

@@ -77,7 +76,6 @@ describe('@boost - Boost', () => {
7776
await expectTextWithin('ActivityShort-1', '+');
7877

7978
// orig tx still there
80-
await swipeFullScreen('up');
8179
await tap('ActivityShort-1');
8280
await expectText('100 000', { strategy: 'contains' });
8381
await elementById('BoostedButton').waitForDisplayed();
@@ -106,7 +104,6 @@ describe('@boost - Boost', () => {
106104
await restoreWallet(seed);
107105

108106
// check activity after restore
109-
await swipeFullScreen('up');
110107
await elementById('BoostingIcon').waitForDisplayed();
111108
await elementById('ActivityShort-1').waitForDisplayed();
112109
await tap('ActivityShort-1');
@@ -148,7 +145,6 @@ describe('@boost - Boost', () => {
148145
await expect(moneyText).not.toHaveText('100 000');
149146

150147
// check Activity
151-
await swipeFullScreen('up');
152148
await elementById('ActivityShort-0').waitForDisplayed();
153149
await expectTextWithin('ActivityShort-0', '-');
154150
await elementById('ActivityShort-1').waitForDisplayed();
@@ -212,7 +208,6 @@ describe('@boost - Boost', () => {
212208
await restoreWallet(seed);
213209

214210
// check activity after restore
215-
await swipeFullScreen('up');
216211
(await elementByIdWithin('ActivityShort-0', 'BoostingIcon')).waitForDisplayed();
217212
await tap('ActivityShort-0');
218213
await elementById('BoostedButton').waitForDisplayed();

test/specs/lightning.e2e.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import initElectrum from '../helpers/electrum';
22
import {
33
completeOnboarding,
44
receiveOnchainFunds,
5-
expectText,
65
enterAddress,
76
multiTap,
87
tap,
@@ -186,8 +185,6 @@ describe('@lightning - Lightning', () => {
186185
await expectTextWithin('ActivitySpending', '9 000');
187186

188187
// check tx history
189-
await swipeFullScreen('up');
190-
await swipeFullScreen('up');
191188
await expectTextWithin('ActivityShort-0', '1 000');
192189
await expectTextWithin('ActivityShort-1', '111');
193190
await expectTextWithin('ActivityShort-2', '111');
@@ -200,8 +197,6 @@ describe('@lightning - Lightning', () => {
200197

201198
// check activity filters & tags
202199
await sleep(500); // wait for the app to settle
203-
await swipeFullScreen('up');
204-
await swipeFullScreen('up');
205200
await tap('ActivityShowAll');
206201

207202
// All transactions
@@ -257,8 +252,6 @@ describe('@lightning - Lightning', () => {
257252
await expectTextWithin('ActivitySpending', '9 000');
258253

259254
// check tx history
260-
await swipeFullScreen('up');
261-
await swipeFullScreen('up');
262255
await expectTextWithin('ActivityShort-0', '1 000');
263256
await expectTextWithin('ActivityShort-1', '111');
264257
await expectTextWithin('ActivityShort-2', '111');
@@ -295,7 +288,6 @@ describe('@lightning - Lightning', () => {
295288
}
296289
await doNavigationClose();
297290

298-
await swipeFullScreen('up');
299291
await expectTextWithin('ActivityShort-0', '9 000');
300292
});
301293
});

test/specs/lnurl.e2e.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ describe('@lnurl - LNURL', () => {
185185
await elementById('SendSuccess').waitForDisplayed();
186186
await tap('Close');
187187
await expectTextWithin('ActivitySpending', '19 851'); // 20 001 - 150
188-
await swipeFullScreen('up');
189-
await swipeFullScreen('up');
190188
await elementById('ActivityShort-0').waitForDisplayed();
191189
await expectTextWithin('ActivityShort-0', '150');
192190
await expectTextWithin('ActivityShort-0', '-');
@@ -224,8 +222,6 @@ describe('@lnurl - LNURL', () => {
224222
await elementById('SendSuccess').waitForDisplayed();
225223
await tap('Close');
226224
await expectTextWithin('ActivitySpending', '19 629'); // 19 851 - 222 = 19 629
227-
await swipeFullScreen('up');
228-
await swipeFullScreen('up');
229225
await elementById('ActivityShort-0').waitForDisplayed();
230226
await expectTextWithin('ActivityShort-0', '222');
231227
await expectTextWithin('ActivityShort-0', '-');
@@ -255,8 +251,6 @@ describe('@lnurl - LNURL', () => {
255251
await elementById('SendSuccess').waitForDisplayed();
256252
await tap('Close');
257253
await expectTextWithin('ActivitySpending', '19 308'); // 19 629 - 321 = 19 308
258-
await swipeFullScreen('up');
259-
await swipeFullScreen('up');
260254
await elementById('ActivityShort-0').waitForDisplayed();
261255
await expectTextWithin('ActivityShort-0', '321');
262256
await expectTextWithin('ActivityShort-0', '-');
@@ -283,8 +277,6 @@ describe('@lnurl - LNURL', () => {
283277
await tap('WithdrawConfirmButton');
284278
await acknowledgeReceivedPayment();
285279
await expectTextWithin('ActivitySpending', '19 410'); // 19 308 + 102 = 19 410
286-
await swipeFullScreen('up');
287-
await swipeFullScreen('up');
288280
await elementById('ActivityShort-0').waitForDisplayed();
289281
await expectTextWithin('ActivityShort-0', '102');
290282
await expectTextWithin('ActivityShort-0', '+');
@@ -308,8 +300,6 @@ describe('@lnurl - LNURL', () => {
308300
await tap('WithdrawConfirmButton');
309301
await acknowledgeReceivedPayment();
310302
await expectTextWithin('ActivitySpending', '19 713'); // 19 410 + 303 = 19 713
311-
await swipeFullScreen('up');
312-
await swipeFullScreen('up');
313303
await elementById('ActivityShort-0').waitForDisplayed();
314304
await expectTextWithin('ActivityShort-0', '303');
315305
await expectTextWithin('ActivityShort-0', '+');

0 commit comments

Comments
 (0)