1
+ import { type Locator , type Page } from '@playwright/test' ;
2
+
1
3
import { CloseAccountModal } from './close-account-modal' ;
2
4
5
+ type TransactionEntry = {
6
+ debit ?: string ;
7
+ credit ?: string ;
8
+ account ?: string ;
9
+ payee ?: string ;
10
+ notes ?: string ;
11
+ category ?: string ;
12
+ } ;
13
+
3
14
export class AccountPage {
4
- constructor ( page ) {
15
+ readonly page : Page ;
16
+ readonly accountName : Locator ;
17
+ readonly accountBalance : Locator ;
18
+ readonly addNewTransactionButton : Locator ;
19
+ readonly newTransactionRow : Locator ;
20
+ readonly addTransactionButton : Locator ;
21
+ readonly cancelTransactionButton : Locator ;
22
+ readonly accountMenuButton : Locator ;
23
+ readonly transactionTable : Locator ;
24
+ readonly transactionTableRow : Locator ;
25
+ readonly filterButton : Locator ;
26
+ readonly filterSelectTooltip : Locator ;
27
+ readonly selectButton : Locator ;
28
+ readonly selectTooltip : Locator ;
29
+
30
+ constructor ( page : Page ) {
5
31
this . page = page ;
6
32
7
33
this . accountName = this . page . getByTestId ( 'account-name' ) ;
@@ -30,14 +56,14 @@ export class AccountPage {
30
56
this . selectTooltip = this . page . getByTestId ( 'transactions-select-tooltip' ) ;
31
57
}
32
58
33
- async waitFor ( ) {
34
- await this . transactionTable . waitFor ( ) ;
59
+ async waitFor ( ... options : Parameters < Locator [ 'waitFor' ] > ) {
60
+ await this . transactionTable . waitFor ( ... options ) ;
35
61
}
36
62
37
63
/**
38
64
* Enter details of a transaction
39
65
*/
40
- async enterSingleTransaction ( transaction ) {
66
+ async enterSingleTransaction ( transaction : TransactionEntry ) {
41
67
await this . addNewTransactionButton . click ( ) ;
42
68
await this . _fillTransactionFields ( this . newTransactionRow , transaction ) ;
43
69
}
@@ -53,15 +79,18 @@ export class AccountPage {
53
79
/**
54
80
* Create a single transaction
55
81
*/
56
- async createSingleTransaction ( transaction ) {
82
+ async createSingleTransaction ( transaction : TransactionEntry ) {
57
83
await this . enterSingleTransaction ( transaction ) ;
58
84
await this . addEnteredTransaction ( ) ;
59
85
}
60
86
61
87
/**
62
88
* Create split transactions
63
89
*/
64
- async createSplitTransaction ( [ rootTransaction , ...transactions ] ) {
90
+ async createSplitTransaction ( [
91
+ rootTransaction ,
92
+ ...transactions
93
+ ] : TransactionEntry [ ] ) {
65
94
await this . addNewTransactionButton . click ( ) ;
66
95
67
96
// Root transaction
@@ -87,7 +116,7 @@ export class AccountPage {
87
116
await this . cancelTransactionButton . click ( ) ;
88
117
}
89
118
90
- async selectNthTransaction ( index ) {
119
+ async selectNthTransaction ( index : number ) {
91
120
const row = this . transactionTableRow . nth ( index ) ;
92
121
await row . getByTestId ( 'select' ) . click ( ) ;
93
122
}
@@ -96,7 +125,7 @@ export class AccountPage {
96
125
* Retrieve the data for the nth-transaction.
97
126
* 0-based index
98
127
*/
99
- getNthTransaction ( index ) {
128
+ getNthTransaction ( index : number ) {
100
129
const row = this . transactionTableRow . nth ( index ) ;
101
130
102
131
return this . _getTransactionDetails ( row ) ;
@@ -106,11 +135,9 @@ export class AccountPage {
106
135
return this . _getTransactionDetails ( this . newTransactionRow ) ;
107
136
}
108
137
109
- _getTransactionDetails ( row ) {
110
- const account = row . getByTestId ( 'account' ) ;
111
-
138
+ _getTransactionDetails ( row : Locator ) {
112
139
return {
113
- ... ( account ? { account } : { } ) ,
140
+ account : row . getByTestId ( 'account' ) ,
114
141
payee : row . getByTestId ( 'payee' ) ,
115
142
notes : row . getByTestId ( 'notes' ) ,
116
143
category : row . getByTestId ( 'category' ) ,
@@ -119,7 +146,7 @@ export class AccountPage {
119
146
} ;
120
147
}
121
148
122
- async clickSelectAction ( action ) {
149
+ async clickSelectAction ( action : string | RegExp ) {
123
150
await this . selectButton . click ( ) ;
124
151
await this . selectTooltip . getByRole ( 'button' , { name : action } ) . click ( ) ;
125
152
}
@@ -130,16 +157,13 @@ export class AccountPage {
130
157
async clickCloseAccount ( ) {
131
158
await this . accountMenuButton . click ( ) ;
132
159
await this . page . getByRole ( 'button' , { name : 'Close Account' } ) . click ( ) ;
133
- return new CloseAccountModal (
134
- this . page ,
135
- this . page . getByTestId ( 'close-account-modal' ) ,
136
- ) ;
160
+ return new CloseAccountModal ( this . page . getByTestId ( 'close-account-modal' ) ) ;
137
161
}
138
162
139
163
/**
140
164
* Open the filtering popover.
141
165
*/
142
- async filterBy ( field ) {
166
+ async filterBy ( field : string | RegExp ) {
143
167
await this . filterButton . click ( ) ;
144
168
await this . filterSelectTooltip . getByRole ( 'button' , { name : field } ) . click ( ) ;
145
169
@@ -149,7 +173,7 @@ export class AccountPage {
149
173
/**
150
174
* Filter to a specific note
151
175
*/
152
- async filterByNote ( note ) {
176
+ async filterByNote ( note : string ) {
153
177
const filterTooltip = await this . filterBy ( 'Note' ) ;
154
178
await this . page . keyboard . type ( note ) ;
155
179
await filterTooltip . applyButton . click ( ) ;
@@ -158,14 +182,17 @@ export class AccountPage {
158
182
/**
159
183
* Remove the nth filter
160
184
*/
161
- async removeFilter ( idx ) {
185
+ async removeFilter ( idx : number ) {
162
186
await this . page
163
187
. getByRole ( 'button' , { name : 'Delete filter' } )
164
188
. nth ( idx )
165
189
. click ( ) ;
166
190
}
167
191
168
- async _fillTransactionFields ( transactionRow , transaction ) {
192
+ async _fillTransactionFields (
193
+ transactionRow : Locator ,
194
+ transaction : TransactionEntry ,
195
+ ) {
169
196
if ( transaction . debit ) {
170
197
await transactionRow . getByTestId ( 'debit' ) . click ( ) ;
171
198
await this . page . keyboard . type ( transaction . debit ) ;
@@ -210,8 +237,11 @@ export class AccountPage {
210
237
}
211
238
212
239
class FilterTooltip {
213
- constructor ( page ) {
214
- this . page = page ;
215
- this . applyButton = page . getByRole ( 'button' , { name : 'Apply' } ) ;
240
+ readonly locator : Locator ;
241
+ readonly applyButton : Locator ;
242
+
243
+ constructor ( locator : Locator ) {
244
+ this . locator = locator ;
245
+ this . applyButton = locator . getByRole ( 'button' , { name : 'Apply' } ) ;
216
246
}
217
247
}
0 commit comments