123 lines
5.1 KiB
JavaScript
123 lines
5.1 KiB
JavaScript
// @ts-check
|
|
import { test, expect } from '@playwright/test';
|
|
import { loadTestUser } from '../utils/testUser.js';
|
|
|
|
test.describe('@p0 Onboarding E2E — Welcome→Career→Financial→College→Review→Roadmap', () => {
|
|
test.setTimeout(120_000);
|
|
|
|
test('Submit lands on /career-roadmap/:id', async ({ page }) => {
|
|
const u = loadTestUser();
|
|
|
|
// PremiumRoute gate: mark user premium BEFORE any navigation
|
|
await page.route(
|
|
/\/api\/user-profile\?fields=.*(firstname|is_premium|is_pro_premium).*/i,
|
|
async route => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ firstname: 'Tester', is_premium: 1, is_pro_premium: 0 })
|
|
});
|
|
}
|
|
);
|
|
|
|
// Sign in (single continuous session)
|
|
await page.context().clearCookies();
|
|
await page.goto('/signin', { waitUntil: 'domcontentloaded' });
|
|
await page.getByPlaceholder('Username', { exact: true }).fill(u.username);
|
|
await page.getByPlaceholder('Password', { exact: true }).fill(u.password);
|
|
await page.getByRole('button', { name: /^Sign In$/ }).click();
|
|
await page.waitForURL('**/signin-landing**', { timeout: 15_000 });
|
|
|
|
// Clean local pointers; seed career BEFORE starting (Career step reads LS)
|
|
await page.evaluate(() => {
|
|
localStorage.removeItem('premiumOnboardingPointer');
|
|
sessionStorage.removeItem('suppressOnboardingGuard');
|
|
localStorage.setItem('selectedCareer', JSON.stringify({
|
|
title: 'Data Analyst', soc_code: '15-2051.00'
|
|
}));
|
|
});
|
|
|
|
// Welcome → Career
|
|
await page.goto('/premium-onboarding', { waitUntil: 'domcontentloaded' });
|
|
await page.getByRole('button', { name: /^Get Started$/i }).click();
|
|
await expect(page.getByRole('heading', { name: /Career Details/i })).toBeVisible({ timeout: 15_000 });
|
|
|
|
// Career
|
|
const selects = page.locator('select');
|
|
await selects.nth(0).selectOption('yes'); // currently earning
|
|
await selects.nth(1).selectOption('planned'); // status
|
|
await selects.nth(2).selectOption('currently_enrolled'); // in-school (requires expected grad)
|
|
await page.locator('input[type="date"]').fill('2025-09-01');
|
|
|
|
const nextFromCareer = page.getByRole('button', { name: /^Financial →$/i });
|
|
await expect(nextFromCareer).toBeEnabled();
|
|
await nextFromCareer.click();
|
|
|
|
// Financial (selectors by name)
|
|
await expect(page.getByRole('heading', { name: /Financial Details/i })).toBeVisible({ timeout: 15_000 });
|
|
await page.locator('input[name="monthly_expenses"]').fill('1200');
|
|
await page.getByRole('button', { name: /Next: College →/i }).click();
|
|
|
|
// College
|
|
await expect(page.getByRole('heading', { name: /College Details/i })).toBeVisible({ timeout: 20_000 });
|
|
|
|
// Known-good pair from your dataset
|
|
const SCHOOL = 'Alabama A & M University';
|
|
const PROGRAM = 'Agriculture, General.';
|
|
|
|
// helper — some nested lists require two selects; simulate that
|
|
async function commitAutosuggest(input, text) {
|
|
await input.click();
|
|
await input.fill(text);
|
|
await page.keyboard.press('ArrowDown').catch(() => {});
|
|
await page.keyboard.press('Enter').catch(() => {});
|
|
await input.blur();
|
|
const v1 = (await input.inputValue()).trim();
|
|
// second pass if UI needs double-confirm
|
|
if (v1.toLowerCase() === text.toLowerCase()) {
|
|
await input.click();
|
|
await page.keyboard.press('ArrowDown').catch(() => {});
|
|
await page.keyboard.press('Enter').catch(() => {});
|
|
await input.blur();
|
|
}
|
|
}
|
|
|
|
// Fill + commit autosuggests
|
|
const schoolBox = page.locator('input[name="selected_school"]');
|
|
const programBox = page.locator('input[name="selected_program"]');
|
|
await commitAutosuggest(schoolBox, SCHOOL);
|
|
await commitAutosuggest(programBox, PROGRAM);
|
|
|
|
// Degree Type — use Bachelor's or first non-placeholder
|
|
const degreeSelect = page.getByLabel(/Degree Type/i);
|
|
let picked = false;
|
|
try {
|
|
await degreeSelect.selectOption({ label: "Bachelor's Degree" });
|
|
picked = true;
|
|
} catch {}
|
|
if (!picked) {
|
|
const secondOption = degreeSelect.locator('option').nth(1);
|
|
await secondOption.waitFor({ state: 'attached', timeout: 10_000 });
|
|
const val = await secondOption.getAttribute('value');
|
|
if (val) await degreeSelect.selectOption(val);
|
|
}
|
|
|
|
// Required when in-school
|
|
await page.getByLabel(/Expected Graduation Date/i).fill('2027-06-01');
|
|
|
|
// Continue to Review
|
|
const finishBtn = page.getByRole('button', { name: /Finish Onboarding/i });
|
|
await expect(finishBtn).toBeEnabled({ timeout: 10_000 });
|
|
await finishBtn.click();
|
|
|
|
// Review → Submit All
|
|
await expect(page.getByRole('heading', { name: /Review Your Info/i })).toBeVisible({ timeout: 20_000 });
|
|
await page.getByRole('button', { name: /^Submit All$/i }).click();
|
|
|
|
// Roadmap
|
|
await expect(page).toHaveURL(/\/career-roadmap\/[a-z0-9-]+$/i, { timeout: 30_000 });
|
|
await expect(page.getByText(/Where you are now and where you are going/i))
|
|
.toBeVisible({ timeout: 20_000 });
|
|
});
|
|
});
|