import { test, expect } from '@playwright/test'; import { mockAuthenticatedUser, mockPublicStoreApis } from './fixtures/apiMocks'; test.describe('Profile Drawer & Logout Flows', () => { test('updates profile details and logs out cleanly', async ({ page }) => { await mockPublicStoreApis(page); await mockAuthenticatedUser(page, { display_name: 'Dr. Initial', phone_number: '+919876543210', country: 'India', }); await page.route('**/api/auth/profile', async (route) => { if (route.request().method() === 'PUT') { const body = route.request().postDataJSON(); await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ id: 'user-1', email: 'practitioner@acupedia.in', display_name: body.display_name, phone_number: body.phone_number, country: body.country, }), }); return; } await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ id: 'user-1', email: 'practitioner@acupedia.in', display_name: 'Dr. Initial', phone_number: '+919876543210', country: 'India', }), }); }); await page.goto('./'); // Open Profile Drawer via header avatar/button (shows 'Dr. Initial' on desktop, 'D' on mobile) await page.locator('header button').filter({ hasText: /^D/ }).first().click(); await expect(page.getByText('Save Profile Details')).toBeVisible(); // Update Display Name and save const nameInput = page.locator('input[value="Dr. Initial"]'); await nameInput.fill('Dr. Updated'); await page.getByRole('button', { name: 'Save Profile Details' }).click(); await expect(page.getByText(/Changes saved successfully!/i)).toBeVisible(); // Logout -> LoggedOutView await page.getByRole('button', { name: /Log Out/i }).click(); await expect(page.getByText('Successfully Logged Out')).toBeVisible(); }); test('changes password and shows PasswordUpdatedModal', async ({ page }) => { await mockPublicStoreApis(page); await mockAuthenticatedUser(page, { display_name: 'Dr. Initial', phone_number: '+919876543210', country: 'India', }); await page.route('**/api/auth/change-password', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ message: 'Password updated successfully!' }), }); }); await page.goto('./'); await page.locator('header button').filter({ hasText: /^D/ }).first().click(); await expect(page.getByText('Save Profile Details')).toBeVisible(); await page.getByRole('button', { name: 'Change Password' }).click(); await page.getByPlaceholder('Enter current password').fill('OldPass1!'); await page.getByPlaceholder('Min 8 chars, 1 uppercase, 1 digit, 1 special').fill('NewPass1!'); await page.getByPlaceholder('Repeat new password').fill('NewPass1!'); await page.getByRole('button', { name: 'Update Password' }).click(); await expect(page.getByText(/Password Updated/i)).toBeVisible(); }); });