merge: integrate coding default page

# Conflicts:
#	src/components/layout/Sidebar.tsx
#	tests/unit/coding-chat-panel.test.tsx
This commit is contained in:
inman
2026-09-07 10:10:34 +08:00
12 changed files with 487 additions and 36 deletions

View File

@@ -1,6 +1,86 @@
import { mkdir, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { closeElectronApp, expect, getStableWindow, test } from './fixtures/electron';
async function seedInactiveCodingProjects(resources: { rootDir: string; userDataDir: string }) {
const now = '2026-09-06T08:00:00.000Z';
const older = '2026-09-04T08:00:00.000Z';
const projects = [
{
id: 'project-moonlight',
name: '月光小游戏',
path: join(resources.rootDir, '月光小游戏'),
createdAt: older,
updatedAt: now,
lastOpenedAt: now,
projectId: '11111111-1111-4111-8111-111111111111',
},
{
id: 'project-storybook',
name: '故事绘本',
path: join(resources.rootDir, '故事绘本'),
createdAt: older,
updatedAt: older,
lastOpenedAt: older,
projectId: '22222222-2222-4222-8222-222222222222',
},
];
for (const project of projects) {
await mkdir(join(project.path, '.makelore'), { recursive: true });
await mkdir(join(project.path, 'knowledge'), { recursive: true });
await writeFile(join(project.path, '.makelore', 'project.json'), JSON.stringify({
schemaVersion: 2,
projectType: 'custom',
projectId: project.projectId,
initialized: true,
agents: [],
knowledgeDirectory: 'knowledge',
createdAt: project.createdAt,
updatedAt: project.updatedAt,
}));
}
await writeFile(join(resources.userDataDir, 'makelore-projects.json'), JSON.stringify({
projects: {
projects: Object.fromEntries(projects.map(({ projectId: _projectId, ...project }) => [project.id, project])),
activeProjectId: null,
},
}));
}
test.describe('Makelore module navigation without setup flow', () => {
test('offers a create CTA and horizontal cards for remembered inactive Code projects', async ({
electronTestResources,
launchElectronApp,
}) => {
await seedInactiveCodingProjects(electronTestResources);
const app = await launchElectronApp({ skipSetup: true });
try {
const page = await getStableWindow(app);
await expect(page.getByTestId('ai-module-selection-page')).toBeVisible();
await page.getByTestId('ai-module-option-programming').click();
await expect(page).toHaveURL(/\/chat$/);
await expect(page.getByRole('button', { name: '新增项目' })).toBeVisible();
await expect(page.getByText('已有项目')).toHaveCount(0);
await expect(page.getByText('选择一个项目继续')).toHaveCount(0);
const projectCards = page.getByTestId('coding-existing-projects');
await expect(projectCards).toBeVisible();
await expect(projectCards.getByRole('button')).toHaveCount(2);
await expect(projectCards.getByRole('button').nth(0)).toContainText('月光小游戏');
await expect(projectCards.getByRole('button').nth(1)).toContainText('故事绘本');
await projectCards.getByRole('button', { name: '进入项目 故事绘本' }).click();
await expect(page.getByTestId('coding-chat-panel')).toBeVisible();
await expect(page.getByTestId('coding-existing-projects')).toHaveCount(0);
await expect(page.getByTestId('sidebar-course-project-project-storybook')).toHaveAttribute('aria-current', 'page');
} finally {
await closeElectronApp(app);
}
});
test('keeps the three module entries in a proportional vertical stack while resizing the window', async ({ launchElectronApp }) => {
const app = await launchElectronApp({ skipSetup: true });
@@ -139,8 +219,14 @@ test.describe('Makelore module navigation without setup flow', () => {
await expect(page.getByTestId('ai-module-selection-page')).toBeVisible();
await page.getByTestId('ai-module-option-programming').click();
await expect(page.getByTestId('main-layout')).toBeVisible();
await expect(page).toHaveURL(/\/chat$/);
await expect(page.getByText('请先新建项目')).toHaveCount(0);
await expect(page.getByText('一念成光,万物可创。')).toBeVisible();
await expect(page.getByRole('heading', { name: '你想让麦洛和你一起构建什么?' })).toBeVisible();
await expect(page.getByRole('img', { name: '麦洛 M 标识' })).toBeVisible();
await expect(page.getByRole('button', { name: '新增项目' })).toBeVisible();
await expect(page.getByTestId('coding-project-starter')).toHaveCount(0);
await expect(page.getByTestId('coding-existing-projects')).toHaveCount(0);
await expect(page.getByText('一念成光,万物可创。')).toHaveCount(0);
await expect(page.getByRole('img', { name: 'Makelore logo' })).toBeVisible();
await expect(page.getByTestId('sidebar-module-switcher-trigger')).toContainText('编程 Code');
await expect(page.getByTestId('sidebar-module-return-icon')).toBeVisible();
@@ -154,6 +240,12 @@ test.describe('Makelore module navigation without setup flow', () => {
await expect(page.getByTestId('game-asset-browser')).toHaveCount(0);
await expect(page.getByTestId('game-asset-review-summary')).toHaveCount(0);
await page.getByTestId('coding-start-project-button').click();
const createProjectDialog = page.getByRole('dialog', { name: '新建项目' });
await expect(createProjectDialog).toBeVisible();
await createProjectDialog.getByRole('button', { name: '取消' }).first().click();
await expect(page.getByRole('dialog', { name: '新建项目' })).toHaveCount(0);
await expect(page.getByTestId('sidebar-module-switcher')).toBeVisible();
const moduleHomeTrigger = page.getByTestId('sidebar-module-switcher-trigger');
await expect(moduleHomeTrigger).toHaveAttribute('aria-label', '返回首页');

View File

@@ -60,6 +60,12 @@ const project: CodingProjectSummary = {
updatedAt: '2026-08-23T00:00:00.000Z',
lastOpenedAt: '2026-08-23T00:00:00.000Z',
};
const secondProject: CodingProjectSummary = {
...project,
id: 'project-2',
name: 'Second local project',
lastOpenedAt: '2026-08-22T00:00:00.000Z',
};
const agent: CodingProjectAgent = {
id: 'agent-1',
avatarId: 'default',
@@ -217,6 +223,40 @@ describe('CodingChatPanel first Conversation', () => {
expect(openProjectSettings).toHaveBeenCalledOnce();
});
it('shows a branded create CTA and horizontal existing-project cards before a project is selected', async () => {
projectApi.list.mockResolvedValue({ projects: [project, secondProject], activeProjectId: null });
const onCreateProject = vi.fn();
const onOpenProject = vi.fn();
const onOpenProjectSettings = vi.fn();
const { CodingChatPanel } = await import('@/pages/Chat/CodingChatPanel');
render(
<CodingChatPanel
onCreateProject={onCreateProject}
onOpenProject={onOpenProject}
onOpenProjectSettings={onOpenProjectSettings}
/>,
);
expect(await screen.findByTestId('coding-chat-empty-project')).toBeInTheDocument();
expect(screen.getByRole('heading', { name: '你想让麦洛和你一起构建什么?' })).toBeInTheDocument();
expect(screen.getByRole('img', { name: '麦洛 M 标识' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '新增项目' })).toBeInTheDocument();
expect(screen.getByTestId('coding-existing-projects')).toHaveTextContent('Local project');
expect(screen.getByTestId('coding-existing-projects')).toHaveTextContent('Second local project');
expect(screen.queryByText('已有项目')).not.toBeInTheDocument();
expect(screen.queryByText('选择一个项目继续')).not.toBeInTheDocument();
expect(screen.queryByTestId('coding-project-starter')).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: '项目与插件设置' })).not.toBeInTheDocument();
fireEvent.click(screen.getByTestId('coding-start-project-button'));
expect(onCreateProject).toHaveBeenCalledOnce();
fireEvent.click(screen.getByRole('button', { name: '进入项目 Second local project' }));
expect(onOpenProject).toHaveBeenCalledWith(secondProject.id);
expect(onOpenProjectSettings).not.toHaveBeenCalled();
});
it('makes the first-Conversation textarea editable while runtime metadata is held', async () => {
projectApi.list.mockResolvedValue({ projects: [project], activeProjectId: project.id });
projectApi.config.mockResolvedValue({ project, config });
@@ -233,6 +273,8 @@ describe('CodingChatPanel first Conversation', () => {
const view = render(<CodingChatPanel />);
const textbox = await screen.findByRole('textbox');
expect(screen.getByRole('heading', { name: '你想让麦洛和你一起构建什么?' })).toBeInTheDocument();
expect(screen.getByRole('img', { name: '麦洛 M 标识' })).toBeInTheDocument();
expect(textbox).toBeEnabled();
expect(projectApi.create).toHaveBeenCalledOnce();
expect(conversationApi.snapshot).toHaveBeenCalledWith(conversation.id);
@@ -940,7 +982,7 @@ describe('CodingChatPanel first Conversation', () => {
target: { files },
});
expect(await screen.findByText('每条消息最多添加 16 张图片。')).toBeInTheDocument();
expect(screen.getAllByRole('img')).toHaveLength(16);
expect(screen.getAllByRole('img', { name: /^image-\d+\.png$/u })).toHaveLength(16);
expect(codingConversationStore.getState().entriesByConversationId[conversation.id])
.toMatchObject({ loadState: 'live', error: null });
await waitFor(() => expect(screen.getByRole('button', { name: '发送' })).toBeEnabled());

View File

@@ -0,0 +1,33 @@
import { describe, expect, it, vi } from 'vitest';
import {
requestCodingProjectCreation,
requestCodingProjectOpen,
subscribeCodingProjectCreationRequest,
subscribeCodingProjectOpenRequest,
} from '@/lib/coding-project-entry';
describe('coding project entry events', () => {
it('delivers project creation requests and removes the listener on unsubscribe', () => {
const listener = vi.fn();
const unsubscribe = subscribeCodingProjectCreationRequest(listener);
requestCodingProjectCreation();
expect(listener).toHaveBeenCalledOnce();
unsubscribe();
requestCodingProjectCreation();
expect(listener).toHaveBeenCalledOnce();
});
it('delivers the selected project id and ignores requests after unsubscribe', () => {
const listener = vi.fn();
const unsubscribe = subscribeCodingProjectOpenRequest(listener);
requestCodingProjectOpen('project-2');
expect(listener).toHaveBeenCalledWith('project-2');
unsubscribe();
requestCodingProjectOpen('project-3');
expect(listener).toHaveBeenCalledOnce();
});
});