@@ -134,7 +134,11 @@ export async function elementsByText(text: string, timeout = 8000): Promise<Chai
134134 */
135135export 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
645648export 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
975986export 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
11531162export 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
14061419export 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
0 commit comments