1
1
import { strict as assert } from 'assert' ;
2
2
import { Suite } from 'mocha' ;
3
- import messages from '../../../../app/_locales/en/messages.json' ;
4
-
5
- import {
6
- WALLET_PASSWORD ,
7
- completeSRPRevealQuiz ,
8
- getSelectedAccountAddress ,
9
- openSRPRevealQuiz ,
10
- removeSelectedAccount ,
11
- tapAndHoldToRevealSRP ,
12
- } from '../../helpers' ;
13
- import { createBtcAccount , withBtcAccountSnap } from './common-btc' ;
3
+ import { WALLET_PASSWORD } from '../../helpers' ;
4
+ import AccountListPage from '../../page-objects/pages/account-list-page' ;
5
+ import HeaderNavbar from '../../page-objects/pages/header-navbar' ;
6
+ import LoginPage from '../../page-objects/pages/login-page' ;
7
+ import PrivacySettings from '../../page-objects/pages/settings/privacy-settings' ;
8
+ import ResetPasswordPage from '../../page-objects/pages/reset-password-page' ;
9
+ import SettingsPage from '../../page-objects/pages/settings/settings-page' ;
10
+ import { withBtcAccountSnap } from './common-btc' ;
14
11
15
12
describe ( 'Create BTC Account' , function ( this : Suite ) {
16
13
it ( 'create BTC account from the menu' , async function ( ) {
17
14
await withBtcAccountSnap (
18
15
{ title : this . test ?. fullTitle ( ) } ,
19
16
async ( driver ) => {
20
- await driver . findElement ( {
21
- css : '[data-testid="account-menu-icon"]' ,
22
- text : 'Bitcoin Account' ,
23
- } ) ;
17
+ const headerNavbar = new HeaderNavbar ( driver ) ;
18
+ await headerNavbar . check_pageIsLoaded ( ) ;
19
+ await headerNavbar . check_accountLabel ( 'Bitcoin Account' ) ;
24
20
} ,
25
21
) ;
26
22
} ) ;
@@ -29,27 +25,23 @@ describe('Create BTC Account', function (this: Suite) {
29
25
await withBtcAccountSnap (
30
26
{ title : this . test ?. fullTitle ( ) } ,
31
27
async ( driver ) => {
32
- await driver . delay ( 500 ) ;
33
- await driver . clickElement ( '[data-testid="account-menu-icon"]' ) ;
34
- await driver . clickElement (
35
- '[data-testid="multichain-account-menu-popover-action-button"]' ,
36
- ) ;
37
-
38
- const createButton = await driver . findElement ( {
39
- text : messages . addNewBitcoinAccount . message ,
40
- tag : 'button' ,
28
+ // check that we have one BTC account
29
+ const headerNavbar = new HeaderNavbar ( driver ) ;
30
+ await headerNavbar . check_pageIsLoaded ( ) ;
31
+ await headerNavbar . check_accountLabel ( 'Bitcoin Account' ) ;
32
+
33
+ // check user cannot create second BTC account
34
+ await headerNavbar . openAccountMenu ( ) ;
35
+ const accountListPage = new AccountListPage ( driver ) ;
36
+ await accountListPage . check_pageIsLoaded ( ) ;
37
+ await accountListPage . addNewBtcAccount ( {
38
+ btcAccountCreationEnabled : false ,
41
39
} ) ;
42
- assert . equal ( await createButton . isEnabled ( ) , false ) ;
43
40
44
- // modal will still be here
45
- await driver . clickElement ( '.mm-box button[aria-label="Close"]' ) ;
46
-
47
- // check the number of accounts. it should only be 2.
48
- await driver . clickElement ( '[data-testid="account-menu-icon"]' ) ;
49
- const menuItems = await driver . findElements (
50
- '.multichain-account-list-item' ,
51
- ) ;
52
- assert . equal ( menuItems . length , 2 ) ;
41
+ // check the number of available accounts is 2
42
+ await headerNavbar . openAccountMenu ( ) ;
43
+ await accountListPage . check_pageIsLoaded ( ) ;
44
+ await accountListPage . check_numberOfAvailableAccounts ( 2 ) ;
53
45
} ,
54
46
) ;
55
47
} ) ;
@@ -58,29 +50,22 @@ describe('Create BTC Account', function (this: Suite) {
58
50
await withBtcAccountSnap (
59
51
{ title : this . test ?. fullTitle ( ) } ,
60
52
async ( driver ) => {
61
- await driver . findElement ( {
62
- css : '[data-testid="account-menu-icon"]' ,
63
- text : 'Bitcoin Account' ,
64
- } ) ;
65
-
66
- await driver . clickElement ( '[data-testid="account-menu-icon"]' ) ;
67
- await driver . clickElement (
68
- '.multichain-account-list-item--selected [data-testid="account-list-item-menu-button"]' ,
69
- ) ;
70
- await driver . clickElement ( '[data-testid="account-list-menu-remove"]' ) ;
71
- await driver . clickElement ( { text : 'Nevermind' , tag : 'button' } ) ;
72
-
73
- await driver . findElement ( {
74
- css : '[data-testid="account-menu-icon"]' ,
75
- text : 'Bitcoin Account' ,
76
- } ) ;
77
-
78
- // check the number of accounts. it should only be 2.
79
- await driver . clickElement ( '[data-testid="account-menu-icon"]' ) ;
80
- const menuItems = await driver . findElements (
81
- '.multichain-account-list-item' ,
82
- ) ;
83
- assert . equal ( menuItems . length , 2 ) ;
53
+ // check that we have one BTC account
54
+ const headerNavbar = new HeaderNavbar ( driver ) ;
55
+ await headerNavbar . check_pageIsLoaded ( ) ;
56
+ await headerNavbar . check_accountLabel ( 'Bitcoin Account' ) ;
57
+
58
+ // check user can cancel the removal of the BTC account
59
+ await headerNavbar . openAccountMenu ( ) ;
60
+ const accountListPage = new AccountListPage ( driver ) ;
61
+ await accountListPage . check_pageIsLoaded ( ) ;
62
+ await accountListPage . removeAccount ( 'Bitcoin Account' , false ) ;
63
+ await headerNavbar . check_accountLabel ( 'Bitcoin Account' ) ;
64
+
65
+ // check the number of accounts. it should be 2.
66
+ await headerNavbar . openAccountMenu ( ) ;
67
+ await accountListPage . check_pageIsLoaded ( ) ;
68
+ await accountListPage . check_numberOfAvailableAccounts ( 2 ) ;
84
69
} ,
85
70
) ;
86
71
} ) ;
@@ -89,22 +74,33 @@ describe('Create BTC Account', function (this: Suite) {
89
74
await withBtcAccountSnap (
90
75
{ title : this . test ?. fullTitle ( ) } ,
91
76
async ( driver ) => {
92
- await driver . findElement ( {
93
- css : '[data-testid="account-menu-icon"]' ,
94
- text : 'Bitcoin Account' ,
95
- } ) ;
96
-
97
- const accountAddress = await getSelectedAccountAddress ( driver ) ;
98
- await removeSelectedAccount ( driver ) ;
99
-
100
- // Recreate account
101
- await createBtcAccount ( driver ) ;
102
- await driver . findElement ( {
103
- css : '[data-testid="account-menu-icon"]' ,
104
- text : 'Bitcoin Account' ,
105
- } ) ;
77
+ // check that we have one BTC account
78
+ const headerNavbar = new HeaderNavbar ( driver ) ;
79
+ await headerNavbar . check_pageIsLoaded ( ) ;
80
+ await headerNavbar . check_accountLabel ( 'Bitcoin Account' ) ;
81
+
82
+ // get the address of the BTC account and remove it
83
+ await headerNavbar . openAccountMenu ( ) ;
84
+ const accountListPage = new AccountListPage ( driver ) ;
85
+ await accountListPage . check_pageIsLoaded ( ) ;
86
+ const accountAddress = await accountListPage . getAccountAddress (
87
+ 'Bitcoin Account' ,
88
+ ) ;
89
+ await headerNavbar . openAccountMenu ( ) ;
90
+ await accountListPage . removeAccount ( 'Bitcoin Account' ) ;
91
+
92
+ // Recreate account and check that the address is the same
93
+ await headerNavbar . openAccountMenu ( ) ;
94
+ await accountListPage . check_pageIsLoaded ( ) ;
95
+ await accountListPage . addNewBtcAccount ( ) ;
96
+ await headerNavbar . check_accountLabel ( 'Bitcoin Account' ) ;
97
+
98
+ await headerNavbar . openAccountMenu ( ) ;
99
+ await accountListPage . check_pageIsLoaded ( ) ;
100
+ const recreatedAccountAddress = await accountListPage . getAccountAddress (
101
+ 'Bitcoin Account' ,
102
+ ) ;
106
103
107
- const recreatedAccountAddress = await getSelectedAccountAddress ( driver ) ;
108
104
assert ( accountAddress === recreatedAccountAddress ) ;
109
105
} ,
110
106
) ;
@@ -114,62 +110,50 @@ describe('Create BTC Account', function (this: Suite) {
114
110
await withBtcAccountSnap (
115
111
{ title : this . test ?. fullTitle ( ) } ,
116
112
async ( driver ) => {
117
- await driver . findElement ( {
118
- css : '[data-testid="account-menu-icon"]' ,
119
- text : 'Bitcoin Account' ,
120
- } ) ;
121
-
122
- const accountAddress = await getSelectedAccountAddress ( driver ) ;
123
-
124
- await openSRPRevealQuiz ( driver ) ;
125
- await completeSRPRevealQuiz ( driver ) ;
126
- await driver . fill ( '[data-testid="input-password"]' , WALLET_PASSWORD ) ;
127
- await driver . press ( '[data-testid="input-password"]' , driver . Key . ENTER ) ;
128
- await tapAndHoldToRevealSRP ( driver ) ;
129
- const seedPhrase = await (
130
- await driver . findElement ( '[data-testid="srp_text"]' )
131
- ) . getText ( ) ;
132
-
133
- // Reset wallet
134
- await driver . clickElement (
135
- '[data-testid="account-options-menu-button"]' ,
136
- ) ;
137
- await driver . clickElement ( {
138
- css : '[data-testid="global-menu-lock"]' ,
139
- text : 'Lock MetaMask' ,
140
- } ) ;
141
-
142
- await driver . clickElement ( {
143
- text : 'Forgot password?' ,
144
- tag : 'a' ,
145
- } ) ;
146
-
147
- await driver . pasteIntoField (
148
- '[data-testid="import-srp__srp-word-0"]' ,
149
- seedPhrase ,
113
+ // check that we have one BTC account
114
+ const headerNavbar = new HeaderNavbar ( driver ) ;
115
+ await headerNavbar . check_pageIsLoaded ( ) ;
116
+ await headerNavbar . check_accountLabel ( 'Bitcoin Account' ) ;
117
+
118
+ await headerNavbar . openAccountMenu ( ) ;
119
+ const accountListPage = new AccountListPage ( driver ) ;
120
+ await accountListPage . check_pageIsLoaded ( ) ;
121
+ const accountAddress = await accountListPage . getAccountAddress (
122
+ 'Bitcoin Account' ,
150
123
) ;
151
124
152
- await driver . fill (
153
- '[data-testid="create-vault-password"]' ,
154
- WALLET_PASSWORD ,
125
+ // go to privacy settings page and get the SRP
126
+ await headerNavbar . openSettingsPage ( ) ;
127
+ const settingsPage = new SettingsPage ( driver ) ;
128
+ await settingsPage . check_pageIsLoaded ( ) ;
129
+ await settingsPage . goToPrivacySettings ( ) ;
130
+
131
+ const privacySettings = new PrivacySettings ( driver ) ;
132
+ await privacySettings . check_pageIsLoaded ( ) ;
133
+ await privacySettings . openRevealSrpQuiz ( ) ;
134
+ await privacySettings . completeRevealSrpQuiz ( ) ;
135
+ await privacySettings . fillPasswordToRevealSrp ( WALLET_PASSWORD ) ;
136
+ const seedPhrase = await privacySettings . getSrpInRevealSrpDialog ( ) ;
137
+
138
+ // lock metamask and reset wallet by clicking forgot password button
139
+ await headerNavbar . lockMetaMask ( ) ;
140
+ await new LoginPage ( driver ) . gotoResetPasswordPage ( ) ;
141
+ const resetPasswordPage = new ResetPasswordPage ( driver ) ;
142
+ await resetPasswordPage . check_pageIsLoaded ( ) ;
143
+ await resetPasswordPage . resetPassword ( seedPhrase , WALLET_PASSWORD ) ;
144
+
145
+ // create a BTC account and check that the address is the same
146
+ await headerNavbar . check_pageIsLoaded ( ) ;
147
+ await headerNavbar . openAccountMenu ( ) ;
148
+ await accountListPage . check_pageIsLoaded ( ) ;
149
+ await accountListPage . addNewBtcAccount ( ) ;
150
+ await headerNavbar . check_accountLabel ( 'Bitcoin Account' ) ;
151
+
152
+ await headerNavbar . openAccountMenu ( ) ;
153
+ await accountListPage . check_pageIsLoaded ( ) ;
154
+ const recreatedAccountAddress = await accountListPage . getAccountAddress (
155
+ 'Bitcoin Account' ,
155
156
) ;
156
- await driver . fill (
157
- '[data-testid="create-vault-confirm-password"]' ,
158
- WALLET_PASSWORD ,
159
- ) ;
160
-
161
- await driver . clickElement ( {
162
- text : 'Restore' ,
163
- tag : 'button' ,
164
- } ) ;
165
-
166
- await createBtcAccount ( driver ) ;
167
- await driver . findElement ( {
168
- css : '[data-testid="account-menu-icon"]' ,
169
- text : 'Bitcoin Account' ,
170
- } ) ;
171
-
172
- const recreatedAccountAddress = await getSelectedAccountAddress ( driver ) ;
173
157
assert ( accountAddress === recreatedAccountAddress ) ;
174
158
} ,
175
159
) ;
0 commit comments