Files
openmaic/OpenMAIC/e2e/tests/home-to-generation.spec.ts
2026-08-16 14:58:47 +08:00

78 lines
2.7 KiB
TypeScript

import { test, expect } from '../fixtures/base';
import { HomePage } from '../pages/home.page';
import { createSettingsStorage } from '../fixtures/test-data/settings';
// Inject settings with modelId so the "enter classroom" button works
const SETTINGS_STORAGE = createSettingsStorage();
test.describe('Home → Generation', () => {
test.beforeEach(async ({ page }) => {
await page.addInitScript((settings) => {
localStorage.setItem('maic:account:settings-storage', settings);
localStorage.setItem('locale', 'en-US');
}, SETTINGS_STORAGE);
});
test('plain requirement starts a durable background job', async ({ page }) => {
let requestBody: unknown;
await page.route('**/api/generate-classroom', async (route) => {
requestBody = route.request().postDataJSON();
await route.fulfill({
status: 202,
contentType: 'application/json',
body: JSON.stringify({ success: true, jobId: 'job-e2e' }),
});
});
const home = new HomePage(page);
await home.goto();
// Core elements visible
await expect(home.logo).toBeVisible();
await expect(home.textarea).toBeVisible();
await expect(home.enterButton).toBeDisabled();
// Type requirement → button activates
await home.fillRequirement('讲解光合作用');
await expect(home.enterButton).toBeEnabled();
// Plain requirements stay on the home page and start a server-side job.
await home.submit();
await expect.poll(() => requestBody).toEqual({ requirement: '讲解光合作用' });
await expect(page).toHaveURL(/\/$/);
});
test('interactive mode enters the original foreground generation flow', async ({ page }) => {
const home = new HomePage(page);
await home.goto();
await home.fillRequirement('讲解光合作用');
await home.enableInteractiveMode();
await expect(home.enterButton).toHaveText('Foreground');
await home.submit();
await page.waitForURL(/\/generation-preview/);
const session = await page.evaluate(() => {
const raw = sessionStorage.getItem('generationSession');
return raw ? JSON.parse(raw) : null;
});
expect(session).toMatchObject({
requirements: {
requirement: '讲解光合作用',
interactiveMode: true,
},
previewPhase: 'preparing',
currentStep: 'generating',
});
});
test('does not expose operator settings on the learner surface', async ({ page }) => {
const home = new HomePage(page);
await home.goto();
await expect(home.logo).toBeVisible();
await expect(page.locator('button:has(svg.lucide-settings)')).toHaveCount(0);
await expect(page.getByRole('dialog', { name: 'Settings' })).toHaveCount(0);
});
});