Skip to content
75 changes: 45 additions & 30 deletions test/helpers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ export async function elementsByText(text: string, timeout = 8000): Promise<Chai
*/
export async function expectText(
text: string,
{ visible = true, strategy = 'exact', timeout = 30_000 }: { visible?: boolean; strategy?: RetrieveStrategy; timeout?: number } = {}
{
visible = true,
strategy = 'exact',
timeout = 30_000,
}: { visible?: boolean; strategy?: RetrieveStrategy; timeout?: number } = {}
) {
const el = await elementByText(text, strategy);
if (!visible) {
Expand Down Expand Up @@ -295,9 +299,13 @@ export async function getTotalBalance(): Promise<number> {
return Number(digits);
}

export type BalanceCondition = 'eq' | 'gt' | 'gte' | 'lt' | 'lte';
export type BalanceCondition = 'eq' | 'gt' | 'gte' | 'lt' | 'lte' | 'neq';

function checkBalanceCondition(value: number, expected: number, condition: BalanceCondition): boolean {
function checkBalanceCondition(
value: number,
expected: number,
condition: BalanceCondition
): boolean {
switch (condition) {
case 'eq':
return value === expected;
Expand All @@ -309,6 +317,8 @@ function checkBalanceCondition(value: number, expected: number, condition: Balan
return value < expected;
case 'lte':
return value <= expected;
case 'neq':
return value !== expected;
}
}

Expand Down Expand Up @@ -363,10 +373,10 @@ export async function expectTotalBalance(
return expectBalanceWithWait(getTotalBalance, 'total', expected, options);
}

export async function tap(testId: string) {
export async function tap(testId: string, { timeout = 30_000 }: { timeout?: number } = {}) {
const el = await elementById(testId);
await el.waitForDisplayed();
await sleep(150); // Allow time for the element to settle
await el.waitForDisplayed({ timeout });
await sleep(200); // Allow time for the element to settle
await el.click();
await sleep(100);
}
Expand Down Expand Up @@ -632,14 +642,7 @@ export async function completeOnboarding({ isFirstTime = true } = {}) {
}

// Wait for wallet to be created
for (let i = 1; i <= 3; i++) {
try {
await tap('WalletOnboardingClose');
break;
} catch {
if (i === 3) throw new Error('Tapping "WalletOnboardingClose" timeout');
}
}
await elementById('TotalBalance-primary').waitForDisplayed({ timeout: 60_000 });
}

export async function restoreWallet(
Expand Down Expand Up @@ -752,7 +755,11 @@ export async function waitForAnyText(texts: string[], timeout: number) {
await browser.waitUntil(
async () => {
for (const text of texts) {
if (await elementByText(text, 'contains').isDisplayed().catch(() => false)) {
if (
await elementByText(text, 'contains')
.isDisplayed()
.catch(() => false)
) {
return true;
}
}
Expand All @@ -770,7 +777,11 @@ export async function waitForTextToDisappear(texts: string[], timeout: number) {
await browser.waitUntil(
async () => {
for (const text of texts) {
if (await elementByText(text, 'contains').isDisplayed().catch(() => false)) {
if (
await elementByText(text, 'contains')
.isDisplayed()
.catch(() => false)
) {
return false;
}
}
Expand Down Expand Up @@ -870,8 +881,7 @@ export async function switchAndFundEachAddressType({
);
}
}
const moneyText = await elementByIdWithin('TotalBalance-primary', 'MoneyText');
await expect(moneyText).toHaveText(formatSats(satsPerAddressType * (i + 1)));
await expectTotalBalance(satsPerAddressType * (i + 1));

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

Expand Down Expand Up @@ -909,7 +919,9 @@ export async function transferSavingsToSpending({
await tap('TransferToSpending');
await sleep(800);

const hasSpendingIntro = await elementById('SpendingIntro-button').isDisplayed().catch(() => false);
const hasSpendingIntro = await elementById('SpendingIntro-button')
.isDisplayed()
.catch(() => false);
if (hasSpendingIntro) {
await tap('SpendingIntro-button');
await sleep(800);
Expand Down Expand Up @@ -964,7 +976,6 @@ export async function transferSavingsToSpending({
await expectTextWithin('Activity-1', 'Transfer', { timeout: 60_000 });
await expectTextWithin('Activity-1', '-');
await tap('NavigationBack');

} else {
await dismissBackgroundPaymentsTimedSheet({ triggerTimedSheet: false });
await dismissQuickPayIntro({ triggerTimedSheet: true });
Expand All @@ -973,7 +984,6 @@ export async function transferSavingsToSpending({
}

export async function transferSpendingToSavings() {

await tap('ActivitySpending');
await tap('TransferToSavings');
await sleep(800);
Expand Down Expand Up @@ -1107,8 +1117,6 @@ export async function receiveOnchainFunds({
blocksToMine?: number;
expectHighBalanceWarning?: boolean;
} = {}) {
const formattedSats = formatSats(sats);

// receive some first
const address = await getReceiveAddress();
await swipeFullScreen('down');
Expand All @@ -1118,8 +1126,9 @@ export async function receiveOnchainFunds({

await mineBlocks(blocksToMine);

const moneyText = await elementByIdWithin('TotalBalance-primary', 'MoneyText');
await expect(moneyText).toHaveText(formattedSats);
await expectTotalBalance(sats);
await expectSavingsBalance(sats);
await expectSpendingBalance(0);

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

export async function waitForToast(
toastId: ToastId,
{ waitToDisappear = false, dismiss = true , timeout = 30_000 }: { waitToDisappear?: boolean; dismiss?: boolean; timeout?: number } = {}
{
waitToDisappear = false,
dismiss = true,
timeout = 30_000,
}: { waitToDisappear?: boolean; dismiss?: boolean; timeout?: number } = {}
) {
await elementById(toastId).waitForDisplayed({ timeout });
if (waitToDisappear) {
Expand All @@ -1166,7 +1179,7 @@ export async function waitForToast(

/** Acknowledges the received payment notification by tapping the button.
*/
export async function acknowledgeReceivedPayment( { timeout = 20_000 }: { timeout?: number } = {}) {
export async function acknowledgeReceivedPayment({ timeout = 20_000 }: { timeout?: number } = {}) {
await elementById('ReceivedTransaction').waitForDisplayed({ timeout });
await sleep(500);
await tap('ReceivedTransactionButton');
Expand Down Expand Up @@ -1404,17 +1417,19 @@ export async function enterAddressViaScanPrompt(
}

export async function deleteAllDefaultWidgets() {
await swipeFullScreen('up');
await swipeFullScreen('up');
await tap('WidgetsEdit');
for (const w of ['Bitcoin Price', 'Bitcoin Blocks', 'Bitcoin Headlines']) {
for (const w of ['Bitcoin Price', 'Bitcoin Blocks', 'Bitkit Suggestions']) {
tap(w + '_WidgetActionDelete');
await elementByText('Yes, Delete').waitForDisplayed();
await elementByText('Yes, Delete').click();
await elementById(w).waitForDisplayed({ reverse: true, timeout: 5000 });
await sleep(500);
await sleep(1000);
}
await tap('WidgetsEdit');
await elementById('PriceWidget').waitForDisplayed({ reverse: true });
await elementById('NewsWidget').waitForDisplayed({ reverse: true });
await elementById('SuggestionsWidget').waitForDisplayed({ reverse: true });
await elementById('BlocksWidget').waitForDisplayed({ reverse: true });
}

Expand Down
9 changes: 5 additions & 4 deletions test/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ export function getBackend(): Backend {

export const electrumHost =
getBackend() === 'regtest'
? process.env.ELECTRUM_HOST ?? 'electrs.bitkit.stag0.blocktank.to'
? (process.env.ELECTRUM_HOST ?? 'electrs.bitkit.stag0.blocktank.to')
: getBackend() === 'mainnet'
? process.env.ELECTRUM_HOST ?? 'electrum.bitkit.to'
: process.env.ELECTRUM_HOST ?? '127.0.0.1';
? (process.env.ELECTRUM_HOST ?? 'electrum.bitkit.to')
: (process.env.ELECTRUM_HOST ?? '127.0.0.1');
export const electrumPort = Number.parseInt(
process.env.ELECTRUM_PORT ?? (getBackend() === 'regtest' ? '9999' : getBackend() === 'mainnet' ? '50001' : '60001'),
process.env.ELECTRUM_PORT ??
(getBackend() === 'regtest' ? '9999' : getBackend() === 'mainnet' ? '50001' : '60001'),
10
);

Expand Down
8 changes: 7 additions & 1 deletion test/specs/backup.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
receiveOnchainFunds,
restoreWallet,
sleep,
swipeFullScreen,
tap,
typeText,
waitForBackup,
Expand Down Expand Up @@ -90,7 +91,8 @@ describe('@backup - Backup', () => {
await tap('WidgetSave');
}
await elementById('PriceWidget').waitForDisplayed();

await elementById('SuggestionsWidget').waitForDisplayed({ reverse: true });
await elementById('BlocksWidget').waitForDisplayed({ reverse: true });
// - backup seed and restore wallet //
const seed = await getSeed();
await waitForBackup();
Expand All @@ -102,7 +104,11 @@ describe('@backup - Backup', () => {
const moneyFiatSymbol = await elementByIdWithin('TotalBalance', 'MoneyFiatSymbol');
await expect(moneyFiatSymbol).toHaveText('£');
// check widget
await swipeFullScreen('up');
await elementById('PriceWidget').waitForDisplayed();
await elementById('SuggestionsWidget').waitForDisplayed({ reverse: true });
await elementById('BlocksWidget').waitForDisplayed({ reverse: true });
await swipeFullScreen('down');
// check metadata
await tap('ActivitySavings');
await tap('Activity-1');
Expand Down
5 changes: 0 additions & 5 deletions test/specs/boost.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ describe('@boost - Boost', () => {
await receiveOnchainFunds({ sats: 100_000, blocksToMine: 0 });

// check Activity
await swipeFullScreen('up');
await expectTextWithin('ActivityShort-0', '100 000');
await expectTextWithin('ActivityShort-0', '+');

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

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

// check activity after restore
await swipeFullScreen('up');
await elementById('BoostingIcon').waitForDisplayed();
await elementById('ActivityShort-1').waitForDisplayed();
await tap('ActivityShort-1');
Expand Down Expand Up @@ -148,7 +145,6 @@ describe('@boost - Boost', () => {
await expect(moneyText).not.toHaveText('100 000');

// check Activity
await swipeFullScreen('up');
await elementById('ActivityShort-0').waitForDisplayed();
await expectTextWithin('ActivityShort-0', '-');
await elementById('ActivityShort-1').waitForDisplayed();
Expand Down Expand Up @@ -212,7 +208,6 @@ describe('@boost - Boost', () => {
await restoreWallet(seed);

// check activity after restore
await swipeFullScreen('up');
(await elementByIdWithin('ActivityShort-0', 'BoostingIcon')).waitForDisplayed();
await tap('ActivityShort-0');
await elementById('BoostedButton').waitForDisplayed();
Expand Down
8 changes: 0 additions & 8 deletions test/specs/lightning.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import initElectrum from '../helpers/electrum';
import {
completeOnboarding,
receiveOnchainFunds,
expectText,
enterAddress,
multiTap,
tap,
Expand Down Expand Up @@ -186,8 +185,6 @@ describe('@lightning - Lightning', () => {
await expectTextWithin('ActivitySpending', '9 000');

// check tx history
await swipeFullScreen('up');
await swipeFullScreen('up');
await expectTextWithin('ActivityShort-0', '1 000');
await expectTextWithin('ActivityShort-1', '111');
await expectTextWithin('ActivityShort-2', '111');
Expand All @@ -200,8 +197,6 @@ describe('@lightning - Lightning', () => {

// check activity filters & tags
await sleep(500); // wait for the app to settle
await swipeFullScreen('up');
await swipeFullScreen('up');
await tap('ActivityShowAll');

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

// check tx history
await swipeFullScreen('up');
await swipeFullScreen('up');
await expectTextWithin('ActivityShort-0', '1 000');
await expectTextWithin('ActivityShort-1', '111');
await expectTextWithin('ActivityShort-2', '111');
Expand Down Expand Up @@ -295,7 +288,6 @@ describe('@lightning - Lightning', () => {
}
await doNavigationClose();

await swipeFullScreen('up');
await expectTextWithin('ActivityShort-0', '9 000');
});
});
10 changes: 0 additions & 10 deletions test/specs/lnurl.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ describe('@lnurl - LNURL', () => {
await elementById('SendSuccess').waitForDisplayed();
await tap('Close');
await expectTextWithin('ActivitySpending', '19 851'); // 20 001 - 150
await swipeFullScreen('up');
await swipeFullScreen('up');
await elementById('ActivityShort-0').waitForDisplayed();
await expectTextWithin('ActivityShort-0', '150');
await expectTextWithin('ActivityShort-0', '-');
Expand Down Expand Up @@ -224,8 +222,6 @@ describe('@lnurl - LNURL', () => {
await elementById('SendSuccess').waitForDisplayed();
await tap('Close');
await expectTextWithin('ActivitySpending', '19 629'); // 19 851 - 222 = 19 629
await swipeFullScreen('up');
await swipeFullScreen('up');
await elementById('ActivityShort-0').waitForDisplayed();
await expectTextWithin('ActivityShort-0', '222');
await expectTextWithin('ActivityShort-0', '-');
Expand Down Expand Up @@ -255,8 +251,6 @@ describe('@lnurl - LNURL', () => {
await elementById('SendSuccess').waitForDisplayed();
await tap('Close');
await expectTextWithin('ActivitySpending', '19 308'); // 19 629 - 321 = 19 308
await swipeFullScreen('up');
await swipeFullScreen('up');
await elementById('ActivityShort-0').waitForDisplayed();
await expectTextWithin('ActivityShort-0', '321');
await expectTextWithin('ActivityShort-0', '-');
Expand All @@ -283,8 +277,6 @@ describe('@lnurl - LNURL', () => {
await tap('WithdrawConfirmButton');
await acknowledgeReceivedPayment();
await expectTextWithin('ActivitySpending', '19 410'); // 19 308 + 102 = 19 410
await swipeFullScreen('up');
await swipeFullScreen('up');
await elementById('ActivityShort-0').waitForDisplayed();
await expectTextWithin('ActivityShort-0', '102');
await expectTextWithin('ActivityShort-0', '+');
Expand All @@ -308,8 +300,6 @@ describe('@lnurl - LNURL', () => {
await tap('WithdrawConfirmButton');
await acknowledgeReceivedPayment();
await expectTextWithin('ActivitySpending', '19 713'); // 19 410 + 303 = 19 713
await swipeFullScreen('up');
await swipeFullScreen('up');
await elementById('ActivityShort-0').waitForDisplayed();
await expectTextWithin('ActivityShort-0', '303');
await expectTextWithin('ActivityShort-0', '+');
Expand Down
Loading