修正首页推荐位用例断言到模板库
- 首页「灵感推荐」已被模板库推荐位替换,用例改为断言模板库推荐卡片、已下载徽标与共 N 个模板计数 - 用例改为断言点击推荐位进入模板库页面,且不触发下载或由模板创建项目 - 保留不请求已退役展示流接口的断言
This commit is contained in:
@@ -182,24 +182,98 @@ export function registerClientHomeTests() {
|
||||
);
|
||||
});
|
||||
|
||||
it('shows the built-in inspiration masonry gallery and opens a dismissible preview without requesting the retired feed', async () => {
|
||||
it('shows the home template recommendations and opens the library without creating a project', async () => {
|
||||
const fetchSpy = vi.spyOn(globalThis, 'fetch');
|
||||
const templateLibrarySnapshot = {
|
||||
schemaVersion: 'game-template-library.v1',
|
||||
library: 'genarrative-official',
|
||||
libraryVersion: 3,
|
||||
updatedAt: '2026-09-17T00:00:00Z',
|
||||
fetchedAtMillis: 1,
|
||||
source: 'remote',
|
||||
templates: [
|
||||
{
|
||||
id: 'lane-defense',
|
||||
title: '星际防线',
|
||||
summary: '塔防原型',
|
||||
tags: ['塔防'],
|
||||
runtime: 'phaser',
|
||||
engine: 'Phaser',
|
||||
engineVersion: '4.2.1',
|
||||
templateVersion: '1.0.0',
|
||||
updatedAt: '2026-09-17T00:00:00Z',
|
||||
entry: 'index.html',
|
||||
zipUrl:
|
||||
'https://agc-dev.oss-rg-china-mainland.aliyuncs.com/agc/templates/lane-defense.zip',
|
||||
zipSizeBytes: 2048,
|
||||
zipSha256: 'a'.repeat(64),
|
||||
coverUrl:
|
||||
'https://agc-dev.oss-rg-china-mainland.aliyuncs.com/agc/templates/lane-defense.png',
|
||||
coverWidth: 320,
|
||||
coverHeight: 180,
|
||||
installed: true,
|
||||
installedVersion: '1.0.0',
|
||||
installedAtMillis: 2,
|
||||
},
|
||||
{
|
||||
id: 'cozy-farm',
|
||||
title: '悠然农场',
|
||||
summary: '经营原型',
|
||||
tags: ['经营'],
|
||||
runtime: 'phaser',
|
||||
engine: 'Phaser',
|
||||
engineVersion: '4.2.1',
|
||||
templateVersion: '1.0.0',
|
||||
updatedAt: '2026-09-17T00:00:00Z',
|
||||
entry: 'index.html',
|
||||
zipUrl:
|
||||
'https://agc-dev.oss-rg-china-mainland.aliyuncs.com/agc/templates/cozy-farm.zip',
|
||||
zipSizeBytes: 4096,
|
||||
zipSha256: 'b'.repeat(64),
|
||||
coverUrl:
|
||||
'https://agc-dev.oss-rg-china-mainland.aliyuncs.com/agc/templates/cozy-farm.png',
|
||||
coverWidth: 320,
|
||||
coverHeight: 180,
|
||||
installed: false,
|
||||
installedVersion: null,
|
||||
installedAtMillis: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
const invoke = vi.fn(async (command: string) => {
|
||||
if (command === 'read_game_creator_app_config') {
|
||||
return { config: { selectedModelId: 'quality' } };
|
||||
}
|
||||
if (command === 'fetch_game_template_library') {
|
||||
return templateLibrarySnapshot;
|
||||
}
|
||||
throw new Error(`unexpected invoke ${command}`);
|
||||
});
|
||||
window.__TAURI__ = { core: { invoke } };
|
||||
renderLauncherAt('/?launcher');
|
||||
|
||||
const inspiration = screen.getByLabelText('灵感推荐');
|
||||
const inspirationImages = within(inspiration).getAllByRole('button', {
|
||||
name: /查看灵感图片/,
|
||||
// 首页推荐位只展示封面、标题、运行时与已下载徽标,本机灵感图库已随模板库上线删除。
|
||||
const recommendations = await screen.findByLabelText('模板库推荐');
|
||||
const recommendationCards = within(recommendations).getAllByRole('button', {
|
||||
name: /^查看模板 /u,
|
||||
});
|
||||
expect(inspirationImages.length).toBeGreaterThan(0);
|
||||
expect(inspiration.closest('.overflow-y-auto')).not.toBeNull();
|
||||
expect(screen.queryByText('暂无灵感')).toBeNull();
|
||||
expect(recommendationCards.length).toBe(2);
|
||||
expect(within(recommendationCards[0]!).getByText('已下载')).not.toBeNull();
|
||||
|
||||
fireEvent.click(inspirationImages[0]!);
|
||||
const preview = screen.getByRole('dialog', { name: '查看灵感图片' });
|
||||
fireEvent.click(screen.getByAltText('放大的灵感图片'));
|
||||
expect(screen.getByRole('dialog', { name: '查看灵感图片' })).not.toBeNull();
|
||||
fireEvent.click(preview);
|
||||
expect(screen.queryByRole('dialog', { name: '查看灵感图片' })).toBeNull();
|
||||
fireEvent.click(recommendationCards[0]!);
|
||||
|
||||
// 点击推荐位只进入模板库页面,不在首页直接下载或创建项目。
|
||||
const librarySummary = await screen.findByText('共 2 个模板 · 已下载 1 个');
|
||||
expect(librarySummary).not.toBeNull();
|
||||
expect(screen.getByRole('button', { name: '返回' })).not.toBeNull();
|
||||
expect(screen.queryByLabelText('模板库推荐')).toBeNull();
|
||||
expect(
|
||||
invoke.mock.calls.some(
|
||||
([command]) =>
|
||||
command === 'download_game_template' ||
|
||||
command === 'create_automatic_local_game_project_from_template',
|
||||
),
|
||||
).toBe(false);
|
||||
|
||||
await act(async () => {
|
||||
await Promise.resolve();
|
||||
|
||||
Reference in New Issue
Block a user