Refactor to enforce AuthContext usage over useAuthStore and improve test stability
- Replaced `useAuthStore` with `useAuth` from `AuthContext` across frontend components and tests to ensure dependency injection compliance. - Enhanced E2E test stability by delaying navigation until the auth context is fully initialized. - Updated Playwright configuration to use a single worker to prevent mock conflicts. - Refactored test setup to consistently inject `AuthProvider` for improved isolation and mocking. - Adjusted comments and documentation to clarify dependency injection and testability patterns.
This commit is contained in:
@@ -11,9 +11,15 @@ test.describe('Settings Navigation', () => {
|
||||
// Set up API mocks for authenticated user
|
||||
await setupAuthenticatedMocks(page);
|
||||
|
||||
// Delay to ensure auth store injection completes before navigation
|
||||
await page.waitForTimeout(200);
|
||||
|
||||
// Navigate to settings
|
||||
await page.goto('/settings/profile');
|
||||
await expect(page).toHaveURL('/settings/profile');
|
||||
|
||||
// Wait for page to fully load with auth context
|
||||
await page.waitForSelector('h2:has-text("Profile")', { timeout: 10000 });
|
||||
});
|
||||
|
||||
test('should display settings tabs', async ({ page }) => {
|
||||
@@ -48,7 +54,7 @@ test.describe('Settings Navigation', () => {
|
||||
]);
|
||||
|
||||
await expect(page).toHaveURL('/settings/password');
|
||||
await expect(page.locator('h2')).toContainText(/Change Password/i);
|
||||
await expect(page.locator('h2')).toContainText(/Password Settings/i);
|
||||
});
|
||||
|
||||
test('should navigate from Profile to Sessions', async ({ page }) => {
|
||||
@@ -95,7 +101,7 @@ test.describe('Settings Navigation', () => {
|
||||
]);
|
||||
|
||||
await expect(page).toHaveURL('/settings/password');
|
||||
await expect(page.locator('h2')).toContainText(/Change Password/i);
|
||||
await expect(page.locator('h2')).toContainText(/Password Settings/i);
|
||||
});
|
||||
|
||||
test('should maintain layout when navigating between tabs', async ({ page }) => {
|
||||
|
||||
Reference in New Issue
Block a user