Cover expanded home module entries in Electron
This commit is contained in:
1 parent
1c39471156
commit
cca23df79c
1 file changed
+90
@@ -51,6 +51,96 @@ async function seedInactiveCodingProjects(resources: { rootDir: string; userData
|
||||
}
|
||||
|
||||
test.describe('Makelore module navigation without setup flow', () => {
|
||||
test('opens each home module with the sidebar expanded after a saved collapse', async ({ launchElectronApp }) => {
|
||||
const app = await launchElectronApp({ skipSetup: true });
|
||||
try {
|
||||
const page = await getStableWindow(app);
|
||||
await expect(page.getByTestId('ai-module-selection-page')).toBeVisible();
|
||||
await app.evaluate(({ ipcMain, BrowserWindow }, summary) => {
|
||||
const window = BrowserWindow.getAllWindows()[0];
|
||||
window.setSize(1440, 900);
|
||||
const session = () => ({ accessToken: 'home-sidebar-fixture', tokenType: 'Bearer', expiresAt: Date.now() + 3600000, lastActiveAt: Date.now(), canRefresh: false });
|
||||
const send = window.webContents.send.bind(window.webContents);
|
||||
window.webContents.send = (channel: string, ...args: unknown[]) => send(channel, ...(channel === 'auth:session-changed' ? [session()] : args));
|
||||
const result = (json: unknown) => ({ ok: true, data: { status: 200, ok: true, json } });
|
||||
ipcMain.removeHandler('hostapi:fetch');
|
||||
ipcMain.handle('hostapi:fetch', async (_event, request: { path?: string }) => {
|
||||
const path = request.path ?? '';
|
||||
if (path === '/api/auth/session/sync') return result({ success: true, session: session() });
|
||||
if (path === '/api/auth/me') return result({ success: true, user: { username: 'sidebar-child', userId: 'sidebar-user', tenantId: null, deptId: null, authorities: [] }, moduleAccess: { programming: true, design: true, robot: true, cloud_agents: true } });
|
||||
if (['/api/provider-accounts', '/api/provider-accounts/key-info', '/api/provider-vendors', '/api/providers'].includes(path)) return result([]);
|
||||
if (path === '/api/provider-accounts/default') return result({ accountId: null });
|
||||
if (path === '/api/coding/projects') return result({ projects: [], activeProjectId: null });
|
||||
if (path === '/api/settings') return result({ classroomSidebarWidth: 171, sidebarCollapsed: true, setupComplete: true });
|
||||
if (path === '/api/user-sync/bootstrap') return result({ success: true, bootstrap: { preferences: {}, providerAccounts: [], partners: [], usageAggregates: [] } });
|
||||
if (path === '/api/works/user/agent-profile') return result({ success: true, profile: { display_name: '小麦', age: null, gender: null, avatar_url: null, share_age_with_agents: false, share_gender_with_agents: false, analysis_enabled: true, completed: true, version: 1, updated_at: '2026-10-14T00:00:00Z' } });
|
||||
if (path === '/api/works/billing/me') return result({ success: true, data: summary });
|
||||
if (path === '/api/works/image-workspace') return result({ success: true, data: {
|
||||
capabilities: { conversation: true, generation: false, image: false, video: false, generationOptions: {
|
||||
image: { available: false, supportedAspectRatios: [], supportedDurationSeconds: [], maxOutputCount: 1, requiresFirstFrame: false, supportedReferenceRoles: [] },
|
||||
video: { available: false, supportedAspectRatios: [], supportedDurationSeconds: [], maxOutputCount: 1, requiresFirstFrame: true, supportedReferenceRoles: [] },
|
||||
} }, workspaces: [],
|
||||
} });
|
||||
if (path.startsWith('/api/cloud-agents/')) {
|
||||
if (path.endsWith('/recovery')) return result({ recent: null, pending: [] });
|
||||
if (path.endsWith('/agents') || path.endsWith('/bootstrap')) return result({ agents: [], next_cursor: null });
|
||||
}
|
||||
return result({ success: true });
|
||||
});
|
||||
}, billingSummary());
|
||||
await page.addInitScript(() => {
|
||||
const now = Date.now();
|
||||
localStorage.setItem('niancode-settings', JSON.stringify({ version: 0, state: { classroomSidebarWidth: 171, sidebarCollapsed: true } }));
|
||||
localStorage.setItem('niancode-auth', JSON.stringify({ version: 4, state: {
|
||||
authBase: 'https://biz.nianxx.cn/auth/', clientId: 'app', accessToken: 'home-sidebar-fixture', tokenType: 'Bearer',
|
||||
expiresAt: now + 3600000, lastActiveAt: now, canRefresh: false, legacyRefreshToken: null,
|
||||
user: { username: 'sidebar-child', userId: 'sidebar-user', tenantId: null, deptId: null, authorities: [] },
|
||||
moduleAccess: { programming: true, design: true, robot: true, cloud_agents: true },
|
||||
} }));
|
||||
localStorage.setItem('niancode-user-agent-profiles', JSON.stringify({ version: 1, state: {
|
||||
profilesByUserId: { 'sidebar-user': { displayName: '小麦', age: null, gender: 'undisclosed', avatarUrl: null,
|
||||
shareAgeWithAgents: false, shareGenderWithAgents: false, analysisEnabled: true,
|
||||
pendingSync: false, version: 1, updatedAt: '2026-10-14T00:00:00Z' } },
|
||||
} }));
|
||||
});
|
||||
await page.reload({ waitUntil: 'domcontentloaded' });
|
||||
const savedCollapsed = () => page.evaluate(() => JSON.parse(localStorage.getItem('niancode-settings')!).state.sidebarCollapsed as boolean);
|
||||
const checkExpanded = async () => {
|
||||
await expect(page.getByTestId('sidebar')).toBeVisible();
|
||||
await expect(page.getByTestId('sidebar')).toHaveAttribute('aria-hidden', 'false');
|
||||
await expect.poll(async () => (await page.getByTestId('sidebar').boundingBox())?.width ?? 0).toBeGreaterThan(150);
|
||||
await expect.poll(savedCollapsed).toBe(false);
|
||||
};
|
||||
const collapseAndReturnHome = async () => {
|
||||
await page.getByTestId('titlebar-sidebar-toggle').click();
|
||||
await page.mouse.click(1000, 500);
|
||||
await expect.poll(savedCollapsed).toBe(true);
|
||||
await expect(page.getByTestId('sidebar')).toHaveAttribute('aria-hidden', 'true');
|
||||
await page.getByTestId('sidebar-module-switcher-trigger').click();
|
||||
await expect(page.getByTestId('ai-module-selection-page')).toBeVisible();
|
||||
await expect.poll(savedCollapsed).toBe(true);
|
||||
};
|
||||
for (const [moduleId, route] of [['programming', /\/chat$/], ['cloud_agents', /\/cloud-agents\?view=mine$/]] as const) {
|
||||
await expect.poll(savedCollapsed).toBe(true);
|
||||
await page.getByTestId(`ai-module-option-${moduleId}`).click();
|
||||
await expect(page).toHaveURL(route);
|
||||
await checkExpanded();
|
||||
await collapseAndReturnHome();
|
||||
await page.getByTestId(`ai-module-option-${moduleId}`).click();
|
||||
await expect(page).toHaveURL(route);
|
||||
await checkExpanded();
|
||||
await collapseAndReturnHome();
|
||||
}
|
||||
await page.getByTestId('ai-module-option-painting').click();
|
||||
await expect(page).toHaveURL(/\/image-canvas$/);
|
||||
await checkExpanded();
|
||||
await expect(page.getByTestId('titlebar-sidebar-toggle')).toHaveCount(0);
|
||||
} finally {
|
||||
await app.evaluate(({ BrowserWindow }) => { for (const window of BrowserWindow.getAllWindows()) window.destroy(); }).catch(() => undefined);
|
||||
await closeElectronApp(app);
|
||||
}
|
||||
});
|
||||
|
||||
test('keeps the home account wallet, profile, settings and logout available without creating a payment', async ({ launchElectronApp }, testInfo) => {
|
||||
const app = await launchElectronApp({ skipSetup: true });
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user