Skip to content

Commit 535c57d

Browse files
committed
fix(test): address PR review feedback for Playwright E2E tests
Security improvements: - Add IP whitelist to Test API (localhost only) to prevent accidental exposure - Remove redundant @EnableWebSecurity annotation from TestApiSecurityConfig - Remove /api/test/** from unprotectedURIs (handled by TestApiSecurityConfig) Code quality fixes: - Add HTTP error handling to TestApiClient with descriptive error messages - Fix invalid Playwright selector 'visible=true' in UpdateUserPage - Remove invalid clear() method calls (fill() clears automatically) - Fix dialog handler in EventDetailsPage to use waitForEvent for reliability - Add missing test user cleanup in delete-account tests - Add missing assertion in change-password test - Update Playwright version in package.json to match lock file (^1.58.0) Cleanup: - Remove unused imports from 10 page object files - Remove unused variables and imports from 5 test files - Add warning log when ROLE_USER not found in TestDataController - Document foreign key constraint handling in deleteTestUser - Document test DB credentials as acceptable for local-only profile
1 parent 755a319 commit 535c57d

21 files changed

Lines changed: 85 additions & 52 deletions

playwright/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"codegen": "playwright codegen http://localhost:8080"
1515
},
1616
"devDependencies": {
17-
"@playwright/test": "^1.40.0",
17+
"@playwright/test": "^1.58.0",
1818
"@types/node": "^20.10.0",
1919
"typescript": "^5.3.0",
2020
"dotenv": "^16.3.0"

playwright/src/pages/AdminActionsPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page, Locator, expect } from '@playwright/test';
1+
import { Page, Locator } from '@playwright/test';
22
import { BasePage } from './BasePage';
33

44
/**

playwright/src/pages/BasePage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page, Locator, expect } from '@playwright/test';
1+
import { Page } from '@playwright/test';
22

33
/**
44
* Base Page Object class providing common functionality for all pages.

playwright/src/pages/DeleteAccountPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page, Locator, expect } from '@playwright/test';
1+
import { Page, Locator } from '@playwright/test';
22
import { BasePage } from './BasePage';
33

44
/**

playwright/src/pages/EventDetailsPage.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page, Locator, expect } from '@playwright/test';
1+
import { Page, Locator } from '@playwright/test';
22
import { BasePage } from './BasePage';
33

44
/**
@@ -76,11 +76,11 @@ export class EventDetailsPage extends BasePage {
7676
* Register for the event.
7777
*/
7878
async register(): Promise<void> {
79-
// Set up dialog handler for the alert
80-
this.page.once('dialog', async (dialog) => {
81-
await dialog.accept();
82-
});
79+
// Set up dialog handler for the alert and verify it appears
80+
const dialogPromise = this.page.waitForEvent('dialog', { timeout: 5000 });
8381
await this.registerButton.click();
82+
const dialog = await dialogPromise;
83+
await dialog.accept();
8484
// Wait for page to reload
8585
await this.page.waitForLoadState('networkidle');
8686
}
@@ -89,11 +89,11 @@ export class EventDetailsPage extends BasePage {
8989
* Unregister from the event.
9090
*/
9191
async unregister(): Promise<void> {
92-
// Set up dialog handler for the alert
93-
this.page.once('dialog', async (dialog) => {
94-
await dialog.accept();
95-
});
92+
// Set up dialog handler for the alert and verify it appears
93+
const dialogPromise = this.page.waitForEvent('dialog', { timeout: 5000 });
9694
await this.unregisterButton.click();
95+
const dialog = await dialogPromise;
96+
await dialog.accept();
9797
// Wait for page to reload
9898
await this.page.waitForLoadState('networkidle');
9999
}

playwright/src/pages/EventListPage.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page, Locator, expect } from '@playwright/test';
1+
import { Page, Locator } from '@playwright/test';
22
import { BasePage } from './BasePage';
33

44
/**
@@ -82,9 +82,6 @@ export class EventListPage extends BasePage {
8282
const name = await card.locator('.card-title').textContent();
8383
const description = await card.locator('.card-text.text-muted').textContent();
8484

85-
// Get date and location from the card text
86-
const cardBody = await card.locator('.card-body').textContent();
87-
8885
return {
8986
name: name?.trim() || '',
9087
description: description?.trim() || '',

playwright/src/pages/ForgotPasswordPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page, Locator, expect } from '@playwright/test';
1+
import { Page, Locator } from '@playwright/test';
22
import { BasePage } from './BasePage';
33

44
/**

playwright/src/pages/LoginPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page, Locator, expect } from '@playwright/test';
1+
import { Page, Locator } from '@playwright/test';
22
import { BasePage } from './BasePage';
33

44
/**

playwright/src/pages/RegisterPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page, Locator, expect } from '@playwright/test';
1+
import { Page, Locator } from '@playwright/test';
22
import { BasePage } from './BasePage';
33

44
/**

playwright/src/pages/UpdatePasswordPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page, Locator, expect } from '@playwright/test';
1+
import { Page, Locator } from '@playwright/test';
22
import { BasePage } from './BasePage';
33

44
/**

0 commit comments

Comments
 (0)