T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/lavocat.ca/private_html/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.ca/private_html/tests/profile-interaction-panel.spec.ts
import { test, expect } from '@playwright/test';

test.describe('ProfileInteractionPanel', () => {
  let testUserId: string;
  let otherUserId: string;

  test.beforeAll(async ({ request }) => {
    // Create test users for testing
    const user1 = await request.post('/api/test/create-user', {
      data: {
        email: 'testuser1@example.com',
        name: 'Test User 1',
        role: 'LAWYER'
      }
    });
    const user2 = await request.post('/api/test/create-user', {
      data: {
        email: 'testuser2@example.com',
        name: 'Test User 2',
        role: 'LAWYER'
      }
    });
    
    testUserId = (await user1.json()).id;
    otherUserId = (await user2.json()).id;
  });

  test.beforeEach(async ({ page }) => {
    // Login before each test
    await page.goto('/auth/login');
    await page.fill('input[name="email"]', 'testuser1@example.com');
    await page.fill('input[name="password"]', 'password123');
    await page.click('button[type="submit"]');
    await page.waitForURL('/');
  });

  test('should display own profile analytics panel', async ({ page }) => {
    await page.goto(`/profile/${testUserId}`);
    
    // Check that analytics panel is shown for own profile
    await expect(page.locator('text=Profile Analytics')).toBeVisible();
    await expect(page.locator('text=Profile Views')).toBeVisible();
    await expect(page.locator('text=Followers')).toBeVisible();
    await expect(page.locator('text=View Detailed Analytics')).toBeVisible();
    
    // Check that interaction buttons are not shown for own profile
    await expect(page.locator('text=Connect with')).not.toBeVisible();
    await expect(page.locator('text=Follow')).not.toBeVisible();
    await expect(page.locator('text=Endorse')).not.toBeVisible();
  });

  test('should display interaction panel for other users', async ({ page }) => {
    await page.goto(`/profile/${otherUserId}`);
    
    // Check that interaction panel is shown for other users
    await expect(page.locator('text=Connect with Test User 2')).toBeVisible();
    await expect(page.locator('text=Send Message')).toBeVisible();
    await expect(page.locator('text=Follow')).toBeVisible();
    await expect(page.locator('text=Schedule Meeting')).toBeVisible();
    await expect(page.locator('text=Endorse')).toBeVisible();
    await expect(page.locator('text=Share')).toBeVisible();
    
    // Check stats are displayed
    await expect(page.locator('text=Followers')).toBeVisible();
    await expect(page.locator('text=Endorsements')).toBeVisible();
    await expect(page.locator('text=Mutual')).toBeVisible();
  });

  test('should handle follow/unfollow functionality', async ({ page }) => {
    await page.goto(`/profile/${otherUserId}`);
    
    // Initial state - should show Follow button
    const followButton = page.locator('button:has-text("Follow")');
    await expect(followButton).toBeVisible();
    
    // Click follow
    await followButton.click();
    
    // Should show success toast
    await expect(page.locator('.toast-success')).toBeVisible();
    await expect(page.locator('text=Following Test User 2')).toBeVisible();
    
    // Button should change to Unfollow
    await expect(page.locator('button:has-text("Unfollow")')).toBeVisible();
    
    // Follower count should increase
    const followerCount = page.locator('text=Followers').locator('..').locator('.text-lg');
    await expect(followerCount).toContainText('1');
    
    // Click unfollow
    await page.locator('button:has-text("Unfollow")').click();
    
    // Should show success toast
    await expect(page.locator('.toast-success')).toBeVisible();
    await expect(page.locator('text=Unfollowed Test User 2')).toBeVisible();
    
    // Button should change back to Follow
    await expect(page.locator('button:has-text("Follow")')).toBeVisible();
    
    // Follower count should decrease
    await expect(followerCount).toContainText('0');
  });

  test('should handle endorse/unendorse functionality', async ({ page }) => {
    await page.goto(`/profile/${otherUserId}`);
    
    // Initial state - should show Endorse button
    const endorseButton = page.locator('button:has-text("Endorse")');
    await expect(endorseButton).toBeVisible();
    
    // Click endorse
    await endorseButton.click();
    
    // Should show success toast
    await expect(page.locator('.toast-success')).toBeVisible();
    await expect(page.locator('text=Endorsed Test User 2')).toBeVisible();
    
    // Button should change to Endorsed
    await expect(page.locator('button:has-text("Endorsed")')).toBeVisible();
    
    // Endorsement count should increase
    const endorsementCount = page.locator('text=Endorsements').locator('..').locator('.text-lg');
    await expect(endorsementCount).toContainText('1');
    
    // Click unendorse
    await page.locator('button:has-text("Endorsed")').click();
    
    // Should show success toast
    await expect(page.locator('.toast-success')).toBeVisible();
    await expect(page.locator('text=Removed endorsement for Test User 2')).toBeVisible();
    
    // Button should change back to Endorse
    await expect(page.locator('button:has-text("Endorse")')).toBeVisible();
    
    // Endorsement count should decrease
    await expect(endorsementCount).toContainText('0');
  });

  test('should handle share functionality', async ({ page, context }) => {
    await page.goto(`/profile/${otherUserId}`);
    
    // Mock navigator.share
    await page.addInitScript(() => {
      Object.defineProperty(navigator, 'share', {
        value: async () => Promise.resolve(),
        writable: true
      });
    });
    
    // Click share button
    await page.locator('button:has-text("Share")').click();
    
    // Should show success toast (or use native share if available)
    await expect(page.locator('.toast-success')).toBeVisible();
  });

  test('should handle bookmark functionality', async ({ page }) => {
    await page.goto(`/profile/${otherUserId}`);
    
    // Click bookmark button (if implemented)
    const bookmarkButton = page.locator('button:has-text("Bookmark")');
    if (await bookmarkButton.isVisible()) {
      await bookmarkButton.click();
      await expect(page.locator('.toast-success')).toBeVisible();
      await expect(page.locator('text=Profile bookmarked!')).toBeVisible();
    }
  });

  test('should show online status when user is online', async ({ page }) => {
    // Set user as online
    await page.evaluate((userId) => {
      localStorage.setItem(`online_${userId}`, 'true');
    }, otherUserId);
    
    await page.goto(`/profile/${otherUserId}`);
    
    // Should show online indicator
    await expect(page.locator('text=Online now')).toBeVisible();
    await expect(page.locator('.bg-green-500.animate-pulse')).toBeVisible();
  });

  test('should handle error states gracefully', async ({ page }) => {
    // Test with invalid profile ID
    await page.goto('/profile/invalid-id');
    
    // Should show error message
    await expect(page.locator('text=User not found')).toBeVisible();
  });

  test('should handle network errors gracefully', async ({ page }) => {
    await page.goto(`/profile/${otherUserId}`);
    
    // Intercept API calls and return error
    await page.route('**/api/profile/*/follow', route => {
      route.fulfill({ status: 500, body: 'Internal Server Error' });
    });
    
    // Try to follow
    await page.locator('button:has-text("Follow")').click();
    
    // Should show error toast
    await expect(page.locator('.toast-error')).toBeVisible();
    await expect(page.locator('text=Error updating follow status')).toBeVisible();
  });

  test('should handle authentication errors', async ({ page }) => {
    // Logout
    await page.goto('/auth/logout');
    
    // Try to access profile page
    await page.goto(`/profile/${otherUserId}`);
    
    // Try to follow without being logged in
    await page.locator('button:has-text("Follow")').click();
    
    // Should show authentication error
    await expect(page.locator('.toast-error')).toBeVisible();
    await expect(page.locator('text=Please log in to follow users')).toBeVisible();
  });

  test('should handle loading states', async ({ page }) => {
    await page.goto(`/profile/${otherUserId}`);
    
    // Intercept API call to delay response
    await page.route('**/api/profile/*/follow', route => {
      setTimeout(() => {
        route.fulfill({ status: 200, body: JSON.stringify({ success: true }) });
      }, 1000);
    });
    
    // Click follow button
    const followButton = page.locator('button:has-text("Follow")');
    await followButton.click();
    
    // Button should be disabled during loading
    await expect(followButton).toBeDisabled();
    
    // Wait for response
    await page.waitForTimeout(1100);
    
    // Button should be enabled again
    await expect(followButton).not.toBeDisabled();
  });

  test('should update mutual connections count', async ({ page }) => {
    await page.goto(`/profile/${otherUserId}`);
    
    // Check mutual connections are displayed
    const mutualCount = page.locator('text=Mutual').locator('..').locator('.text-lg');
    await expect(mutualCount).toBeVisible();
    
    // The count should be a number
    const count = await mutualCount.textContent();
    expect(parseInt(count || '0')).toBeGreaterThanOrEqual(0);
  });

  test('should handle message button click', async ({ page }) => {
    await page.goto(`/profile/${otherUserId}`);
    
    // Click message button
    await page.locator('button:has-text("Send Message")').click();
    
    // Should navigate to messages or open chat
    // This depends on your implementation
    await expect(page).toHaveURL(/.*message.*|.*chat.*/);
  });

  test('should handle schedule meeting button click', async ({ page }) => {
    await page.goto(`/profile/${otherUserId}`);
    
    // Click schedule meeting button
    await page.locator('button:has-text("Schedule Meeting")').click();
    
    // Should navigate to scheduling page or open modal
    // This depends on your implementation
    await expect(page).toHaveURL(/.*schedule.*|.*meeting.*/);
  });

  test.afterAll(async ({ request }) => {
    // Clean up test users
    await request.delete(`/api/test/delete-user/${testUserId}`);
    await request.delete(`/api/test/delete-user/${otherUserId}`);
  });
}); 

CasperSecurity Mini