fix(home): restore account wallet and settings access

This commit is contained in:
鲨鱼辣椒 committed 2026-10-13 12:47:49 +08:00
1 parent 2b6ee37bdd
commit 5f7c851022
6 files changed
+373 -4

No files matched your search

+114
View File
@@ -1,6 +1,7 @@
import { mkdir, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { closeElectronApp, expect, getStableWindow, test } from './fixtures/electron';
import { billingSummary } from '../fixtures/permanent-points';
async function seedInactiveCodingProjects(resources: { rootDir: string; userDataDir: string }) {
const now = '2026-09-06T08:00:00.000Z';
@@ -50,6 +51,119 @@ async function seedInactiveCodingProjects(resources: { rootDir: string; userData
}
test.describe('Makelore module navigation without setup flow', () => {
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 {
const page = await getStableWindow(app);
await expect(page.getByTestId('ai-module-selection-page')).toBeVisible();
const applicationUrl = page.url();
await page.goto('about:blank');
await app.evaluate(({ ipcMain, BrowserWindow }, summary) => {
BrowserWindow.getAllWindows()[0].setSize(1440, 900);
const state = { loggedIn: true, requests: [] as { method: string; path: string }[] };
Object.assign(globalThis, { homeAccountFixture: state });
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; method?: string }) => {
const path = request.path ?? '';
const method = (request.method ?? 'GET').toUpperCase();
state.requests.push({ method, path });
if (path === '/api/auth/session/sync') return result({ success: true, session: state.loggedIn ? { accessToken: 'home-account-fixture', tokenType: 'Bearer', expiresAt: Date.now() + 3600000, lastActiveAt: Date.now(), canRefresh: false } : null });
if (path === '/api/auth/me') return result({ success: true, user: state.loggedIn ? { username: 'child-wallet', userId: 'home-user', tenantId: null, deptId: null, authorities: [] } : null, moduleAccess: { programming: true, design: true, robot: true, cloud_agents: true } });
if (path === '/api/auth/logout' && method === 'POST') { state.loggedIn = false; return result({ success: true }); }
if (path === '/api/works/user/agent-profile' && method === 'GET') 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-13T00:00:00Z' } });
if (path === '/api/works/billing/me' && method === 'GET') return result({ success: true, data: summary });
if (path.startsWith('/api/works/billing/recharge/orders?') && method === 'GET') return result({ success: true, data: { items: [] } });
if (path.startsWith('/api/works/billing/') || path === '/api/works/user/agent-profile') throw new Error('Unexpected home account write ' + method + ' ' + path);
return result({ success: true });
});
}, billingSummary());
// The setup-skipping fixture starts as a guest. Hydrate only this isolated
// Renderer with a fake persisted session before the auth store is created.
await page.addInitScript(() => {
const now = Date.now();
localStorage.setItem('niancode-auth', JSON.stringify({ version: 4, state: {
authBase: 'https://biz.nianxx.cn/auth/', clientId: 'app',
accessToken: 'home-account-fixture', tokenType: 'Bearer',
expiresAt: now + 3600000, lastActiveAt: now, canRefresh: false, legacyRefreshToken: null,
user: { username: 'child-wallet', userId: 'home-user', tenantId: null, deptId: null, authorities: [] },
moduleAccess: { programming: true, design: true, robot: true, cloud_agents: true },
} }));
// Setup-skipping mode also suppresses the home profile sync. Restore the
// isolated account's cached profile in the store's persisted shape.
localStorage.setItem('niancode-user-agent-profiles', JSON.stringify({ version: 1, state: {
profilesByUserId: { 'home-user': { displayName: '小麦', age: null, gender: 'undisclosed', avatarUrl: null,
shareAgeWithAgents: false, shareGenderWithAgents: false, analysisEnabled: true,
pendingSync: false, version: 1, updatedAt: '2026-10-13T00:00:00Z' } },
} }));
});
await page.goto(applicationUrl);
const trigger = page.getByTestId('home-account-menu-trigger');
const menu = page.getByTestId('home-account-menu');
await expect(trigger).toContainText('小麦');
await expect(page.locator('[data-testid^="ai-module-option-"]')).toHaveCount(3);
const footer = await trigger.evaluate(element => element.closest('footer')!.getBoundingClientRect().top);
const cards = await page.getByTestId('ai-module-options').boundingBox();
expect(footer).toBeGreaterThanOrEqual(cards!.y + cards!.height);
await trigger.click();
await expect(menu.getByTestId('sidebar-total-token-points')).toHaveText('75 点');
await expect(menu.getByText('永久有效 · 预占 5 点', { exact: true })).toBeVisible();
await expect(menu.getByRole('menuitem', { name: '词元点数与充值', exact: true })).toBeVisible();
await page.screenshot({ path: testInfo.outputPath('home-account-menu-desktop.png') });
await page.keyboard.press('Escape');
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
await expect(trigger).toBeFocused();
await trigger.click();
await page.getByRole('heading', { name: '今天,想创作什么?', exact: true }).click();
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
await trigger.click();
await menu.getByRole('menuitem', { name: '词元点数与充值', exact: true }).click();
const wallet = page.getByTestId('point-wallet-dialog');
await expect(wallet).toBeVisible();
await expect(wallet.getByTestId('point-recharge-recipient')).toHaveText('充值到:小麦(child-wallet)');
await expect(wallet.getByRole('button', { name: /500 点\s*¥10.00/ })).toBeEnabled();
await wallet.getByText('我的可用点数', { exact: true }).click();
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
await expect(wallet).toBeVisible();
await wallet.getByRole('button', { name: '关闭词元点数', exact: true }).click();
await expect(wallet).toHaveCount(0);
await trigger.click();
await menu.getByRole('menuitem', { name: '个人资料', exact: true }).click();
const profile = page.getByRole('dialog', { name: '个人资料', exact: true });
await expect(profile.getByLabel(/名字/)).toHaveValue('小麦');
await profile.getByRole('button', { name: '关闭个人资料', exact: true }).click();
await trigger.click();
await menu.getByRole('menuitem', { name: '设置', exact: true }).click();
await expect(page).toHaveURL(/\/settings$/);
await page.evaluate(() => { window.location.hash = '#/module-select'; });
await expect(trigger).toContainText('小麦');
await app.evaluate(({ BrowserWindow }) => { const window = BrowserWindow.getAllWindows()[0]; window.setMinimumSize(360, 600); window.setSize(375, 800); });
await expect.poll(() => page.evaluate(() => innerWidth)).toBe(375);
await trigger.click();
await expect(menu.getByTestId('sidebar-total-token-points')).toHaveText('75 点');
await expect.poll(() => page.evaluate(() => document.documentElement.scrollWidth - innerWidth)).toBeLessThanOrEqual(1);
const menuBox = await menu.boundingBox();
expect(menuBox!.x).toBeGreaterThanOrEqual(0);
expect(menuBox!.x + menuBox!.width).toBeLessThanOrEqual(375);
await page.screenshot({ path: testInfo.outputPath('home-account-menu-375.png') });
await menu.getByRole('menuitem', { name: '退出登录', exact: true }).click();
await expect(page).toHaveURL(/\/login$/);
await expect(trigger).toHaveCount(0);
const requests = await app.evaluate(() => (globalThis as typeof globalThis & { homeAccountFixture: { requests: { method: string; path: string }[] } }).homeAccountFixture.requests);
const billingReads = requests.filter(request => request.path.startsWith('/api/works/billing/'));
expect(billingReads.length).toBeGreaterThan(0);
expect(billingReads.every(request => request.method === 'GET')).toBe(true);
expect(requests.filter(request => request.path === '/api/works/user/agent-profile').every(request => request.method === 'GET')).toBe(true);
expect(requests.filter(request => request.path === '/api/auth/logout' && request.method === 'POST')).toHaveLength(1);
} finally {
await app.evaluate(({ BrowserWindow }) => { for (const window of BrowserWindow.getAllWindows()) window.destroy(); }).catch(() => undefined);
await closeElectronApp(app);
}
});
test('opens remembered Code projects and keeps the module return entry in chat instead of project settings', async ({
electronTestResources,
launchElectronApp,