Skip to content

Commit 3bd81eb

Browse files
authored
Merge pull request #76 from synonymdev/test/transfer
Test/transfer
2 parents 67bad9f + a3b90d7 commit 3bd81eb

File tree

4 files changed

+117
-58
lines changed

4 files changed

+117
-58
lines changed

test/helpers/actions.ts

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,34 @@ export async function expectText(
170170
export async function expectTextWithin(
171171
ancestorId: string,
172172
text: string,
173-
{ visible = true, timeout = 30_000 }: { visible?: boolean; timeout?: number } = {}
173+
{
174+
visible = true,
175+
timeout = 30_000,
176+
strategy = 'contains',
177+
}: {
178+
visible?: boolean;
179+
timeout?: number;
180+
strategy?: RetrieveStrategy;
181+
} = {}
174182
) {
175183
const parent = elementById(ancestorId);
176184
await parent.waitForDisplayed();
177185

178186
if (driver.isIOS) {
179187
const parentLabel = await parent.getAttribute('label');
180188
const parentValue = await parent.getAttribute('value');
181-
const matchesParent =
182-
(typeof parentLabel === 'string' && parentLabel.includes(text)) ||
183-
(typeof parentValue === 'string' && parentValue.includes(text));
189+
const matchesParent = (() => {
190+
if (strategy === 'exact') {
191+
return (
192+
(typeof parentLabel === 'string' && parentLabel === text) ||
193+
(typeof parentValue === 'string' && parentValue === text)
194+
);
195+
}
196+
return (
197+
(typeof parentLabel === 'string' && parentLabel.includes(text)) ||
198+
(typeof parentValue === 'string' && parentValue.includes(text))
199+
);
200+
})();
184201

185202
if (matchesParent) {
186203
if (!visible) {
@@ -190,9 +207,15 @@ export async function expectTextWithin(
190207
}
191208
}
192209

193-
const needle = driver.isAndroid
194-
? `.//*[contains(@text,'${text}')]`
195-
: `.//*[self::XCUIElementTypeStaticText or self::XCUIElementTypeTextView or self::XCUIElementTypeTextField][contains(@label,'${text}') or contains(@value,'${text}')]`;
210+
const needle = (() => {
211+
if (driver.isAndroid) {
212+
return strategy === 'exact' ? `.//*[@text='${text}']` : `.//*[contains(@text,'${text}')]`;
213+
}
214+
215+
return strategy === 'exact'
216+
? `.//*[self::XCUIElementTypeStaticText or self::XCUIElementTypeTextView or self::XCUIElementTypeTextField][@label='${text}' or @value='${text}']`
217+
: `.//*[self::XCUIElementTypeStaticText or self::XCUIElementTypeTextView or self::XCUIElementTypeTextField][contains(@label,'${text}') or contains(@value,'${text}')]`;
218+
})();
196219

197220
if (!visible) {
198221
await parent.$(needle).waitForDisplayed({ reverse: true, timeout });
@@ -201,6 +224,10 @@ export async function expectTextWithin(
201224
}
202225
}
203226

227+
export async function expectNoTextWithin(ancestorId: string, text: string) {
228+
await expectTextWithin(ancestorId, text, { visible: false, strategy: 'exact' });
229+
}
230+
204231
type Index = number | 'first' | 'last';
205232
/**
206233
* Get text from a descendant text element under a container.
@@ -703,6 +730,15 @@ export async function acknowledgeReceivedPayment() {
703730
await sleep(300);
704731
}
705732

733+
/** Acknowledges the external success notification by tapping the button.
734+
*/
735+
export async function acknowledgeExternalSuccess() {
736+
await elementById('ExternalSuccess').waitForDisplayed();
737+
await sleep(500);
738+
await tap('ExternalSuccess-button');
739+
await sleep(300);
740+
}
741+
706742
/**
707743
* Triggers the timed backup sheet by navigating to settings and back.
708744
* Since timed sheets are sometimes triggered by user behavior (when user goes back to home screen),

test/specs/lnurl.e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
dismissBackgroundPaymentsTimedSheet,
2525
enterAddressViaScanPrompt,
2626
acknowledgeReceivedPayment,
27+
acknowledgeExternalSuccess,
2728
} from '../helpers/actions';
2829
import { reinstallApp } from '../helpers/setup';
2930
import { ciIt } from '../helpers/suite';
@@ -142,8 +143,7 @@ describe('@lnurl - LNURL', () => {
142143
// Success toast/flow
143144
if (driver.isIOS) await waitForToast('SpendingBalanceReadyToast');
144145
if (driver.isAndroid) await dismissQuickPayIntro();
145-
await elementById('ExternalSuccess').waitForDisplayed({ timeout: 30_000 });
146-
await tap('ExternalSuccess-button');
146+
await acknowledgeExternalSuccess();
147147
if (driver.isIOS) {
148148
await dismissBackgroundPaymentsTimedSheet();
149149
await dismissQuickPayIntro({ triggerTimedSheet: driver.isIOS });

test/specs/numberpad.e2e.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
sleep,
88
tap,
99
doNavigationClose,
10+
expectTextWithin,
1011
} from '../helpers/actions';
1112
import { launchFreshApp, reinstallApp } from '../helpers/setup';
1213
import { ciIt } from '../helpers/suite';
@@ -78,8 +79,11 @@ async function modernDenominationChecks(mode: NumberpadMode) {
7879
await tap(`${mode}NumberPadUnit`);
7980
// reset to 0
8081
await multiTap('NRemove', 8);
81-
await expectText('0.00');
82-
82+
if (mode === 'Send') {
83+
await expectTextWithin('SendNumberField', '0.00');
84+
} else {
85+
await expectTextWithin('ReceiveNumberPadTextField', '0.00');
86+
}
8387
await tap('N0');
8488
await tap('N0');
8589
await tap('N1');
@@ -110,7 +114,11 @@ async function classicDenominationChecks(mode: NumberpadMode) {
110114

111115
// reset to 0
112116
await multiTap('NRemove', 2);
113-
await expectText('0.00000000');
117+
if (mode === 'Send') {
118+
await expectTextWithin('SendNumberField', '0.00000000');
119+
} else {
120+
await expectTextWithin('ReceiveNumberPadTextField', '0.00000000');
121+
}
114122
await tap('N4');
115123
await tap('NDecimal');
116124
await tap('N2');

test/specs/transfer.e2e.ts

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import {
2020
dismissQuickPayIntro,
2121
doNavigationClose,
2222
waitForToast,
23+
getTextUnder,
24+
acknowledgeExternalSuccess,
25+
dismissBackgroundPaymentsTimedSheet,
26+
expectNoTextWithin,
2327
} from '../helpers/actions';
2428
import {
2529
checkChannelStatus,
@@ -83,40 +87,36 @@ describe('@transfer - Transfer', () => {
8387
await elementByText('EUR (€)').click();
8488
await doNavigationClose();
8589

86-
await launchFreshApp();
90+
if (driver.isAndroid) await launchFreshApp();
8791
await tap('Suggestion-lightning');
8892
await tap('TransferIntro-button');
8993
await tap('FundTransfer');
9094
await tap('SpendingIntro-button');
9195
await sleep(3000); // let the animation finish
9296

93-
//--- skip due to: https://github.com/synonymdev/bitkit-android/issues/425 ---//
94-
//// can continue with default client balance (0)
95-
//await tap('SpendingAmountContinue');
96-
//await sleep(100);
97-
//await tap('SpendingConfirmAdvanced');
98-
//await tap('SpendingAdvancedMin');
99-
//await expectTextVisible('100 000');
100-
//await tap('SpendingAdvancedDefault');
101-
//await tap('SpendingAdvancedNumberField'); // change to fiat
102-
//const label = await getTextUnder('SpendingAdvancedNumberField');
103-
//const eurBalance = Number.parseInt(label, 10);
104-
//await expect(eurBalance).toBeGreaterThan(440);
105-
//await expect(eurBalance).toBeLessThan(460);
106-
//await tap('SpendingAdvancedNumberField'); // change back to sats
107-
//await tap('SpendingAdvancedContinue');
108-
//await tap('NavigationBack');
109-
//--- skip due to: https://github.com/synonymdev/bitkit-android/issues/425 ---//
110-
111-
//--- skip due to: https://github.com/synonymdev/bitkit-android/issues/424 ---//
97+
// can continue with default client balance (0)
98+
await tap('SpendingAmountContinue');
99+
await sleep(100);
100+
await tap('SpendingConfirmAdvanced');
101+
await tap('SpendingAdvancedMin');
102+
await expectText('100 000', { strategy: 'contains' });
103+
await tap('SpendingAdvancedDefault');
104+
await tap('SpendingAdvancedNumberField'); // change to fiat
105+
const label = await getTextUnder('SpendingAdvancedNumberField');
106+
const eurBalance = Number.parseInt(label, 10);
107+
await expect(eurBalance).toBeGreaterThan(440);
108+
await expect(eurBalance).toBeLessThan(460);
109+
await tap('SpendingAdvancedNumberField'); // change back to sats
110+
await tap('SpendingAdvancedContinue');
111+
await tap('NavigationBack');
112+
112113
// can continue with max client balance
113-
//await tap('SpendingAmountMax');
114-
//await elementById('SpendingAmountContinue').waitForEnabled();
115-
//await sleep(500);
116-
//await tap('SpendingAmountContinue');
117-
//await elementById('SpendingConfirmAdvanced').waitForDisplayed();
118-
//await tap('NavigationBack');
119-
//--- skip due to: https://github.com/synonymdev/bitkit-android/issues/424 ---//
114+
await tap('SpendingAmountMax');
115+
await elementById('SpendingAmountContinue').waitForEnabled();
116+
await sleep(500);
117+
await tap('SpendingAmountContinue');
118+
await elementById('SpendingConfirmAdvanced').waitForDisplayed();
119+
await tap('NavigationBack');
120120

121121
// can continue with 25% client balance
122122
await elementById('SpendingAmountQuarter').waitForEnabled();
@@ -133,7 +133,7 @@ describe('@transfer - Transfer', () => {
133133
await tap('N2');
134134
await multiTap('N0', 5);
135135
await tap('SpendingAmountContinue');
136-
await expectText('200 000');
136+
await expectText('200 000', { strategy: 'contains' });
137137
await tap('SpendingConfirmMore');
138138
await expectText('200 000');
139139
await tap('LiquidityContinue');
@@ -145,6 +145,7 @@ describe('@transfer - Transfer', () => {
145145
// verify transfer activity on savings
146146
await tap('ActivitySavings');
147147
await elementById('Activity-1').waitForDisplayed();
148+
await elementById('Activity-2').waitForDisplayed();
148149
await expectTextWithin('Activity-1', 'Transfer', { timeout: 60_000 });
149150
await expectTextWithin('Activity-1', '-');
150151
await tap('NavigationBack');
@@ -158,7 +159,7 @@ describe('@transfer - Transfer', () => {
158159
await tap('N1');
159160
await multiTap('N0', 5);
160161
await tap('SpendingAmountContinue');
161-
await expectText('100 000');
162+
await expectText('100 000', { strategy: 'contains' });
162163
await sleep(500);
163164
await tap('SpendingConfirmAdvanced');
164165
await sleep(500);
@@ -213,6 +214,8 @@ describe('@transfer - Transfer', () => {
213214
// verify both transfers activities on savings
214215
await tap('ActivitySavings');
215216
await elementById('Activity-1').waitForDisplayed();
217+
await elementById('Activity-2').waitForDisplayed();
218+
await elementById('Activity-3').waitForDisplayed();
216219
await expectTextWithin('Activity-1', 'Transfer');
217220
await expectTextWithin('Activity-1', '-');
218221
await elementById('Activity-2').waitForDisplayed();
@@ -228,7 +231,7 @@ describe('@transfer - Transfer', () => {
228231
await tap('AdvancedSettings');
229232
await tap('Channels');
230233
const channels = await elementsById('Channel');
231-
channels[1].click();
234+
channels[driver.isAndroid ? 1 : 0].click();
232235
await expectTextWithin('TotalSize', '₿ 250 000');
233236
await expectText('Processing payment');
234237
await doNavigationClose();
@@ -298,23 +301,28 @@ describe('@transfer - Transfer', () => {
298301
await sleep(500);
299302

300303
// change fee
301-
await tap('SetCustomFee');
302-
await sleep(500);
303-
await tap('NRemove');
304-
await sleep(1000); // wait for input to register
305-
await tap('FeeCustomContinue');
306-
await tap('N5');
307-
await sleep(1000); // wait for input to register
308-
await tap('FeeCustomContinue');
309-
310-
// Swipe to confirm (set x offset to avoid navigating back)
304+
// this should be removed from Andorid:
305+
// https://github.com/synonymdev/bitkit-android/issues/548
306+
if (driver.isAndroid) {
307+
await tap('SetCustomFee');
308+
await sleep(500);
309+
await tap('NRemove');
310+
await sleep(1000); // wait for input to register
311+
await tap('FeeCustomContinue');
312+
await tap('N5');
313+
await sleep(1000); // wait for input to register
314+
await tap('FeeCustomContinue');
315+
}
316+
317+
// Swipe to confirm
311318
await dragOnElement('GRAB', 'right', 0.95);
312319
console.info('channel opening...');
313320
await sleep(1000);
314-
await elementById('ExternalSuccess').waitForDisplayed();
315-
await tap('ExternalSuccess-button');
316-
await tap('NavigationBack');
317-
await doNavigationClose();
321+
await acknowledgeExternalSuccess();
322+
if (driver.isAndroid) {
323+
await tap('NavigationBack');
324+
await doNavigationClose();
325+
}
318326

319327
// check transfer card
320328
// await elementById('Suggestion-lightning_setting_up').waitForDisplayed();
@@ -334,7 +342,14 @@ describe('@transfer - Transfer', () => {
334342
await mineBlocks(rpc, 6);
335343
await electrum?.waitForSync();
336344
await waitForToast('SpendingBalanceReadyToast');
337-
await dismissQuickPayIntro();
345+
await sleep(1000);
346+
if (driver.isIOS) {
347+
await dismissBackgroundPaymentsTimedSheet({ triggerTimedSheet: driver.isIOS });
348+
await dismissQuickPayIntro({ triggerTimedSheet: driver.isIOS });
349+
} else {
350+
await dismissQuickPayIntro();
351+
}
352+
await expectNoTextWithin('ActivitySpending', '0');
338353
await waitForActiveChannel(lnd, ldkNodeId);
339354

340355
// check transfer card
@@ -364,7 +379,7 @@ describe('@transfer - Transfer', () => {
364379
await dragOnElement('GRAB', 'right', 0.95);
365380
await elementById('TransferSuccess').waitForDisplayed();
366381
await tap('TransferSuccess-button');
367-
await tap('NavigationBack');
382+
if (driver.isAndroid) await tap('NavigationBack');
368383

369384
// check channel is closed
370385
await tap('HeaderMenu');

0 commit comments

Comments
 (0)