Skip to content

Commit 37dfbba

Browse files
joel-jeremygithub-actions[bot]
authored andcommitted
[TypeScript] Convert test page models to TS (actualbudget#4218)
* Dummy commit * Delete js snapshots * Move extended expect and test to fixtures * Fix wrong commit * Update VRT * Dummy commit to run GH actions * Convert test page models to TS * Release notes * Fix typecheck errors * New page models to TS * Fix typecheck error * Fix page name * Put awaits on getTableTotals --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 5b04cc3 commit 37dfbba

27 files changed

+607
-281
lines changed

packages/desktop-client/e2e/budget.mobile.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ async function setBudgetAverage(
6060
await budgetPage.goToPreviousMonth();
6161
const spentButton = await budgetPage.getButtonForSpent(categoryName);
6262
const spent = await spentButton.textContent();
63+
if (!spent) {
64+
throw new Error('Failed to get spent amount');
65+
}
6366
totalSpent += currencyToAmount(spent) ?? 0;
6467
}
6568

@@ -280,6 +283,10 @@ budgetTypes.forEach(budgetType => {
280283

281284
const lastMonthBudget = await budgetedButton.textContent();
282285

286+
if (!lastMonthBudget) {
287+
throw new Error('Failed to get last month budget');
288+
}
289+
283290
await budgetPage.goToNextMonth();
284291

285292
await copyLastMonthBudget(budgetPage, categoryName);

packages/desktop-client/e2e/page-models/account-page.js renamed to packages/desktop-client/e2e/page-models/account-page.ts

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1+
import { type Locator, type Page } from '@playwright/test';
2+
13
import { CloseAccountModal } from './close-account-modal';
24

5+
type TransactionEntry = {
6+
debit?: string;
7+
credit?: string;
8+
account?: string;
9+
payee?: string;
10+
notes?: string;
11+
category?: string;
12+
};
13+
314
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) {
531
this.page = page;
632

733
this.accountName = this.page.getByTestId('account-name');
@@ -30,14 +56,14 @@ export class AccountPage {
3056
this.selectTooltip = this.page.getByTestId('transactions-select-tooltip');
3157
}
3258

33-
async waitFor() {
34-
await this.transactionTable.waitFor();
59+
async waitFor(...options: Parameters<Locator['waitFor']>) {
60+
await this.transactionTable.waitFor(...options);
3561
}
3662

3763
/**
3864
* Enter details of a transaction
3965
*/
40-
async enterSingleTransaction(transaction) {
66+
async enterSingleTransaction(transaction: TransactionEntry) {
4167
await this.addNewTransactionButton.click();
4268
await this._fillTransactionFields(this.newTransactionRow, transaction);
4369
}
@@ -53,15 +79,18 @@ export class AccountPage {
5379
/**
5480
* Create a single transaction
5581
*/
56-
async createSingleTransaction(transaction) {
82+
async createSingleTransaction(transaction: TransactionEntry) {
5783
await this.enterSingleTransaction(transaction);
5884
await this.addEnteredTransaction();
5985
}
6086

6187
/**
6288
* Create split transactions
6389
*/
64-
async createSplitTransaction([rootTransaction, ...transactions]) {
90+
async createSplitTransaction([
91+
rootTransaction,
92+
...transactions
93+
]: TransactionEntry[]) {
6594
await this.addNewTransactionButton.click();
6695

6796
// Root transaction
@@ -87,7 +116,7 @@ export class AccountPage {
87116
await this.cancelTransactionButton.click();
88117
}
89118

90-
async selectNthTransaction(index) {
119+
async selectNthTransaction(index: number) {
91120
const row = this.transactionTableRow.nth(index);
92121
await row.getByTestId('select').click();
93122
}
@@ -96,7 +125,7 @@ export class AccountPage {
96125
* Retrieve the data for the nth-transaction.
97126
* 0-based index
98127
*/
99-
getNthTransaction(index) {
128+
getNthTransaction(index: number) {
100129
const row = this.transactionTableRow.nth(index);
101130

102131
return this._getTransactionDetails(row);
@@ -106,11 +135,9 @@ export class AccountPage {
106135
return this._getTransactionDetails(this.newTransactionRow);
107136
}
108137

109-
_getTransactionDetails(row) {
110-
const account = row.getByTestId('account');
111-
138+
_getTransactionDetails(row: Locator) {
112139
return {
113-
...(account ? { account } : {}),
140+
account: row.getByTestId('account'),
114141
payee: row.getByTestId('payee'),
115142
notes: row.getByTestId('notes'),
116143
category: row.getByTestId('category'),
@@ -119,7 +146,7 @@ export class AccountPage {
119146
};
120147
}
121148

122-
async clickSelectAction(action) {
149+
async clickSelectAction(action: string | RegExp) {
123150
await this.selectButton.click();
124151
await this.selectTooltip.getByRole('button', { name: action }).click();
125152
}
@@ -130,16 +157,13 @@ export class AccountPage {
130157
async clickCloseAccount() {
131158
await this.accountMenuButton.click();
132159
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'));
137161
}
138162

139163
/**
140164
* Open the filtering popover.
141165
*/
142-
async filterBy(field) {
166+
async filterBy(field: string | RegExp) {
143167
await this.filterButton.click();
144168
await this.filterSelectTooltip.getByRole('button', { name: field }).click();
145169

@@ -149,7 +173,7 @@ export class AccountPage {
149173
/**
150174
* Filter to a specific note
151175
*/
152-
async filterByNote(note) {
176+
async filterByNote(note: string) {
153177
const filterTooltip = await this.filterBy('Note');
154178
await this.page.keyboard.type(note);
155179
await filterTooltip.applyButton.click();
@@ -158,14 +182,17 @@ export class AccountPage {
158182
/**
159183
* Remove the nth filter
160184
*/
161-
async removeFilter(idx) {
185+
async removeFilter(idx: number) {
162186
await this.page
163187
.getByRole('button', { name: 'Delete filter' })
164188
.nth(idx)
165189
.click();
166190
}
167191

168-
async _fillTransactionFields(transactionRow, transaction) {
192+
async _fillTransactionFields(
193+
transactionRow: Locator,
194+
transaction: TransactionEntry,
195+
) {
169196
if (transaction.debit) {
170197
await transactionRow.getByTestId('debit').click();
171198
await this.page.keyboard.type(transaction.debit);
@@ -210,8 +237,11 @@ export class AccountPage {
210237
}
211238

212239
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' });
216246
}
217247
}

packages/desktop-client/e2e/page-models/budget-page.js

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)