JB/web/tests/e2e/browser-flows.spec.js

77 lines
3 KiB
JavaScript

const { test, expect } = require('@playwright/test');
const BASE_URL = 'http://localhost:3000';
test.describe('JobsBoard Phase 5 Real Browser Workflows', () => {
test('1. Job Discovery & Navigation Workflow', async ({ page }) => {
// Navigate to homepage
await page.goto(`${BASE_URL}/`);
await expect(page).toHaveTitle(/JobsBoard/i);
// Navigate to jobs marketplace
await page.goto(`${BASE_URL}/jobs`);
await expect(page.locator('h1')).toContainText(/Aggregated Job Postings/i);
// Check search input presence and type query
const searchInput = page.locator('input[placeholder*="Search titles, companies"]');
await expect(searchInput).toBeVisible();
await searchInput.fill('Engineer');
// Wait for filtered jobs
await page.waitForTimeout(1000);
const jobCards = page.locator('div:has-text("Engineer")');
await expect(jobCards.first()).toBeVisible();
// Verify company directory navigation
await page.goto(`${BASE_URL}/companies`);
await expect(page.locator('h1')).toContainText(/Company Directory/i);
const companyCards = page.locator('a[href^="/companies/"]');
await expect(companyCards.first()).toBeVisible();
});
test('2. Company Profile & Claiming UI Workflow', async ({ page }) => {
// Fetch first company from api
const res = await page.request.get(`${BASE_URL}/api/companies`);
const data = await res.json();
const targetCompany = data.companies[0];
expect(targetCompany).toBeDefined();
// Open company detail page
await page.goto(`${BASE_URL}/companies/${targetCompany.id}`);
await expect(page.locator('h1').first()).toContainText(targetCompany.name);
// Verify company header/banner exists and displays company name
const heading = page.locator('h1', { hasText: targetCompany.name });
await expect(heading).toBeVisible();
// Verify tabs are available
await expect(page.locator('button:has-text("Open Jobs")')).toBeVisible();
await expect(page.locator('button:has-text("Overview & Culture")')).toBeVisible();
// If claim button is rendered, click to test claim modal
const claimBtn = page.locator('button:has-text("Claim This Company")');
if (await claimBtn.isVisible()) {
await claimBtn.click();
await expect(page.locator('h3:has-text("Claim & Verify")')).toBeVisible();
// Close modal
await page.locator('button:has-text("✕")').first().click();
}
});
test('3. Employer Team Management View (Access-Gated)', async ({ page }) => {
// Attempt visiting team page without authentication
await page.goto(`${BASE_URL}/employer/team`);
await page.waitForTimeout(1000);
const bodyText = await page.textContent('body');
expect(bodyText).toBeDefined();
});
test('4. Security & Invitation Validation Flow', async ({ page }) => {
// Visit invalid invitation token
await page.goto(`${BASE_URL}/invitations/invalid-bogus-token-12345`);
const heading = page.locator('h1:has-text("Invalid Invitation Link")');
await expect(heading).toBeVisible();
});
});