Skip to content

Commit a05d602

Browse files
Fix performance and responsive layout tests
Performance Tests: - Enable Chrome memory API with --enable-precise-memory-info flag - Add defensive checks for memory metrics availability - Gracefully handle browsers without Memory API support Responsive Layout Tests: - Fix mobile menu test to handle persistent sidebar layout - Move login outside viewport loop to prevent re-authentication timeouts - Test now correctly verifies functionality across Mobile, Tablet, and Desktop viewports Results: All 20 tests now passing (8 performance + 12 responsive)
1 parent cbb841b commit a05d602

3 files changed

Lines changed: 47 additions & 19 deletions

File tree

playwright.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export default defineConfig({
8484
use: {
8585
...devices['Desktop Chrome'],
8686
viewport: { width: 1366, height: 768 }, // Standard laptop resolution
87+
launchOptions: {
88+
args: ['--enable-precise-memory-info'], // Enable performance.memory API for memory tests
89+
},
8790
},
8891
dependencies: ['setup'],
8992
},

tests/performance/large-datasets.spec.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,27 @@ test.describe('Large Datasets Performance', () => {
208208
// Get memory metrics
209209
const metrics = await page.evaluate(() => {
210210
if ('memory' in performance) {
211-
return (performance as any).memory;
211+
const mem = (performance as any).memory;
212+
return {
213+
usedJSHeapSize: mem?.usedJSHeapSize,
214+
totalJSHeapSize: mem?.totalJSHeapSize,
215+
jsHeapSizeLimit: mem?.jsHeapSizeLimit,
216+
};
212217
}
213218
return null;
214219
});
215220

216-
if (metrics) {
221+
if (metrics && typeof metrics.usedJSHeapSize === 'number') {
217222
console.log(`JS Heap Size: ${(metrics.usedJSHeapSize / 1048576).toFixed(2)} MB`);
218-
console.log(`Total Heap Size: ${(metrics.totalJSHeapSize / 1048576).toFixed(2)} MB`);
223+
console.log(`Total Heap Size: ${(metrics.totalJSHeapSize! / 1048576).toFixed(2)} MB`);
224+
console.log(`Heap Size Limit: ${(metrics.jsHeapSizeLimit! / 1048576).toFixed(2)} MB`);
219225

220226
// Memory usage should be reasonable (< 100MB for typical SPA)
221227
expect(metrics.usedJSHeapSize).toBeLessThan(100 * 1048576);
228+
} else {
229+
console.log('Memory API not available or not enabled. Skipping memory assertion.');
230+
console.log('To enable: Run Chromium with --enable-precise-memory-info flag');
231+
// Test passes but doesn't assert - memory API is optional
222232
}
223233
});
224234
});

tests/responsive/mobile-layout.spec.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,31 @@ test.describe('Mobile/Responsive Layout', () => {
5050
await page.goto('/dashboard');
5151
await page.waitForLoadState('networkidle');
5252

53-
// Look for mobile menu toggle
54-
const menuButton = page.locator('button[aria-label*="menu"], button mat-icon').filter({ hasText: /menu/i });
55-
56-
if (await menuButton.isVisible({ timeout: 3000 })) {
57-
await menuButton.first().click();
58-
await page.waitForTimeout(500);
53+
// Check if mobile menu/sidenav is visible (either already open or after toggling)
54+
const menu = page.locator('mat-sidenav, .sidenav, nav, aside').first();
55+
const menuVisible = await menu.isVisible({ timeout: 3000 }).catch(() => false);
56+
57+
if (!menuVisible) {
58+
// Menu not visible, look for toggle button
59+
const menuButton = page.locator('button[aria-label*="menu"], button mat-icon').filter({ hasText: /menu/i });
60+
61+
if (await menuButton.isVisible({ timeout: 2000 })) {
62+
await menuButton.first().click();
63+
await page.waitForTimeout(500);
64+
65+
// Verify menu opened
66+
await expect(menu).toBeVisible({ timeout: 2000 });
67+
}
68+
} else {
69+
// Menu is already visible (persistent on mobile)
70+
console.log('Mobile menu is already visible (persistent layout)');
71+
}
5972

60-
// Menu should open
61-
const menu = page.locator('mat-sidenav, .mobile-menu, nav');
62-
const isMenuVisible = await menu.isVisible({ timeout: 2000 }).catch(() => false);
73+
// Verify menu navigation items are visible
74+
const navItems = page.locator('mat-nav-list a, nav a, .nav-item');
75+
const navCount = await navItems.count();
6376

64-
expect(isMenuVisible).toBe(true);
65-
}
77+
expect(navCount).toBeGreaterThan(0);
6678
});
6779

6880
test('should handle table scrolling on mobile', async ({ page }) => {
@@ -234,14 +246,17 @@ test.describe('Mobile/Responsive Layout', () => {
234246
{ width: 1920, height: 1080, name: 'Desktop' },
235247
];
236248

249+
// Login once before testing all viewports
250+
await loginAsRole(page, 'manager');
251+
await page.goto('/employees');
252+
await page.waitForLoadState('networkidle');
253+
237254
for (const viewport of viewports) {
255+
// Change viewport size
238256
await page.setViewportSize({ width: viewport.width, height: viewport.height });
257+
await page.waitForTimeout(500); // Wait for layout to adjust
239258

240-
await loginAsRole(page, 'manager');
241-
await page.goto('/employees');
242-
await page.waitForLoadState('networkidle');
243-
244-
// Core functionality should work
259+
// Core functionality should work at this viewport size
245260
const employeeTable = page.locator('table, mat-table');
246261
const hasTable = await employeeTable.isVisible({ timeout: 5000 }).catch(() => false);
247262

0 commit comments

Comments
 (0)