95 lines
3.3 KiB
TypeScript
95 lines
3.3 KiB
TypeScript
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
|
|
import {
|
|
EDUTAINMENT_BABY_OBJECT_MATCH_TEMPLATE_ID,
|
|
EDUTAINMENT_BABY_OBJECT_MATCH_TEMPLATE_NAME,
|
|
type PlatformPublicGalleryCard,
|
|
} from '../rpg-entry/rpgEntryWorldPresentation';
|
|
import {
|
|
canExposePublicWork,
|
|
filterEdutainmentPublicWorks,
|
|
filterGeneralPublicWorks,
|
|
isEdutainmentEntryEnabled,
|
|
isEdutainmentPublicWork,
|
|
} from './platformEdutainmentVisibility';
|
|
|
|
function buildPuzzleCard(themeTags: string[]): PlatformPublicGalleryCard {
|
|
return {
|
|
sourceType: 'puzzle',
|
|
workId: 'puzzle-work-education-demo',
|
|
profileId: 'puzzle-profile-education-demo',
|
|
publicWorkCode: 'PZ-EDUDEMO',
|
|
ownerUserId: 'user-education',
|
|
authorDisplayName: '动作 Demo 作者',
|
|
worldName: '儿童动作热身 Demo',
|
|
subtitle: '拼图关卡',
|
|
summaryText: '本地动作 Demo。',
|
|
coverImageSrc: null,
|
|
themeTags,
|
|
visibility: 'published',
|
|
publishedAt: '2026-05-09T10:00:00.000Z',
|
|
updatedAt: '2026-05-09T10:00:00.000Z',
|
|
};
|
|
}
|
|
|
|
function buildBabyObjectMatchCard(themeTags: string[]): PlatformPublicGalleryCard {
|
|
return {
|
|
sourceType: 'edutainment',
|
|
templateId: EDUTAINMENT_BABY_OBJECT_MATCH_TEMPLATE_ID,
|
|
templateName: EDUTAINMENT_BABY_OBJECT_MATCH_TEMPLATE_NAME,
|
|
workId: 'baby-object-match-work-1',
|
|
profileId: 'baby-object-match-profile-1',
|
|
publicWorkCode: 'EDU-BABY01',
|
|
ownerUserId: 'user-education',
|
|
authorDisplayName: '动作 Demo 作者',
|
|
worldName: '宝贝识物水果篮',
|
|
subtitle: '宝贝识物',
|
|
summaryText: '将物品放入对应的篮子里。',
|
|
coverImageSrc: null,
|
|
themeTags,
|
|
visibility: 'published',
|
|
publishedAt: '2026-05-11T10:00:00.000Z',
|
|
updatedAt: '2026-05-11T10:00:00.000Z',
|
|
};
|
|
}
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllEnvs();
|
|
});
|
|
|
|
describe('platformEdutainmentVisibility', () => {
|
|
test('matches only the exact edutainment tag from full work tags', () => {
|
|
const exact = buildPuzzleCard(['运动', '安全', '拼图', '寓教于乐']);
|
|
const fuzzy = buildPuzzleCard(['儿童教育', '寓教于乐 ']);
|
|
|
|
expect(isEdutainmentPublicWork(exact)).toBe(true);
|
|
expect(isEdutainmentPublicWork(fuzzy)).toBe(false);
|
|
expect(filterEdutainmentPublicWorks([exact, fuzzy])).toEqual([exact]);
|
|
expect(filterGeneralPublicWorks([exact, fuzzy])).toEqual([fuzzy]);
|
|
});
|
|
|
|
test('defaults to enabled and blocks exact edutainment works only when disabled', () => {
|
|
const exact = buildPuzzleCard(['寓教于乐']);
|
|
const general = buildPuzzleCard(['儿童教育']);
|
|
|
|
expect(isEdutainmentEntryEnabled()).toBe(true);
|
|
expect(canExposePublicWork(exact)).toBe(true);
|
|
|
|
vi.stubEnv('VITE_ENABLE_EDUTAINMENT_ENTRY', 'false');
|
|
|
|
expect(isEdutainmentEntryEnabled()).toBe(false);
|
|
expect(canExposePublicWork(exact)).toBe(false);
|
|
expect(canExposePublicWork(general)).toBe(true);
|
|
});
|
|
|
|
test('applies the same exact tag rule to baby object match cards', () => {
|
|
const exact = buildBabyObjectMatchCard(['寓教于乐', '宝贝识物']);
|
|
const fuzzy = buildBabyObjectMatchCard(['寓教于乐 ', '宝贝识物']);
|
|
|
|
expect(isEdutainmentPublicWork(exact)).toBe(true);
|
|
expect(isEdutainmentPublicWork(fuzzy)).toBe(false);
|
|
expect(filterEdutainmentPublicWorks([exact, fuzzy])).toEqual([exact]);
|
|
expect(filterGeneralPublicWorks([exact, fuzzy])).toEqual([fuzzy]);
|
|
});
|
|
});
|