A local-first personal finance app
remove forced waits to speed up some Playwright tests (#8293)
Matt Fiddamand4ba32c18135
diff --git a/packages/desktop-client/e2e/budget.test.ts b/packages/desktop-client/e2e/budget.test.tsindex 1385f7a155..b16f255ef6 100644--- a/packages/desktop-client/e2e/budget.test.ts+++ b/packages/desktop-client/e2e/budget.test.ts@@ -43,11 +43,10 @@ test.describe('Budget', () => {const currentFundsB = await budgetPage.getBalanceForRow(2);await budgetPage.transferAllBalance(1, 2);- await page.waitForTimeout(1000);- expect(await budgetPage.getBalanceForRow(2)).toEqual(- currentFundsA + currentFundsB,- );+ await expect+ .poll(() => budgetPage.getBalanceForRow(2))+ .toEqual(currentFundsA + currentFundsB);await expect(page).toMatchThemeScreenshots();});diff --git a/packages/desktop-client/e2e/page-models/budget-page.ts b/packages/desktop-client/e2e/page-models/budget-page.tsindex 13e0947253..9bf4ccd17e 100644--- a/packages/desktop-client/e2e/page-models/budget-page.ts+++ b/packages/desktop-client/e2e/page-models/budget-page.ts@@ -1,3 +1,4 @@+import { expect } from '@playwright/test';import type { Locator, Page } from '@playwright/test';import { AccountPage } from './account-page';@@ -105,33 +106,26 @@ export class BudgetPage {async #waitForNewMonthToLoad({currentMonth,errorMessage,- maxAttempts = 3,}: {currentMonth: string;errorMessage: string;- maxAttempts: number;}) {- for (let attempt = 0; attempt < maxAttempts; attempt++) {- const newMonth = await this.getSelectedMonth();- if (newMonth !== currentMonth) {- return newMonth;- }- await this.page.waitForTimeout(500);- }+ await expect(this.selectedMonthButton, errorMessage).not.toHaveAttribute(+ 'data-month',+ currentMonth,+ );- throw new Error(errorMessage);+ return this.getSelectedMonth();}- async goToNextMonth({ maxAttempts = 3 }: { maxAttempts?: number } = {}) {+ async goToNextMonth() {const currentMonth = await this.getSelectedMonth();await this.nextMonthButton.click();return await this.#waitForNewMonthToLoad({currentMonth,- maxAttempts,- errorMessage:- 'Failed to navigate to the next month after maximum attempts.',+ errorMessage: 'Failed to navigate to the next month.',});}diff --git a/packages/desktop-client/e2e/page-models/mobile-budget-page.ts b/packages/desktop-client/e2e/page-models/mobile-budget-page.tsindex 621d2c18bf..a05d7b9348 100644--- a/packages/desktop-client/e2e/page-models/mobile-budget-page.ts+++ b/packages/desktop-client/e2e/page-models/mobile-budget-page.ts@@ -1,3 +1,4 @@+import { expect } from '@playwright/test';import type { Locator, Page } from '@playwright/test';import { MobileAccountPage } from './mobile-account-page';@@ -262,33 +263,26 @@ export class MobileBudgetPage {async #waitForNewMonthToLoad({currentMonth,errorMessage,- maxAttempts = 3,}: {currentMonth: string;errorMessage: string;- maxAttempts: number;}) {- for (let attempt = 0; attempt < maxAttempts; attempt++) {- const newMonth = await this.getSelectedMonth();- if (newMonth !== currentMonth) {- return newMonth;- }- await this.page.waitForTimeout(500);- }+ await expect(+ this.heading.locator('[data-month]'),+ errorMessage,+ ).not.toHaveAttribute('data-month', currentMonth);- throw new Error(errorMessage);+ return this.getSelectedMonth();}- async goToPreviousMonth({ maxAttempts = 3 }: { maxAttempts?: number } = {}) {+ async goToPreviousMonth() {const currentMonth = await this.getSelectedMonth();await this.previousMonthButton.click();return await this.#waitForNewMonthToLoad({currentMonth,- maxAttempts,- errorMessage:- 'Failed to navigate to the previous month after maximum attempts.',+ errorMessage: 'Failed to navigate to the previous month.',});}@@ -296,16 +290,14 @@ export class MobileBudgetPage {await this.selectedBudgetMonthButton.click();}- async goToNextMonth({ maxAttempts = 3 }: { maxAttempts?: number } = {}) {+ async goToNextMonth() {const currentMonth = await this.getSelectedMonth();await this.nextMonthButton.click();return await this.#waitForNewMonthToLoad({currentMonth,- maxAttempts,- errorMessage:- 'Failed to navigate to the next month after maximum attempts.',+ errorMessage: 'Failed to navigate to the next month.',});}diff --git a/packages/desktop-client/e2e/page-models/mobile-navigation.ts b/packages/desktop-client/e2e/page-models/mobile-navigation.tsindex e211056fdf..b42f2f73ef 100644--- a/packages/desktop-client/e2e/page-models/mobile-navigation.ts+++ b/packages/desktop-client/e2e/page-models/mobile-navigation.ts@@ -1,3 +1,4 @@+import { expect } from '@playwright/test';import type { Locator, Page } from '@playwright/test';import { MobileAccountPage } from './mobile-account-page';@@ -91,9 +92,7 @@ export class MobileNavigation {},});- // Wait for the react-spring animation to complete before taking screenshots.- // The animation typically takes a few hundred milliseconds to finish.- await this.page.waitForTimeout(500);+ await expect(this.navbar).not.toHaveAttribute('data-navbar-state', 'open');}async hasNavbarState(...states: string[]) {diff --git a/packages/desktop-client/e2e/page-models/schedules-page.ts b/packages/desktop-client/e2e/page-models/schedules-page.tsindex 195862e779..c6d5bf4dd9 100644--- a/packages/desktop-client/e2e/page-models/schedules-page.ts+++ b/packages/desktop-client/e2e/page-models/schedules-page.ts@@ -55,7 +55,6 @@ export class SchedulesPage {*/async postNthSchedule(index: number) {await this._performNthAction(index, 'Post transaction today');- await this.page.waitForTimeout(1000);}/**@@ -64,7 +63,6 @@ export class SchedulesPage {*/async completeNthSchedule(index: number) {await this._performNthAction(index, 'Complete');- await this.page.waitForTimeout(1000);}async _performNthAction(index: number, actionName: string | RegExp) {diff --git a/packages/desktop-client/e2e/payees.mobile.test.ts b/packages/desktop-client/e2e/payees.mobile.test.tsindex 14a782b053..a2c4cd7415 100644--- a/packages/desktop-client/e2e/payees.mobile.test.ts+++ b/packages/desktop-client/e2e/payees.mobile.test.ts@@ -86,7 +86,6 @@ test.describe('Mobile Payees', () => {test('page handles empty state gracefully', async () => {// Search for something that won't match to get empty stateawait payeesPage.searchFor('NonExistentPayee123456789');- await page.waitForTimeout(500);// Check that empty message is shownconst emptyMessage = page.getByText('No payees found.');diff --git a/packages/desktop-client/e2e/rules.mobile.test.ts b/packages/desktop-client/e2e/rules.mobile.test.tsindex 249c10d6c4..92fdb4b8bc 100644--- a/packages/desktop-client/e2e/rules.mobile.test.ts+++ b/packages/desktop-client/e2e/rules.mobile.test.ts@@ -76,7 +76,6 @@ test.describe('Mobile Rules', () => {test('page handles empty state gracefully', async () => {// Search for something that won't match to get empty stateawait rulesPage.searchFor('NonExistentRule123456789');- await page.waitForTimeout(500);// Check that empty message is shownconst emptyMessage = page.getByText(/No rules found/);diff --git a/packages/desktop-client/e2e/rules.test.ts b/packages/desktop-client/e2e/rules.test.tsindex 212ce0d0ae..52e0298889 100644--- a/packages/desktop-client/e2e/rules.test.ts+++ b/packages/desktop-client/e2e/rules.test.ts@@ -71,8 +71,6 @@ test.describe('Rules', () => {});test('creates a split transaction rule and makes sure it is applied when creating a transaction', async () => {- rulesPage = await navigation.goToRulesPage();-const editRuleModal = await rulesPage.createNewRule();await editRuleModal.fill({conditions: [diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts b/packages/desktop-client/e2e/schedules.mobile.test.tsindex cd248838c0..0f0dfa27cf 100644--- a/packages/desktop-client/e2e/schedules.mobile.test.ts+++ b/packages/desktop-client/e2e/schedules.mobile.test.ts@@ -57,7 +57,6 @@ test.describe('Mobile Schedules', () => {test('page handles empty state gracefully', async () => {// Search for something that won't match to get empty stateawait schedulesPage.searchFor('NonExistentSchedule123456789');- await page.waitForTimeout(500);// Check that empty message is shownawait expect(schedulesPage.emptyMessage).toBeVisible();@@ -99,20 +98,20 @@ test.describe('Mobile Schedules', () => {// Search for a specific scheduleawait schedulesPage.searchFor('Dominion Power');- await page.waitForTimeout(500);// Verify search box has the valueawait expect(schedulesPage.searchBox).toHaveValue('Dominion Power');- expect(await schedulesPage.getScheduleCount()).toBe(1);+ await expect.poll(() => schedulesPage.getScheduleCount()).toBe(1);await expect(page).toMatchThemeScreenshots();// Clear searchawait schedulesPage.clearSearch();- await page.waitForTimeout(500);// Verify all schedules are visible again- expect(await schedulesPage.getScheduleCount()).toBeGreaterThan(1);+ await expect+ .poll(() => schedulesPage.getScheduleCount())+ .toBeGreaterThan(1);await expect(page).toMatchThemeScreenshots();});diff --git a/upcoming-release-notes/test-speeds-1.md b/upcoming-release-notes/test-speeds-1.mdnew file mode 100644index 0000000000..f70a666323--- /dev/null+++ b/upcoming-release-notes/test-speeds-1.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [matt-fidd]+---++Remove forced waits to speed up some Playwright tests