52 lines
2.2 KiB
JavaScript
52 lines
2.2 KiB
JavaScript
// @ts-check
|
|
import { test, expect } from '@playwright/test';
|
|
import { loadTestUser } from '../utils/testUser.js';
|
|
|
|
test.describe('@p0 Interest Inventory — restore from profile', () => {
|
|
test.setTimeout(20000);
|
|
|
|
test('after submit, returning shows 60/60 answered (prefilled)', async ({ page }) => {
|
|
const u = loadTestUser();
|
|
|
|
// Sign in
|
|
await page.context().clearCookies();
|
|
await page.goto('/signin', { waitUntil: 'networkidle' });
|
|
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: 15000 });
|
|
|
|
// Go to Inventory
|
|
await page.goto('/interest-inventory', { waitUntil: 'networkidle' });
|
|
await expect(page.getByRole('heading', { name: /Interest Inventory/i })).toBeVisible();
|
|
|
|
// If not completed, complete now (dev has Randomize)
|
|
const answered = page.getByText(/60\s*\/\s*60\s*answered/i);
|
|
if (!(await answered.isVisible({ timeout: 1000 }).catch(() => false))) {
|
|
const randomize = page.getByRole('button', { name: /Randomize Answers/i });
|
|
if (await randomize.isVisible().catch(() => false)) {
|
|
await randomize.click();
|
|
} else {
|
|
// fallback: fill current page
|
|
for (let p = 0; p < 10; p++) {
|
|
const selects = page.locator('select');
|
|
const n = await selects.count();
|
|
for (let i = 0; i < n; i++) await selects.nth(i).selectOption('3');
|
|
if (p < 9) await page.getByRole('button', { name: /^Next$/ }).click();
|
|
}
|
|
}
|
|
// advance to last page and submit
|
|
for (let i = 0; i < 9; i++) {
|
|
const next = page.getByRole('button', { name: /^Next$/ });
|
|
if (await next.isVisible().catch(() => false)) await next.click();
|
|
}
|
|
await page.getByRole('button', { name: /^Submit$/ }).click();
|
|
await page.waitForURL('**/career-explorer**', { timeout: 20000 });
|
|
}
|
|
|
|
// Return to inventory; it should show 60/60 answered (restored)
|
|
await page.goto('/interest-inventory', { waitUntil: 'networkidle' });
|
|
await expect(page.getByText(/60\s*\/\s*60\s*answered/i)).toBeVisible({ timeout: 10000 });
|
|
});
|
|
});
|