1
1
import { strict as assert } from 'assert' ;
2
2
import { Suite } from 'mocha' ;
3
- import { Driver } from '../../webdriver/driver' ;
4
3
import { DEFAULT_BTC_ACCOUNT , DEFAULT_BTC_BALANCE } from '../../constants' ;
5
- import {
6
- getTransactionRequest ,
7
- SendFlowPlaceHolders ,
8
- withBtcAccountSnap ,
9
- } from './common-btc' ;
10
-
11
- export async function startSendFlow ( driver : Driver , recipient ?: string ) {
12
- // Wait a bit so the MultichainRatesController is able to fetch BTC -> USD rates.
13
- await driver . delay ( 1000 ) ;
14
-
15
- // Start the send flow.
16
- const sendButton = await driver . waitForSelector ( {
17
- text : 'Send' ,
18
- tag : 'button' ,
19
- css : '[data-testid="coin-overview-send"]' ,
20
- } ) ;
21
- // FIXME: Firefox test is flaky without this delay. The send flow doesn't start properly.
22
- if ( driver . browser === 'firefox' ) {
23
- await driver . delay ( 1000 ) ;
24
- }
25
- await sendButton . click ( ) ;
26
-
27
- // See the review button is disabled by default.
28
- await driver . waitForSelector ( {
29
- text : 'Review' ,
30
- tag : 'button' ,
31
- css : '[disabled]' ,
32
- } ) ;
33
-
34
- if ( recipient ) {
35
- // Set the recipient address (if any).
36
- await driver . pasteIntoField (
37
- `input[placeholder="${ SendFlowPlaceHolders . RECIPIENT } "]` ,
38
- recipient ,
39
- ) ;
40
- }
41
- }
4
+ import ActivityListPage from '../../page-objects/pages/home/activity-list' ;
5
+ import BitcoinSendPage from '../../page-objects/pages/send/bitcoin-send-page' ;
6
+ import BitcoinHomepage from '../../page-objects/pages/home/bitcoin-homepage' ;
7
+ import BitcoinReviewTxPage from '../../page-objects/pages/send/bitcoin-review-tx-page' ;
8
+ import { getTransactionRequest , withBtcAccountSnap } from './common-btc' ;
42
9
43
10
describe ( 'BTC Account - Send' , function ( this : Suite ) {
44
- it ( 'can send complete the send flow' , async function ( ) {
11
+ it ( 'can complete the send flow' , async function ( ) {
45
12
await withBtcAccountSnap (
46
13
{ title : this . test ?. fullTitle ( ) } ,
47
14
async ( driver , mockServer ) => {
48
- await startSendFlow ( driver , DEFAULT_BTC_ACCOUNT ) ;
15
+ const homePage = new BitcoinHomepage ( driver ) ;
16
+ await homePage . check_pageIsLoaded ( ) ;
17
+ await homePage . check_isExpectedBitcoinBalanceDisplayed (
18
+ DEFAULT_BTC_BALANCE ,
19
+ ) ;
20
+ await homePage . startSendFlow ( ) ;
49
21
22
+ // Set the recipient address and amount
23
+ const bitcoinSendPage = new BitcoinSendPage ( driver ) ;
24
+ await bitcoinSendPage . check_pageIsLoaded ( ) ;
25
+ await bitcoinSendPage . fillRecipientAddress ( DEFAULT_BTC_ACCOUNT ) ;
50
26
// TODO: Remove delay here. There is a race condition if the amount and address are set too fast.
51
27
await driver . delay ( 1000 ) ;
52
-
53
- // Set the amount to send.
54
28
const mockAmountToSend = '0.5' ;
55
- await driver . pasteIntoField (
56
- `input[placeholder="${ SendFlowPlaceHolders . AMOUNT } "]` ,
57
- mockAmountToSend ,
58
- ) ;
59
-
60
- // From here, the "summary panel" should have some information about the fees and total.
61
- await driver . waitForSelector ( {
62
- text : 'Total' ,
63
- tag : 'p' ,
64
- } ) ;
29
+ await bitcoinSendPage . fillAmount ( mockAmountToSend ) ;
65
30
66
- // The review button will become available.
67
- const snapReviewButton = await driver . findClickableElement ( {
68
- text : 'Review' ,
69
- tag : 'button' ,
70
- css : '.snap-ui-renderer__footer-button' ,
71
- } ) ;
72
- assert . equal ( await snapReviewButton . isEnabled ( ) , true ) ;
73
- await snapReviewButton . click ( ) ;
31
+ // Click the review button
32
+ await bitcoinSendPage . clickReviewButton ( ) ;
74
33
75
34
// TODO: There isn't any check for the fees and total amount. This requires calculating the vbytes used in a transaction dynamically.
76
35
// We already have unit tests for these calculations on the Snap.
77
-
78
36
// ------------------------------------------------------------------------------
79
37
// From here, we have moved to the confirmation screen (second part of the flow).
80
38
81
- // We should be able to send the transaction right away.
82
- const snapSendButton = await driver . waitForSelector ( {
83
- text : 'Send' ,
84
- tag : 'button' ,
85
- css : '.snap-ui-renderer__footer-button' ,
86
- } ) ;
87
- assert . equal ( await snapSendButton . isEnabled ( ) , true ) ;
88
- await snapSendButton . click ( ) ;
89
-
90
- // Check that we are selecting the "Activity tab" right after the send.
91
- await driver . waitForSelector ( {
92
- tag : 'div' ,
93
- text : 'Bitcoin activity is not supported' ,
94
- } ) ;
39
+ // Click the send transaction button
40
+ const bitcoinReviewTxPage = new BitcoinReviewTxPage ( driver ) ;
41
+ await bitcoinReviewTxPage . check_pageIsLoaded ( ) ;
42
+ await bitcoinReviewTxPage . clickSendButton ( ) ;
95
43
44
+ // Check that we are on the activity list page and the warning message is displayed
45
+ await homePage . check_pageIsLoaded ( ) ;
46
+ await new ActivityListPage ( driver ) . check_warningMessage (
47
+ 'Bitcoin activity is not supported' ,
48
+ ) ;
96
49
const transaction = await getTransactionRequest ( mockServer ) ;
97
50
assert ( transaction !== undefined ) ;
98
51
} ,
@@ -103,58 +56,43 @@ describe('BTC Account - Send', function (this: Suite) {
103
56
await withBtcAccountSnap (
104
57
{ title : this . test ?. fullTitle ( ) } ,
105
58
async ( driver , mockServer ) => {
106
- await startSendFlow ( driver , DEFAULT_BTC_ACCOUNT ) ;
59
+ const homePage = new BitcoinHomepage ( driver ) ;
60
+ await homePage . check_pageIsLoaded ( ) ;
61
+ await homePage . check_isExpectedBitcoinBalanceDisplayed (
62
+ DEFAULT_BTC_BALANCE ,
63
+ ) ;
64
+ await homePage . startSendFlow ( ) ;
107
65
66
+ // Use the max spendable amount of that account
67
+ const bitcoinSendPage = new BitcoinSendPage ( driver ) ;
68
+ await bitcoinSendPage . check_pageIsLoaded ( ) ;
69
+ await bitcoinSendPage . fillRecipientAddress ( DEFAULT_BTC_ACCOUNT ) ;
108
70
// TODO: Remove delay here. There is a race condition if the amount and address are set too fast.
109
71
await driver . delay ( 1000 ) ;
110
-
111
- // Use the max spendable amount of that account.
112
- await driver . clickElement ( {
113
- text : 'Max' ,
114
- tag : 'button' ,
115
- } ) ;
72
+ await bitcoinSendPage . selectMaxAmount ( ) ;
73
+ await bitcoinSendPage . check_amountIsDisplayed (
74
+ `${ DEFAULT_BTC_BALANCE } BTC` ,
75
+ ) ;
116
76
117
77
// From here, the "summary panel" should have some information about the fees and total.
118
- await driver . waitForSelector ( {
119
- text : 'Total' ,
120
- tag : 'p' ,
121
- } ) ;
122
-
123
- await driver . waitForSelector ( {
124
- text : `${ DEFAULT_BTC_BALANCE } BTC` ,
125
- tag : 'p' ,
126
- } ) ;
127
-
128
- // The review button will become available.
129
- const snapReviewButton = await driver . findClickableElement ( {
130
- text : 'Review' ,
131
- tag : 'button' ,
132
- css : '.snap-ui-renderer__footer-button' ,
133
- } ) ;
134
- assert . equal ( await snapReviewButton . isEnabled ( ) , true ) ;
135
- await snapReviewButton . click ( ) ;
78
+ await bitcoinSendPage . clickReviewButton ( ) ;
136
79
137
80
// TODO: There isn't any check for the fees and total amount. This requires calculating the vbytes used in a transaction dynamically.
138
81
// We already have unit tests for these calculations on the snap.
139
82
140
83
// ------------------------------------------------------------------------------
141
84
// From here, we have moved to the confirmation screen (second part of the flow).
142
85
143
- // We should be able to send the transaction right away.
144
- const snapSendButton = await driver . waitForSelector ( {
145
- text : 'Send' ,
146
- tag : 'button' ,
147
- css : '.snap-ui-renderer__footer-button' ,
148
- } ) ;
149
- assert . equal ( await snapSendButton . isEnabled ( ) , true ) ;
150
- await snapSendButton . click ( ) ;
151
-
152
- // Check that we are selecting the "Activity tab" right after the send.
153
- await driver . waitForSelector ( {
154
- tag : 'div' ,
155
- text : 'Bitcoin activity is not supported' ,
156
- } ) ;
86
+ // Click the send transaction button
87
+ const bitcoinReviewTxPage = new BitcoinReviewTxPage ( driver ) ;
88
+ await bitcoinReviewTxPage . check_pageIsLoaded ( ) ;
89
+ await bitcoinReviewTxPage . clickSendButton ( ) ;
157
90
91
+ // Check that we are on the activity list page and the warning message is displayed
92
+ await homePage . check_pageIsLoaded ( ) ;
93
+ await new ActivityListPage ( driver ) . check_warningMessage (
94
+ 'Bitcoin activity is not supported' ,
95
+ ) ;
158
96
const transaction = await getTransactionRequest ( mockServer ) ;
159
97
assert ( transaction !== undefined ) ;
160
98
} ,
0 commit comments